1
0

CleanupInvitationTokenJobTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018, Georg Ehrke <oc.list@georgehrke.com>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Georg Ehrke <oc.list@georgehrke.com>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. *
  12. * @license GNU AGPL version 3 or any later version
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License as
  16. * published by the Free Software Foundation, either version 3 of the
  17. * License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. *
  27. */
  28. namespace OCA\DAV\Tests\unit\BackgroundJob;
  29. use OCA\DAV\BackgroundJob\CleanupInvitationTokenJob;
  30. use OCP\AppFramework\Utility\ITimeFactory;
  31. use OCP\DB\QueryBuilder\IQueryBuilder;
  32. use OCP\DB\QueryBuilder\IQueryFunction;
  33. use OCP\IDBConnection;
  34. use Test\TestCase;
  35. class CleanupInvitationTokenJobTest extends TestCase {
  36. /** @var IDBConnection | \PHPUnit\Framework\MockObject\MockObject */
  37. private $dbConnection;
  38. /** @var ITimeFactory | \PHPUnit\Framework\MockObject\MockObject */
  39. private $timeFactory;
  40. /** @var \OCA\DAV\BackgroundJob\CleanupInvitationTokenJob */
  41. private $backgroundJob;
  42. protected function setUp(): void {
  43. parent::setUp();
  44. $this->dbConnection = $this->createMock(IDBConnection::class);
  45. $this->timeFactory = $this->createMock(ITimeFactory::class);
  46. $this->backgroundJob = new CleanupInvitationTokenJob(
  47. $this->dbConnection, $this->timeFactory);
  48. }
  49. public function testRun() {
  50. $this->timeFactory->expects($this->once())
  51. ->method('getTime')
  52. ->with()
  53. ->willReturn(1337);
  54. $queryBuilder = $this->createMock(IQueryBuilder::class);
  55. $expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class);
  56. $stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class);
  57. $this->dbConnection->expects($this->once())
  58. ->method('getQueryBuilder')
  59. ->with()
  60. ->willReturn($queryBuilder);
  61. $queryBuilder->method('expr')
  62. ->willReturn($expr);
  63. $queryBuilder->method('createNamedParameter')
  64. ->willReturnMap([
  65. [1337, \PDO::PARAM_STR, null, 'namedParameter1337']
  66. ]);
  67. $function = $this->createMock(IQueryFunction::class);
  68. $expr->expects($this->once())
  69. ->method('lt')
  70. ->with('expiration', 'namedParameter1337')
  71. ->willReturn($function);
  72. $this->dbConnection->expects($this->once())
  73. ->method('getQueryBuilder')
  74. ->with()
  75. ->willReturn($queryBuilder);
  76. $queryBuilder->expects($this->at(0))
  77. ->method('delete')
  78. ->with('calendar_invitations')
  79. ->willReturn($queryBuilder);
  80. $queryBuilder->expects($this->at(3))
  81. ->method('where')
  82. ->with($function)
  83. ->willReturn($queryBuilder);
  84. $queryBuilder->expects($this->at(4))
  85. ->method('execute')
  86. ->with()
  87. ->willReturn($stmt);
  88. $this->backgroundJob->run([]);
  89. }
  90. }