CalDAVSettingsTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\DAV\Tests\Unit\DAV\Settings;
  7. use OCA\DAV\Settings\CalDAVSettings;
  8. use OCP\App\IAppManager;
  9. use OCP\AppFramework\Http\TemplateResponse;
  10. use OCP\AppFramework\Services\IInitialState;
  11. use OCP\IConfig;
  12. use OCP\IURLGenerator;
  13. use PHPUnit\Framework\MockObject\MockObject;
  14. use Test\TestCase;
  15. class CalDAVSettingsTest extends TestCase {
  16. /** @var IConfig|MockObject */
  17. private $config;
  18. /** @var IInitialState|MockObject */
  19. private $initialState;
  20. /** @var IURLGenerator|MockObject */
  21. private $urlGenerator;
  22. /** @var IAppManager|MockObject */
  23. private $appManager;
  24. private CalDAVSettings $settings;
  25. protected function setUp(): void {
  26. parent::setUp();
  27. $this->config = $this->createMock(IConfig::class);
  28. $this->initialState = $this->createMock(IInitialState::class);
  29. $this->urlGenerator = $this->createMock(IURLGenerator::class);
  30. $this->appManager = $this->createMock(IAppManager::class);
  31. $this->settings = new CalDAVSettings($this->config, $this->initialState, $this->urlGenerator, $this->appManager);
  32. }
  33. public function testGetForm(): void {
  34. $this->config->method('getAppValue')
  35. ->withConsecutive(
  36. ['dav', 'sendInvitations', 'yes'],
  37. ['dav', 'generateBirthdayCalendar', 'yes'],
  38. ['dav', 'sendEventReminders', 'yes'],
  39. ['dav', 'sendEventRemindersToSharedUsers', 'yes'],
  40. ['dav', 'sendEventRemindersPush', 'yes'],
  41. )
  42. ->will($this->onConsecutiveCalls('yes', 'no', 'yes', 'yes', 'yes'));
  43. $this->urlGenerator
  44. ->expects($this->once())
  45. ->method('linkToDocs')
  46. ->with('user-sync-calendars')
  47. ->willReturn('Some docs URL');
  48. $this->initialState->method('provideInitialState')
  49. ->withConsecutive(
  50. ['userSyncCalendarsDocUrl', 'Some docs URL'],
  51. ['sendInvitations', true],
  52. ['generateBirthdayCalendar', false],
  53. ['sendEventReminders', true],
  54. ['sendEventRemindersToSharedUsers', true],
  55. ['sendEventRemindersPush', true],
  56. );
  57. $result = $this->settings->getForm();
  58. $this->assertInstanceOf(TemplateResponse::class, $result);
  59. }
  60. public function testGetSection(): void {
  61. $this->appManager->expects(self::once())
  62. ->method('isBackendRequired')
  63. ->with(IAppManager::BACKEND_CALDAV)
  64. ->willReturn(true);
  65. $this->assertEquals('groupware', $this->settings->getSection());
  66. }
  67. public function testGetSectionWithoutCaldavBackend(): void {
  68. $this->appManager->expects(self::once())
  69. ->method('isBackendRequired')
  70. ->with(IAppManager::BACKEND_CALDAV)
  71. ->willReturn(false);
  72. $this->assertEquals(null, $this->settings->getSection());
  73. }
  74. public function testGetPriority(): void {
  75. $this->assertEquals(10, $this->settings->getPriority());
  76. }
  77. }