You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CleanupInvitationTokenJobTest.php 3.1KB

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