‪TYPO3CMS  9.5
ExtensionConfigurationTest.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Prophecy\Argument;
19 use TYPO3\CMS\Core\Configuration\ConfigurationManager;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪ExtensionConfigurationTest extends UnitTestCase
28 {
33  {
34  ‪$extConf = [
35  'aFeature' => 'iAmEnabled',
36  'aFlagCategory' => [
37  'someFlag' => 'foo',
38  ],
39  ];
40  ‪$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['someExtension'] = ‪$extConf;
41  $this->assertSame((new ‪ExtensionConfiguration())->get('someExtension'), ‪$extConf);
42  }
43 
48  {
49  ‪$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['someExtension'] = [
50  'aFeature' => 'iAmEnabled',
51  'aFlagCategory' => [
52  'someFlag' => 'foo',
53  ],
54  ];
55  $this->assertSame((new ‪ExtensionConfiguration())->get('someExtension', 'aFeature'), 'iAmEnabled');
56  }
57 
62  {
63  ‪$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['someExtension'] = [
64  'aFeature' => 'iAmEnabled',
65  'aFlagCategory' => [
66  'someFlag' => 'foo',
67  ],
68  ];
69  $this->assertSame((new ‪ExtensionConfiguration())->get('someExtension', 'aFlagCategory'), ['someFlag' => 'foo']);
70  }
71 
76  {
77  $this->expectException(\RuntimeException::class);
78  $this->expectExceptionCode(1509715852);
79  (new ‪ExtensionConfiguration())->set('');
80  }
81 
86  {
87  $configurationManagerProphecy = $this->prophesize(ConfigurationManager::class);
88  GeneralUtility::addInstance(ConfigurationManager::class, $configurationManagerProphecy->reveal());
89  $configurationManagerProphecy->removeLocalConfigurationKeysByPath(['EXTENSIONS/foo'])->shouldBeCalled();
90  (new ‪ExtensionConfiguration())->set('foo');
91  }
92 
97  {
98  $configurationManagerProphecy = $this->prophesize(ConfigurationManager::class);
99  GeneralUtility::addInstance(ConfigurationManager::class, $configurationManagerProphecy->reveal());
100  $configurationManagerProphecy->setLocalConfigurationValueByPath(Argument::cetera())->shouldBeCalled();
101  $configurationManagerProphecy->setLocalConfigurationValueByPath('EXTENSIONS/foo', ['bar' => 'baz'])->shouldBeCalled();
102  (new ‪ExtensionConfiguration())->set('foo', '', ['bar' => 'baz']);
103  }
104 
109  {
110  $configurationManagerProphecy = $this->prophesize(ConfigurationManager::class);
111  GeneralUtility::addInstance(ConfigurationManager::class, $configurationManagerProphecy->reveal());
112  $configurationManagerProphecy->setLocalConfigurationValueByPath(Argument::cetera())->shouldBeCalled();
113  $configurationManagerProphecy->setLocalConfigurationValueByPath('EXT/extConf', ['foo' => serialize(['bar' => 'baz'])])->shouldBeCalled();
114  (new ‪ExtensionConfiguration())->set('foo', '', ['bar' => 'baz']);
115  }
116 
121  {
122  $configurationManagerProphecy = $this->prophesize(ConfigurationManager::class);
123  GeneralUtility::addInstance(ConfigurationManager::class, $configurationManagerProphecy->reveal());
124  $nestedInput = [
125  'TopLevelKey' => [
126  'subLevelKey' => true,
127  ]
128  ];
129  $expectedLegacyExtConf = [
130  'TopLevelKey.' => [
131  'subLevelKey' => true,
132  ]
133  ];
134  $configurationManagerProphecy->setLocalConfigurationValueByPath(Argument::cetera())->shouldBeCalled();
135  $configurationManagerProphecy->setLocalConfigurationValueByPath('EXT/extConf', ['someExtension' => serialize($expectedLegacyExtConf)])->shouldBeCalled();
136  (new ‪ExtensionConfiguration())->set('someExtension', '', $nestedInput);
137  }
138 
143  {
144  $configurationManagerProphecy = $this->prophesize(ConfigurationManager::class);
145  GeneralUtility::addInstance(ConfigurationManager::class, $configurationManagerProphecy->reveal());
146  $nestedInput = [
147  'aCategory' => [
148  'aSubCategory' => [
149  'aKey' => 'aValue',
150  ],
151  ],
152  ];
153  $expectedLegacyExtConf = [
154  'aCategory.' => [
155  'aSubCategory.' => [
156  'aKey' => 'aValue',
157  ],
158  ],
159  ];
160  $configurationManagerProphecy->setLocalConfigurationValueByPath(Argument::cetera())->shouldBeCalled();
161  $configurationManagerProphecy->setLocalConfigurationValueByPath('EXT/extConf', ['someExtension' => serialize($expectedLegacyExtConf)])->shouldBeCalled();
162  (new ‪ExtensionConfiguration())->set('someExtension', '', $nestedInput);
163  }
164 }
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:42
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest
Definition: ExtensionConfigurationTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\getWithPathReturnsGivenValue
‪getWithPathReturnsGivenValue()
Definition: ExtensionConfigurationTest.php:47
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\setUpdatesLegacyExtConfWithDottedArrayKeysForNestedConfigurationWithMultiNestedArrays
‪setUpdatesLegacyExtConfWithDottedArrayKeysForNestedConfigurationWithMultiNestedArrays()
Definition: ExtensionConfigurationTest.php:142
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\setThrowsExceptionWithEmptyExtension
‪setThrowsExceptionWithEmptyExtension()
Definition: ExtensionConfigurationTest.php:75
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\setUpdatesLegacyExtConfToNewValues
‪setUpdatesLegacyExtConfToNewValues()
Definition: ExtensionConfigurationTest.php:108
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\getWithPathReturnsGivenPathSegment
‪getWithPathReturnsGivenPathSegment()
Definition: ExtensionConfigurationTest.php:61
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\setRemovesFullExtensionConfiguration
‪setRemovesFullExtensionConfiguration()
Definition: ExtensionConfigurationTest.php:85
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\setWritesFullExtensionConfig
‪setWritesFullExtensionConfig()
Definition: ExtensionConfigurationTest.php:96
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\getWithEmptyPathReturnsEntireExtensionConfiguration
‪getWithEmptyPathReturnsEntireExtensionConfiguration()
Definition: ExtensionConfigurationTest.php:32
‪$extConf
‪$extConf
Definition: ext_localconf.php:50
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Tests\Unit\Configuration
Definition: ConfigurationManagerTest.php:4
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\setUpdatesLegacyExtConfWithDottedArrayKeysForNestedConfiguration
‪setUpdatesLegacyExtConfWithDottedArrayKeysForNestedConfiguration()
Definition: ExtensionConfigurationTest.php:120