CleanupInvitationTokenJobTest.php 3.2 KB

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 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\CleanupInvitationTokenJob */
  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(): void {
  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. $function = 'function1337';
  67. $expr->expects($this->once())
  68. ->method('lt')
  69. ->with('expiration', 'namedParameter1337')
  70. ->willReturn($function);
  71. $this->dbConnection->expects($this->once())
  72. ->method('getQueryBuilder')
  73. ->with()
  74. ->willReturn($queryBuilder);
  75. $queryBuilder->expects($this->once())
  76. ->method('delete')
  77. ->with('calendar_invitations')
  78. ->willReturn($queryBuilder);
  79. $queryBuilder->expects($this->once())
  80. ->method('where')
  81. ->with($function)
  82. ->willReturn($queryBuilder);
  83. $queryBuilder->expects($this->once())
  84. ->method('execute')
  85. ->with()
  86. ->willReturn($stmt);
  87. $this->backgroundJob->run([]);
  88. }
  89. }