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.

GenerateBirthdayCalendarBackgroundJobTest.php 3.8KB

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