‪TYPO3CMS  10.4
ConfigurationServiceTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Prophecy\Argument;
21 use Psr\Http\Message\ServerRequestInterface;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
28 class ‪ConfigurationServiceTest extends UnitTestCase
29 {
33  protected ‪$beUserProphecy;
34 
35  public function ‪setUp(): void
36  {
37  parent::setUp();
38  $this->beUserProphecy = $this->prophesize(BackendUserAuthentication::class);
39  ‪$GLOBALS['BE_USER'] = $this->beUserProphecy->reveal();
40  }
41 
46  {
47  $userTsAdmPanelConfig = [
48  'enable.' => [
49  'all' => '1',
50  ],
51  ];
52  $this->‪setUpUserTsConfigForAdmPanel($userTsAdmPanelConfig);
53 
54  $configurationService = new ‪ConfigurationService();
55  $result = $configurationService->getMainConfiguration();
56 
57  self::assertSame($userTsAdmPanelConfig, $result);
58  }
59 
64  {
65  $configurationService = new ConfigurationService();
66  $result = $configurationService->getConfigurationOption('foo', 'bar');
67  self::assertSame('', $result);
68  }
69 
74  {
76  [
77  'override.' => [
78  'preview.' => [
79  'showHiddenPages' => '1',
80  ],
81  ],
82  ]
83  );
84 
85  $configurationService = new ConfigurationService();
86  $result = $configurationService->getConfigurationOption('preview', 'showHiddenPages');
87 
88  self::assertSame('1', $result);
89  }
90 
94  public function ‪getConfigurationOptionCastsResultToString(): void
95  {
97  [
98  'override.' => [
99  'preview.' => [
100  'showHiddenPages' => 1,
101  ],
102  ],
103  ]
104  );
105 
106  $configurationService = new ConfigurationService();
107  $result = $configurationService->getConfigurationOption('preview', 'showHiddenPages');
108 
109  self::assertSame('1', $result);
110  }
111 
113  {
114  return [
115  'empty identifier' => [
116  '',
117  'foo',
118  ],
119  'empty option' => [
120  'foo',
121  '',
122  ],
123  'both empty' => [
124  '',
125  '',
126  ],
127  ];
128  }
129 
136  public function ‪getConfigurationOptionThrowsExceptionOnEmptyArgument($identifier, $option): void
137  {
138  $this->expectException(\InvalidArgumentException::class);
139  $this->expectExceptionCode(1532861423);
140 
141  $configurationService = new ‪ConfigurationService();
142  $configurationService->getConfigurationOption($identifier, $option);
143  }
144 
149  {
151  $this->beUserProphecy->uc = [
152  'AdminPanel' => [
153  'preview_showHiddenPages' => '1',
154  ],
155  ];
156 
157  $configurationService = new ConfigurationService();
158  $result = $configurationService->getConfigurationOption('preview', 'showHiddenPages');
159 
160  self::assertSame('1', $result);
161  }
162 
167  {
168  $subModuleFixture = $this->prophesize(SubModuleFixture::class);
169  $mainModuleFixture = $this->prophesize(MainModuleFixture::class);
170  $mainModuleFixture->isEnabled()->willReturn(true);
171  $mainModuleFixture->onSubmit(Argument::cetera())->shouldBeCalled()->hasReturnVoid();
172  $mainModuleFixture->getSubModules()->willReturn(
173  [$subModuleFixture->reveal()]
174  );
175  $modules = [
176  $mainModuleFixture->reveal(),
177  ];
178 
179  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
180 
181  $configurationService = new ConfigurationService();
182  $configurationService->saveConfiguration($modules, $requestProphecy->reveal());
183 
184  $mainModuleFixture->onSubmit([], $requestProphecy->reveal())->shouldHaveBeenCalled();
185  $subModuleFixture->onSubmit([], $requestProphecy->reveal())->shouldHaveBeenCalled();
186  }
187 
192  {
193  // existing configuration from UC
194  $this->beUserProphecy->uc = [
195  'AdminPanel' => [
196  'foo' => 'bar',
197  ],
198  ];
199 
200  // new configuration to save
201  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
202  $requestProphecy->getParsedBody()->willReturn(
203  [
204  'TSFE_ADMIN_PANEL' => [
205  'baz' => 'bam',
206  ],
207  ]
208  );
209 
210  $configurationService = new ConfigurationService();
211  $configurationService->saveConfiguration([], $requestProphecy->reveal());
212 
213  $expected = [
214  'AdminPanel' => [
215  'foo' => 'bar',
216  'baz' => 'bam',
217  ],
218  ];
219  self::assertSame($expected, $this->beUserProphecy->uc);
220  $this->beUserProphecy->writeUC()->shouldHaveBeenCalled();
221  }
222 
226  private function ‪setUpUserTsConfigForAdmPanel($userTsAdmPanelConfig): void
227  {
228  $this->beUserProphecy->getTSConfig()->willReturn(
229  ['admPanel.' => $userTsAdmPanelConfig]
230  );
231  }
232 }
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\getMainConfigurationReturnsTsConfigFromUser
‪getMainConfigurationReturnsTsConfigFromUser()
Definition: ConfigurationServiceTest.php:44
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\setUpUserTsConfigForAdmPanel
‪setUpUserTsConfigForAdmPanel($userTsAdmPanelConfig)
Definition: ConfigurationServiceTest.php:225
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\$beUserProphecy
‪BackendUserAuthentication Prophecy Prophecy ObjectProphecy $beUserProphecy
Definition: ConfigurationServiceTest.php:32
‪TYPO3\CMS\Adminpanel\Tests\Unit\Fixtures\MainModuleFixture
Definition: MainModuleFixture.php:39
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\getConfigurationOptionReturnsEmptyStringIfNoConfigurationFound
‪getConfigurationOptionReturnsEmptyStringIfNoConfigurationFound()
Definition: ConfigurationServiceTest.php:62
‪TYPO3\CMS\Adminpanel\Service\ConfigurationService
Definition: ConfigurationService.php:34
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\getConfigurationOptionReturnsSettingFromUcIfNoOverrideGiven
‪getConfigurationOptionReturnsSettingFromUcIfNoOverrideGiven()
Definition: ConfigurationServiceTest.php:147
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\setUp
‪setUp()
Definition: ConfigurationServiceTest.php:34
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service
Definition: ConfigurationServiceTest.php:18
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\getConfigurationOptionReturnsOverrideOptionIfSet
‪getConfigurationOptionReturnsOverrideOptionIfSet()
Definition: ConfigurationServiceTest.php:72
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\saveConfigurationSavesMergedExistingAndNewConfiguration
‪saveConfigurationSavesMergedExistingAndNewConfiguration()
Definition: ConfigurationServiceTest.php:190
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\getConfigurationOptionEmptyArgumentDataProvider
‪getConfigurationOptionEmptyArgumentDataProvider()
Definition: ConfigurationServiceTest.php:111
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\saveConfigurationTriggersOnSubmitOnEnabledModules
‪saveConfigurationTriggersOnSubmitOnEnabledModules()
Definition: ConfigurationServiceTest.php:165
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\getConfigurationOptionThrowsExceptionOnEmptyArgument
‪getConfigurationOptionThrowsExceptionOnEmptyArgument($identifier, $option)
Definition: ConfigurationServiceTest.php:135
‪TYPO3\CMS\Adminpanel\Tests\Unit\Fixtures\SubModuleFixture
Definition: SubModuleFixture.php:31
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\getConfigurationOptionCastsResultToString
‪getConfigurationOptionCastsResultToString()
Definition: ConfigurationServiceTest.php:93
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest
Definition: ConfigurationServiceTest.php:29