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.

RegisterRegenerateBirthdayCalendarsTest.php 3.2KB

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