GenerateBirthdayCalendarBackgroundJobTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017, Georg Ehrke
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\DAV\Tests\unit\BackgroundJob;
  27. use OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob;
  28. use OCA\DAV\CalDAV\BirthdayService;
  29. use OCP\IConfig;
  30. use Test\TestCase;
  31. class GenerateBirthdayCalendarBackgroundJobTest extends TestCase {
  32. /** @var BirthdayService | \PHPUnit\Framework\MockObject\MockObject */
  33. private $birthdayService;
  34. /** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */
  35. private $config;
  36. /** @var \OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob */
  37. private $backgroundJob;
  38. protected function setUp(): void {
  39. parent::setUp();
  40. $this->birthdayService = $this->createMock(BirthdayService::class);
  41. $this->config = $this->createMock(IConfig::class);
  42. $this->backgroundJob = new GenerateBirthdayCalendarBackgroundJob(
  43. $this->birthdayService, $this->config);
  44. }
  45. public function testRun() {
  46. $this->config->expects($this->once())
  47. ->method('getAppValue')
  48. ->with('dav', 'generateBirthdayCalendar', 'yes')
  49. ->willReturn('yes');
  50. $this->config->expects($this->once())
  51. ->method('getUserValue')
  52. ->with('user123', 'dav', 'generateBirthdayCalendar', 'yes')
  53. ->willReturn('yes');
  54. $this->birthdayService->expects($this->never())
  55. ->method('resetForUser')
  56. ->with('user123');
  57. $this->birthdayService->expects($this->once())
  58. ->method('syncUser')
  59. ->with('user123');
  60. $this->backgroundJob->run(['userId' => 'user123']);
  61. }
  62. public function testRunAndReset() {
  63. $this->config->expects($this->once())
  64. ->method('getAppValue')
  65. ->with('dav', 'generateBirthdayCalendar', 'yes')
  66. ->willReturn('yes');
  67. $this->config->expects($this->once())
  68. ->method('getUserValue')
  69. ->with('user123', 'dav', 'generateBirthdayCalendar', 'yes')
  70. ->willReturn('yes');
  71. $this->birthdayService->expects($this->once())
  72. ->method('resetForUser')
  73. ->with('user123');
  74. $this->birthdayService->expects($this->once())
  75. ->method('syncUser')
  76. ->with('user123');
  77. $this->backgroundJob->run(['userId' => 'user123', 'purgeBeforeGenerating' => true]);
  78. }
  79. public function testRunGloballyDisabled() {
  80. $this->config->expects($this->once())
  81. ->method('getAppValue')
  82. ->with('dav', 'generateBirthdayCalendar', 'yes')
  83. ->willReturn('no');
  84. $this->config->expects($this->never())
  85. ->method('getUserValue');
  86. $this->birthdayService->expects($this->never())
  87. ->method('syncUser');
  88. $this->backgroundJob->run(['userId' => 'user123']);
  89. }
  90. public function testRunUserDisabled() {
  91. $this->config->expects($this->once())
  92. ->method('getAppValue')
  93. ->with('dav', 'generateBirthdayCalendar', 'yes')
  94. ->willReturn('yes');
  95. $this->config->expects($this->once())
  96. ->method('getUserValue')
  97. ->with('user123', 'dav', 'generateBirthdayCalendar', 'yes')
  98. ->willReturn('no');
  99. $this->birthdayService->expects($this->never())
  100. ->method('syncUser');
  101. $this->backgroundJob->run(['userId' => 'user123']);
  102. }
  103. }