RegisterRegenerateBirthdayCalendarsTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @copyright 2019 Georg Ehrke <oc.list@georgehrke.com>
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\DAV\Tests\unit\BackgroundJob;
  25. use OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob;
  26. use OCA\DAV\BackgroundJob\RegisterRegenerateBirthdayCalendars;
  27. use OCP\AppFramework\Utility\ITimeFactory;
  28. use OCP\BackgroundJob\IJobList;
  29. use OCP\IConfig;
  30. use OCP\IUser;
  31. use OCP\IUserManager;
  32. use Test\TestCase;
  33. class RegisterRegenerateBirthdayCalendarsTest extends TestCase {
  34. /** @var ITimeFactory | \PHPUnit_Framework_MockObject_MockObject */
  35. private $time;
  36. /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */
  37. private $userManager;
  38. /** @var IJobList | \PHPUnit_Framework_MockObject_MockObject */
  39. private $jobList;
  40. /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
  41. private $config;
  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->config = $this->createMock(IConfig::class);
  50. $this->backgroundJob = new RegisterRegenerateBirthdayCalendars($this->time,
  51. $this->userManager, $this->jobList);
  52. }
  53. public function testRun() {
  54. $this->userManager->expects($this->once())
  55. ->method('callForSeenUsers')
  56. ->willReturnCallback(function($closure) {
  57. $user1 = $this->createMock(IUser::class);
  58. $user1->method('getUID')->willReturn('uid1');
  59. $user2 = $this->createMock(IUser::class);
  60. $user2->method('getUID')->willReturn('uid2');
  61. $user3 = $this->createMock(IUser::class);
  62. $user3->method('getUID')->willReturn('uid3');
  63. $closure($user1);
  64. $closure($user2);
  65. $closure($user3);
  66. });
  67. $this->jobList->expects($this->at(0))
  68. ->method('add')
  69. ->with(GenerateBirthdayCalendarBackgroundJob::class, [
  70. 'userId' => 'uid1',
  71. 'purgeBeforeGenerating' => true
  72. ]);
  73. $this->jobList->expects($this->at(1))
  74. ->method('add')
  75. ->with(GenerateBirthdayCalendarBackgroundJob::class, [
  76. 'userId' => 'uid2',
  77. 'purgeBeforeGenerating' => true
  78. ]);
  79. $this->jobList->expects($this->at(2))
  80. ->method('add')
  81. ->with(GenerateBirthdayCalendarBackgroundJob::class, [
  82. 'userId' => 'uid3',
  83. 'purgeBeforeGenerating' => true
  84. ]);
  85. $this->backgroundJob->run([]);
  86. }
  87. }