RegisterRegenerateBirthdayCalendarsTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2019 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 Morris Jobke <hey@morrisjobke.de>
  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\GenerateBirthdayCalendarBackgroundJob;
  29. use OCA\DAV\BackgroundJob\RegisterRegenerateBirthdayCalendars;
  30. use OCP\AppFramework\Utility\ITimeFactory;
  31. use OCP\BackgroundJob\IJobList;
  32. use OCP\IUser;
  33. use OCP\IUserManager;
  34. use Test\TestCase;
  35. class RegisterRegenerateBirthdayCalendarsTest extends TestCase {
  36. /** @var ITimeFactory | \PHPUnit\Framework\MockObject\MockObject */
  37. private $time;
  38. /** @var IUserManager | \PHPUnit\Framework\MockObject\MockObject */
  39. private $userManager;
  40. /** @var IJobList | \PHPUnit\Framework\MockObject\MockObject */
  41. private $jobList;
  42. /** @var RegisterRegenerateBirthdayCalendars */
  43. private $backgroundJob;
  44. protected function setUp(): void {
  45. parent::setUp();
  46. $this->time = $this->createMock(ITimeFactory::class);
  47. $this->userManager = $this->createMock(IUserManager::class);
  48. $this->jobList = $this->createMock(IJobList::class);
  49. $this->backgroundJob = new RegisterRegenerateBirthdayCalendars(
  50. $this->time,
  51. $this->userManager,
  52. $this->jobList
  53. );
  54. }
  55. public function testRun(): void {
  56. $this->userManager->expects($this->once())
  57. ->method('callForSeenUsers')
  58. ->willReturnCallback(function ($closure): void {
  59. $user1 = $this->createMock(IUser::class);
  60. $user1->method('getUID')->willReturn('uid1');
  61. $user2 = $this->createMock(IUser::class);
  62. $user2->method('getUID')->willReturn('uid2');
  63. $user3 = $this->createMock(IUser::class);
  64. $user3->method('getUID')->willReturn('uid3');
  65. $closure($user1);
  66. $closure($user2);
  67. $closure($user3);
  68. });
  69. $this->jobList->expects($this->exactly(3))
  70. ->method('add')
  71. ->withConsecutive(
  72. [GenerateBirthdayCalendarBackgroundJob::class, [
  73. 'userId' => 'uid1',
  74. 'purgeBeforeGenerating' => true
  75. ]],
  76. [GenerateBirthdayCalendarBackgroundJob::class, [
  77. 'userId' => 'uid2',
  78. 'purgeBeforeGenerating' => true
  79. ]],
  80. [GenerateBirthdayCalendarBackgroundJob::class, [
  81. 'userId' => 'uid3',
  82. 'purgeBeforeGenerating' => true
  83. ]],
  84. );
  85. $this->backgroundJob->run([]);
  86. }
  87. }