GenerateBirthdayCalendarBackgroundJobTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017, Georg Ehrke
  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\CalDAV\BirthdayService;
  27. use OCP\IConfig;
  28. use Test\TestCase;
  29. class GenerateBirthdayCalendarBackgroundJobTest extends TestCase {
  30. /** @var BirthdayService | \PHPUnit_Framework_MockObject_MockObject */
  31. private $birthdayService;
  32. /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
  33. private $config;
  34. /** @var \OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob */
  35. private $backgroundJob;
  36. protected function setUp(): void {
  37. parent::setUp();
  38. $this->birthdayService = $this->createMock(BirthdayService::class);
  39. $this->config = $this->createMock(IConfig::class);
  40. $this->backgroundJob = new GenerateBirthdayCalendarBackgroundJob(
  41. $this->birthdayService, $this->config);
  42. }
  43. public function testRun() {
  44. $this->config->expects($this->once())
  45. ->method('getAppValue')
  46. ->with('dav', 'generateBirthdayCalendar', 'yes')
  47. ->willReturn('yes');
  48. $this->config->expects($this->once())
  49. ->method('getUserValue')
  50. ->with('user123', 'dav', 'generateBirthdayCalendar', 'yes')
  51. ->willReturn('yes');
  52. $this->birthdayService->expects($this->never())
  53. ->method('resetForUser')
  54. ->with('user123');
  55. $this->birthdayService->expects($this->once())
  56. ->method('syncUser')
  57. ->with('user123');
  58. $this->backgroundJob->run(['userId' => 'user123']);
  59. }
  60. public function testRunAndReset() {
  61. $this->config->expects($this->once())
  62. ->method('getAppValue')
  63. ->with('dav', 'generateBirthdayCalendar', 'yes')
  64. ->willReturn('yes');
  65. $this->config->expects($this->once())
  66. ->method('getUserValue')
  67. ->with('user123', 'dav', 'generateBirthdayCalendar', 'yes')
  68. ->willReturn('yes');
  69. $this->birthdayService->expects($this->once())
  70. ->method('resetForUser')
  71. ->with('user123');
  72. $this->birthdayService->expects($this->once())
  73. ->method('syncUser')
  74. ->with('user123');
  75. $this->backgroundJob->run(['userId' => 'user123', 'purgeBeforeGenerating' => true]);
  76. }
  77. public function testRunGloballyDisabled() {
  78. $this->config->expects($this->once())
  79. ->method('getAppValue')
  80. ->with('dav', 'generateBirthdayCalendar', 'yes')
  81. ->willReturn('no');
  82. $this->config->expects($this->never())
  83. ->method('getUserValue');
  84. $this->birthdayService->expects($this->never())
  85. ->method('syncUser');
  86. $this->backgroundJob->run(['userId' => 'user123']);
  87. }
  88. public function testRunUserDisabled() {
  89. $this->config->expects($this->once())
  90. ->method('getAppValue')
  91. ->with('dav', 'generateBirthdayCalendar', 'yes')
  92. ->willReturn('yes');
  93. $this->config->expects($this->once())
  94. ->method('getUserValue')
  95. ->with('user123', 'dav', 'generateBirthdayCalendar', 'yes')
  96. ->willReturn('no');
  97. $this->birthdayService->expects($this->never())
  98. ->method('syncUser');
  99. $this->backgroundJob->run(['userId' => 'user123']);
  100. }
  101. }