1
0

AdminTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Theming\Tests\Settings;
  7. use OCA\Theming\AppInfo\Application;
  8. use OCA\Theming\ImageManager;
  9. use OCA\Theming\Settings\Admin;
  10. use OCA\Theming\ThemingDefaults;
  11. use OCP\AppFramework\Http\TemplateResponse;
  12. use OCP\AppFramework\Services\IInitialState;
  13. use OCP\IConfig;
  14. use OCP\IL10N;
  15. use OCP\IURLGenerator;
  16. use Test\TestCase;
  17. class AdminTest extends TestCase {
  18. private Admin $admin;
  19. private IConfig $config;
  20. private ThemingDefaults $themingDefaults;
  21. private IInitialState $initialState;
  22. private IURLGenerator $urlGenerator;
  23. private ImageManager $imageManager;
  24. private IL10N $l10n;
  25. protected function setUp(): void {
  26. parent::setUp();
  27. $this->config = $this->createMock(IConfig::class);
  28. $this->l10n = $this->createMock(IL10N::class);
  29. $this->themingDefaults = $this->createMock(ThemingDefaults::class);
  30. $this->initialState = $this->createMock(IInitialState::class);
  31. $this->urlGenerator = $this->createMock(IURLGenerator::class);
  32. $this->imageManager = $this->createMock(ImageManager::class);
  33. $this->admin = new Admin(
  34. Application::APP_ID,
  35. $this->config,
  36. $this->l10n,
  37. $this->themingDefaults,
  38. $this->initialState,
  39. $this->urlGenerator,
  40. $this->imageManager
  41. );
  42. }
  43. public function testGetFormNoErrors() {
  44. $this->config
  45. ->expects($this->once())
  46. ->method('getSystemValue')
  47. ->with('theme', '')
  48. ->willReturn('');
  49. $this->themingDefaults
  50. ->expects($this->once())
  51. ->method('getEntity')
  52. ->willReturn('MyEntity');
  53. $this->themingDefaults
  54. ->expects($this->once())
  55. ->method('getBaseUrl')
  56. ->willReturn('https://example.com');
  57. $this->themingDefaults
  58. ->expects($this->once())
  59. ->method('getImprintUrl')
  60. ->willReturn('');
  61. $this->themingDefaults
  62. ->expects($this->once())
  63. ->method('getPrivacyUrl')
  64. ->willReturn('');
  65. $this->themingDefaults
  66. ->expects($this->once())
  67. ->method('getSlogan')
  68. ->willReturn('MySlogan');
  69. $this->themingDefaults
  70. ->expects($this->once())
  71. ->method('getDefaultColorPrimary')
  72. ->willReturn('#fff');
  73. $expected = new TemplateResponse('theming', 'settings-admin');
  74. $this->assertEquals($expected, $this->admin->getForm());
  75. }
  76. public function testGetFormWithErrors() {
  77. $this->config
  78. ->expects($this->once())
  79. ->method('getSystemValue')
  80. ->with('theme', '')
  81. ->willReturn('MyCustomTheme');
  82. $this->l10n
  83. ->expects($this->once())
  84. ->method('t')
  85. ->with('You are already using a custom theme. Theming app settings might be overwritten by that.')
  86. ->willReturn('You are already using a custom theme. Theming app settings might be overwritten by that.');
  87. $this->themingDefaults
  88. ->expects($this->once())
  89. ->method('getEntity')
  90. ->willReturn('MyEntity');
  91. $this->themingDefaults
  92. ->expects($this->once())
  93. ->method('getBaseUrl')
  94. ->willReturn('https://example.com');
  95. $this->themingDefaults
  96. ->expects($this->once())
  97. ->method('getImprintUrl')
  98. ->willReturn('');
  99. $this->themingDefaults
  100. ->expects($this->once())
  101. ->method('getPrivacyUrl')
  102. ->willReturn('');
  103. $this->themingDefaults
  104. ->expects($this->once())
  105. ->method('getSlogan')
  106. ->willReturn('MySlogan');
  107. $this->themingDefaults
  108. ->expects($this->once())
  109. ->method('getDefaultColorPrimary')
  110. ->willReturn('#fff');
  111. $expected = new TemplateResponse('theming', 'settings-admin');
  112. $this->assertEquals($expected, $this->admin->getForm());
  113. }
  114. public function testGetSection() {
  115. $this->assertSame('theming', $this->admin->getSection());
  116. }
  117. public function testGetPriority() {
  118. $this->assertSame(5, $this->admin->getPriority());
  119. }
  120. }