1
0

GenerateBirthdayCalendarBackgroundJobTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\Tests\unit\BackgroundJob;
  8. use OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob;
  9. use OCA\DAV\CalDAV\BirthdayService;
  10. use OCP\AppFramework\Utility\ITimeFactory;
  11. use OCP\IConfig;
  12. use PHPUnit\Framework\MockObject\MockObject;
  13. use Test\TestCase;
  14. class GenerateBirthdayCalendarBackgroundJobTest extends TestCase {
  15. /** @var ITimeFactory|MockObject */
  16. private $time;
  17. /** @var BirthdayService | MockObject */
  18. private $birthdayService;
  19. /** @var IConfig | MockObject */
  20. private $config;
  21. /** @var GenerateBirthdayCalendarBackgroundJob */
  22. private $backgroundJob;
  23. protected function setUp(): void {
  24. parent::setUp();
  25. $this->time = $this->createMock(ITimeFactory::class);
  26. $this->birthdayService = $this->createMock(BirthdayService::class);
  27. $this->config = $this->createMock(IConfig::class);
  28. $this->backgroundJob = new GenerateBirthdayCalendarBackgroundJob(
  29. $this->time,
  30. $this->birthdayService,
  31. $this->config,
  32. );
  33. }
  34. public function testRun(): void {
  35. $this->config->expects($this->once())
  36. ->method('getAppValue')
  37. ->with('dav', 'generateBirthdayCalendar', 'yes')
  38. ->willReturn('yes');
  39. $this->config->expects($this->once())
  40. ->method('getUserValue')
  41. ->with('user123', 'dav', 'generateBirthdayCalendar', 'yes')
  42. ->willReturn('yes');
  43. $this->birthdayService->expects($this->never())
  44. ->method('resetForUser')
  45. ->with('user123');
  46. $this->birthdayService->expects($this->once())
  47. ->method('syncUser')
  48. ->with('user123');
  49. $this->backgroundJob->run(['userId' => 'user123']);
  50. }
  51. public function testRunAndReset(): void {
  52. $this->config->expects($this->once())
  53. ->method('getAppValue')
  54. ->with('dav', 'generateBirthdayCalendar', 'yes')
  55. ->willReturn('yes');
  56. $this->config->expects($this->once())
  57. ->method('getUserValue')
  58. ->with('user123', 'dav', 'generateBirthdayCalendar', 'yes')
  59. ->willReturn('yes');
  60. $this->birthdayService->expects($this->once())
  61. ->method('resetForUser')
  62. ->with('user123');
  63. $this->birthdayService->expects($this->once())
  64. ->method('syncUser')
  65. ->with('user123');
  66. $this->backgroundJob->run(['userId' => 'user123', 'purgeBeforeGenerating' => true]);
  67. }
  68. public function testRunGloballyDisabled(): void {
  69. $this->config->expects($this->once())
  70. ->method('getAppValue')
  71. ->with('dav', 'generateBirthdayCalendar', 'yes')
  72. ->willReturn('no');
  73. $this->config->expects($this->never())
  74. ->method('getUserValue');
  75. $this->birthdayService->expects($this->never())
  76. ->method('syncUser');
  77. $this->backgroundJob->run(['userId' => 'user123']);
  78. }
  79. public function testRunUserDisabled(): void {
  80. $this->config->expects($this->once())
  81. ->method('getAppValue')
  82. ->with('dav', 'generateBirthdayCalendar', 'yes')
  83. ->willReturn('yes');
  84. $this->config->expects($this->once())
  85. ->method('getUserValue')
  86. ->with('user123', 'dav', 'generateBirthdayCalendar', 'yes')
  87. ->willReturn('no');
  88. $this->birthdayService->expects($this->never())
  89. ->method('syncUser');
  90. $this->backgroundJob->run(['userId' => 'user123']);
  91. }
  92. }