RegenerateBirthdayCalendarsTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018, Georg Ehrke
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  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\DAV\Migration;
  26. use OCA\DAV\BackgroundJob\RegisterRegenerateBirthdayCalendars;
  27. use OCA\DAV\Migration\RegenerateBirthdayCalendars;
  28. use OCP\BackgroundJob\IJobList;
  29. use OCP\IConfig;
  30. use OCP\Migration\IOutput;
  31. use Test\TestCase;
  32. class RegenerateBirthdayCalendarsTest extends TestCase {
  33. /** @var IJobList | \PHPUnit_Framework_MockObject_MockObject */
  34. private $jobList;
  35. /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
  36. private $config;
  37. /** @var RegenerateBirthdayCalendars */
  38. private $migration;
  39. protected function setUp(): void {
  40. parent::setUp();
  41. $this->jobList = $this->createMock(IJobList::class);
  42. $this->config = $this->createMock(IConfig::class);
  43. $this->migration = new RegenerateBirthdayCalendars($this->jobList,
  44. $this->config);
  45. }
  46. public function testGetName() {
  47. $this->assertEquals(
  48. 'Regenerating birthday calendars to use new icons and fix old birthday events without year',
  49. $this->migration->getName()
  50. );
  51. }
  52. public function testRun() {
  53. $this->config->expects($this->at(0))
  54. ->method('getAppValue')
  55. ->with('dav', 'regeneratedBirthdayCalendarsForYearFix')
  56. ->willReturn(null);
  57. $output = $this->createMock(IOutput::class);
  58. $output->expects($this->once())
  59. ->method('info')
  60. ->with('Adding background jobs to regenerate birthday calendar');
  61. $this->jobList->expects($this->at(0))
  62. ->method('add')
  63. ->with(RegisterRegenerateBirthdayCalendars::class);
  64. $this->config->expects($this->at(1))
  65. ->method('setAppValue')
  66. ->with('dav', 'regeneratedBirthdayCalendarsForYearFix', 'yes');
  67. $this->migration->run($output);
  68. }
  69. public function testRunSecondTime() {
  70. $this->config->expects($this->once())
  71. ->method('getAppValue')
  72. ->with('dav', 'regeneratedBirthdayCalendarsForYearFix')
  73. ->willReturn('yes');
  74. $output = $this->createMock(IOutput::class);
  75. $output->expects($this->once())
  76. ->method('info')
  77. ->with('Repair step already executed');
  78. $this->jobList->expects($this->never())
  79. ->method('add');
  80. $this->migration->run($output);
  81. }
  82. }