RegenerateBirthdayCalendarsTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\DAV\Tests\unit\DAV\Migration;
  7. use OCA\DAV\BackgroundJob\RegisterRegenerateBirthdayCalendars;
  8. use OCA\DAV\Migration\RegenerateBirthdayCalendars;
  9. use OCP\BackgroundJob\IJobList;
  10. use OCP\IConfig;
  11. use OCP\Migration\IOutput;
  12. use Test\TestCase;
  13. class RegenerateBirthdayCalendarsTest extends TestCase {
  14. /** @var IJobList | \PHPUnit\Framework\MockObject\MockObject */
  15. private $jobList;
  16. /** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */
  17. private $config;
  18. /** @var RegenerateBirthdayCalendars */
  19. private $migration;
  20. protected function setUp(): void {
  21. parent::setUp();
  22. $this->jobList = $this->createMock(IJobList::class);
  23. $this->config = $this->createMock(IConfig::class);
  24. $this->migration = new RegenerateBirthdayCalendars($this->jobList,
  25. $this->config);
  26. }
  27. public function testGetName(): void {
  28. $this->assertEquals(
  29. 'Regenerating birthday calendars to use new icons and fix old birthday events without year',
  30. $this->migration->getName()
  31. );
  32. }
  33. public function testRun(): void {
  34. $this->config->expects($this->once())
  35. ->method('getAppValue')
  36. ->with('dav', 'regeneratedBirthdayCalendarsForYearFix')
  37. ->willReturn(null);
  38. $output = $this->createMock(IOutput::class);
  39. $output->expects($this->once())
  40. ->method('info')
  41. ->with('Adding background jobs to regenerate birthday calendar');
  42. $this->jobList->expects($this->once())
  43. ->method('add')
  44. ->with(RegisterRegenerateBirthdayCalendars::class);
  45. $this->config->expects($this->once())
  46. ->method('setAppValue')
  47. ->with('dav', 'regeneratedBirthdayCalendarsForYearFix', 'yes');
  48. $this->migration->run($output);
  49. }
  50. public function testRunSecondTime(): void {
  51. $this->config->expects($this->once())
  52. ->method('getAppValue')
  53. ->with('dav', 'regeneratedBirthdayCalendarsForYearFix')
  54. ->willReturn('yes');
  55. $output = $this->createMock(IOutput::class);
  56. $output->expects($this->once())
  57. ->method('info')
  58. ->with('Repair step already executed');
  59. $this->jobList->expects($this->never())
  60. ->method('add');
  61. $this->migration->run($output);
  62. }
  63. }