RegenerateBirthdayCalendarsTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018, Georg Ehrke
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author François Freitag <mail@franek.fr>
  7. * @author Georg Ehrke <oc.list@georgehrke.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. *
  11. * @license GNU AGPL version 3 or any later version
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as
  15. * published by the Free Software Foundation, either version 3 of the
  16. * License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *
  26. */
  27. namespace OCA\DAV\Tests\unit\DAV\Migration;
  28. use OCA\DAV\BackgroundJob\RegisterRegenerateBirthdayCalendars;
  29. use OCA\DAV\Migration\RegenerateBirthdayCalendars;
  30. use OCP\BackgroundJob\IJobList;
  31. use OCP\IConfig;
  32. use OCP\Migration\IOutput;
  33. use Test\TestCase;
  34. class RegenerateBirthdayCalendarsTest extends TestCase {
  35. /** @var IJobList | \PHPUnit\Framework\MockObject\MockObject */
  36. private $jobList;
  37. /** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */
  38. private $config;
  39. /** @var RegenerateBirthdayCalendars */
  40. private $migration;
  41. protected function setUp(): void {
  42. parent::setUp();
  43. $this->jobList = $this->createMock(IJobList::class);
  44. $this->config = $this->createMock(IConfig::class);
  45. $this->migration = new RegenerateBirthdayCalendars($this->jobList,
  46. $this->config);
  47. }
  48. public function testGetName(): void {
  49. $this->assertEquals(
  50. 'Regenerating birthday calendars to use new icons and fix old birthday events without year',
  51. $this->migration->getName()
  52. );
  53. }
  54. public function testRun(): void {
  55. $this->config->expects($this->once())
  56. ->method('getAppValue')
  57. ->with('dav', 'regeneratedBirthdayCalendarsForYearFix')
  58. ->willReturn(null);
  59. $output = $this->createMock(IOutput::class);
  60. $output->expects($this->once())
  61. ->method('info')
  62. ->with('Adding background jobs to regenerate birthday calendar');
  63. $this->jobList->expects($this->once())
  64. ->method('add')
  65. ->with(RegisterRegenerateBirthdayCalendars::class);
  66. $this->config->expects($this->once())
  67. ->method('setAppValue')
  68. ->with('dav', 'regeneratedBirthdayCalendarsForYearFix', 'yes');
  69. $this->migration->run($output);
  70. }
  71. public function testRunSecondTime(): void {
  72. $this->config->expects($this->once())
  73. ->method('getAppValue')
  74. ->with('dav', 'regeneratedBirthdayCalendarsForYearFix')
  75. ->willReturn('yes');
  76. $output = $this->createMock(IOutput::class);
  77. $output->expects($this->once())
  78. ->method('info')
  79. ->with('Repair step already executed');
  80. $this->jobList->expects($this->never())
  81. ->method('add');
  82. $this->migration->run($output);
  83. }
  84. }