CleanupInvitationTokenJobTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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\IDBConnection;
  33. use Test\TestCase;
  34. class CleanupInvitationTokenJobTest extends TestCase {
  35. /** @var IDBConnection | \PHPUnit\Framework\MockObject\MockObject */
  36. private $dbConnection;
  37. /** @var ITimeFactory | \PHPUnit\Framework\MockObject\MockObject */
  38. private $timeFactory;
  39. /** @var \OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob */
  40. private $backgroundJob;
  41. protected function setUp(): void {
  42. parent::setUp();
  43. $this->dbConnection = $this->createMock(IDBConnection::class);
  44. $this->timeFactory = $this->createMock(ITimeFactory::class);
  45. $this->backgroundJob = new CleanupInvitationTokenJob(
  46. $this->dbConnection, $this->timeFactory);
  47. }
  48. public function testRun() {
  49. $this->timeFactory->expects($this->once())
  50. ->method('getTime')
  51. ->with()
  52. ->willReturn(1337);
  53. $queryBuilder = $this->createMock(IQueryBuilder::class);
  54. $expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class);
  55. $stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class);
  56. $this->dbConnection->expects($this->once())
  57. ->method('getQueryBuilder')
  58. ->with()
  59. ->willReturn($queryBuilder);
  60. $queryBuilder->method('expr')
  61. ->willReturn($expr);
  62. $queryBuilder->method('createNamedParameter')
  63. ->willReturnMap([
  64. [1337, \PDO::PARAM_STR, null, 'namedParameter1337']
  65. ]);
  66. $expr->expects($this->once())
  67. ->method('lt')
  68. ->with('expiration', 'namedParameter1337')
  69. ->willReturn('LT STATEMENT');
  70. $this->dbConnection->expects($this->once())
  71. ->method('getQueryBuilder')
  72. ->with()
  73. ->willReturn($queryBuilder);
  74. $queryBuilder->expects($this->at(0))
  75. ->method('delete')
  76. ->with('calendar_invitations')
  77. ->willReturn($queryBuilder);
  78. $queryBuilder->expects($this->at(3))
  79. ->method('where')
  80. ->with('LT STATEMENT')
  81. ->willReturn($queryBuilder);
  82. $queryBuilder->expects($this->at(4))
  83. ->method('execute')
  84. ->with()
  85. ->willReturn($stmt);
  86. $this->backgroundJob->run([]);
  87. }
  88. }