‪TYPO3CMS  9.5
ConfigurationServiceTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 use Prophecy\Argument;
7 use Psr\Http\Message\ServerRequestInterface;
12 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
13 
14 class ‪ConfigurationServiceTest extends UnitTestCase
15 {
19  protected ‪$beUserProphecy;
20 
21  public function ‪setUp()
22  {
23  parent::setUp();
24  $this->beUserProphecy = $this->prophesize(BackendUserAuthentication::class);
25  ‪$GLOBALS['BE_USER'] = $this->beUserProphecy->reveal();
26  }
27 
32  {
33  $userTsAdmPanelConfig = [
34  'enable.' => [
35  'all' => '1',
36  ],
37  ];
38  $this->‪setUpUserTsConfigForAdmPanel($userTsAdmPanelConfig);
39 
40  $configurationService = new ‪ConfigurationService();
41  $result = $configurationService->getMainConfiguration();
42 
43  self::assertSame($userTsAdmPanelConfig, $result);
44  }
45 
50  {
51  $configurationService = new ConfigurationService();
52  $result = $configurationService->getConfigurationOption('foo', 'bar');
53  self::assertSame('', $result);
54  }
55 
60  {
62  [
63  'override.' => [
64  'preview.' => [
65  'showHiddenPages' => '1',
66  ],
67  ],
68  ]
69  );
70 
71  $configurationService = new ConfigurationService();
72  $result = $configurationService->getConfigurationOption('preview', 'showHiddenPages');
73 
74  self::assertSame('1', $result);
75  }
76 
80  public function ‪getConfigurationOptionCastsResultToString(): void
81  {
83  [
84  'override.' => [
85  'preview.' => [
86  'showHiddenPages' => 1,
87  ],
88  ],
89  ]
90  );
91 
92  $configurationService = new ConfigurationService();
93  $result = $configurationService->getConfigurationOption('preview', 'showHiddenPages');
94 
95  self::assertSame('1', $result);
96  }
97 
99  {
100  return [
101  'empty identifier' => [
102  '',
103  'foo',
104  ],
105  'empty option' => [
106  'foo',
107  '',
108  ],
109  'both empty' => [
110  '',
111  '',
112  ],
113  ];
114  }
115 
122  public function ‪getConfigurationOptionThrowsExceptionOnEmptyArgument($identifier, $option): void
123  {
124  $this->expectException(\InvalidArgumentException::class);
125  $this->expectExceptionCode(1532861423);
126 
127  $configurationService = new ‪ConfigurationService();
128  $configurationService->getConfigurationOption($identifier, $option);
129  }
130 
135  {
137  $this->beUserProphecy->uc = [
138  'AdminPanel' => [
139  'preview_showHiddenPages' => '1',
140  ],
141  ];
142 
143  $configurationService = new ConfigurationService();
144  $result = $configurationService->getConfigurationOption('preview', 'showHiddenPages');
145 
146  self::assertSame('1', $result);
147  }
148 
153  {
154  $subModuleFixture = $this->prophesize(SubModuleFixture::class);
155  $mainModuleFixture = $this->prophesize(MainModuleFixture::class);
156  $mainModuleFixture->isEnabled()->willReturn(true);
157  $mainModuleFixture->onSubmit(Argument::cetera())->shouldBeCalled()->hasReturnVoid();
158  $mainModuleFixture->getSubModules()->willReturn(
159  [$subModuleFixture->reveal()]
160  );
161  $modules = [
162  $mainModuleFixture->reveal(),
163  ];
164 
165  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
166 
167  $configurationService = new ConfigurationService();
168  $configurationService->saveConfiguration($modules, $requestProphecy->reveal());
169 
170  $mainModuleFixture->onSubmit([], $requestProphecy->reveal())->shouldHaveBeenCalled();
171  $subModuleFixture->onSubmit([], $requestProphecy->reveal())->shouldHaveBeenCalled();
172  }
173 
178  {
179  // existing configuration from UC
180  $this->beUserProphecy->uc = [
181  'AdminPanel' => [
182  'foo' => 'bar',
183  ],
184  ];
185 
186  // new configuration to save
187  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
188  $requestProphecy->getParsedBody()->willReturn(
189  [
190  'TSFE_ADMIN_PANEL' => [
191  'baz' => 'bam',
192  ],
193  ]
194  );
195 
196  $configurationService = new ConfigurationService();
197  $configurationService->saveConfiguration([], $requestProphecy->reveal());
198 
199  $expected = [
200  'AdminPanel' => [
201  'foo' => 'bar',
202  'baz' => 'bam',
203  ],
204  ];
205  self::assertSame($expected, $this->beUserProphecy->uc);
206  $this->beUserProphecy->writeUC()->shouldHaveBeenCalled();
207  }
208 
212  private function ‪setUpUserTsConfigForAdmPanel($userTsAdmPanelConfig): void
213  {
214  $this->beUserProphecy->getTSConfig()->willReturn(
215  ['admPanel.' => $userTsAdmPanelConfig]
216  );
217  }
218 }
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\getMainConfigurationReturnsTsConfigFromUser
‪getMainConfigurationReturnsTsConfigFromUser()
Definition: ConfigurationServiceTest.php:30
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\setUpUserTsConfigForAdmPanel
‪setUpUserTsConfigForAdmPanel($userTsAdmPanelConfig)
Definition: ConfigurationServiceTest.php:211
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\$beUserProphecy
‪BackendUserAuthentication Prophecy Prophecy ObjectProphecy $beUserProphecy
Definition: ConfigurationServiceTest.php:18
‪TYPO3\CMS\Adminpanel\Tests\Unit\Fixtures\MainModuleFixture
Definition: MainModuleFixture.php:38
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\getConfigurationOptionReturnsEmptyStringIfNoConfigurationFound
‪getConfigurationOptionReturnsEmptyStringIfNoConfigurationFound()
Definition: ConfigurationServiceTest.php:48
‪TYPO3\CMS\Adminpanel\Service\ConfigurationService
Definition: ConfigurationService.php:33
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\getConfigurationOptionReturnsSettingFromUcIfNoOverrideGiven
‪getConfigurationOptionReturnsSettingFromUcIfNoOverrideGiven()
Definition: ConfigurationServiceTest.php:133
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\setUp
‪setUp()
Definition: ConfigurationServiceTest.php:20
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service
Definition: ConfigurationServiceTest.php:4
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\getConfigurationOptionReturnsOverrideOptionIfSet
‪getConfigurationOptionReturnsOverrideOptionIfSet()
Definition: ConfigurationServiceTest.php:58
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\saveConfigurationSavesMergedExistingAndNewConfiguration
‪saveConfigurationSavesMergedExistingAndNewConfiguration()
Definition: ConfigurationServiceTest.php:176
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\getConfigurationOptionEmptyArgumentDataProvider
‪getConfigurationOptionEmptyArgumentDataProvider()
Definition: ConfigurationServiceTest.php:97
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\saveConfigurationTriggersOnSubmitOnEnabledModules
‪saveConfigurationTriggersOnSubmitOnEnabledModules()
Definition: ConfigurationServiceTest.php:151
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\getConfigurationOptionThrowsExceptionOnEmptyArgument
‪getConfigurationOptionThrowsExceptionOnEmptyArgument($identifier, $option)
Definition: ConfigurationServiceTest.php:121
‪TYPO3\CMS\Adminpanel\Tests\Unit\Fixtures\SubModuleFixture
Definition: SubModuleFixture.php:30
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest\getConfigurationOptionCastsResultToString
‪getConfigurationOptionCastsResultToString()
Definition: ConfigurationServiceTest.php:79
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ConfigurationServiceTest
Definition: ConfigurationServiceTest.php:15