‪TYPO3CMS  11.5
ExtensionConfigurationTest.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 Prophecy\PhpUnit\ProphecyTrait;
22 use TYPO3\CMS\Core\Configuration\ConfigurationManager;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪ExtensionConfigurationTest extends UnitTestCase
31 {
32  use ProphecyTrait;
33 
38  {
39  ‪$extConf = [
40  'aFeature' => 'iAmEnabled',
41  'aFlagCategory' => [
42  'someFlag' => 'foo',
43  ],
44  ];
45  ‪$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['someExtension'] = ‪$extConf;
46  self::assertSame((new ‪ExtensionConfiguration())->get('someExtension'), ‪$extConf);
47  }
48 
52  public function ‪getWithPathReturnsGivenValue(): void
53  {
54  ‪$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['someExtension'] = [
55  'aFeature' => 'iAmEnabled',
56  'aFlagCategory' => [
57  'someFlag' => 'foo',
58  ],
59  ];
60  self::assertSame((new ‪ExtensionConfiguration())->get('someExtension', 'aFeature'), 'iAmEnabled');
61  }
62 
66  public function ‪getWithPathReturnsGivenPathSegment(): void
67  {
68  ‪$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['someExtension'] = [
69  'aFeature' => 'iAmEnabled',
70  'aFlagCategory' => [
71  'someFlag' => 'foo',
72  ],
73  ];
74  self::assertSame((new ‪ExtensionConfiguration())->get('someExtension', 'aFlagCategory'), ['someFlag' => 'foo']);
75  }
76 
80  public function ‪setThrowsExceptionWithEmptyExtension(): void
81  {
82  $this->expectException(\RuntimeException::class);
83  $this->expectExceptionCode(1509715852);
84  (new ‪ExtensionConfiguration())->set('');
85  }
86 
90  public function ‪setRemovesFullExtensionConfiguration(): void
91  {
92  $configurationManagerProphecy = $this->prophesize(ConfigurationManager::class);
93  GeneralUtility::addInstance(ConfigurationManager::class, $configurationManagerProphecy->reveal());
94  $configurationManagerProphecy->removeLocalConfigurationKeysByPath(['EXTENSIONS/foo'])->shouldBeCalled();
95  (new ‪ExtensionConfiguration())->set('foo');
96  }
97 
101  public function ‪setWritesFullExtensionConfig(): void
102  {
103  $configurationManagerProphecy = $this->prophesize(ConfigurationManager::class);
104  GeneralUtility::addInstance(ConfigurationManager::class, $configurationManagerProphecy->reveal());
105  $configurationManagerProphecy->setLocalConfigurationValueByPath(Argument::cetera())->shouldBeCalled();
106  $configurationManagerProphecy->setLocalConfigurationValueByPath('EXTENSIONS/foo', ['bar' => 'baz'])->shouldBeCalled();
107  (new ‪ExtensionConfiguration())->set('foo', ['bar' => 'baz']);
108  }
109 }
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:45
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest
Definition: ExtensionConfigurationTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\getWithPathReturnsGivenValue
‪getWithPathReturnsGivenValue()
Definition: ExtensionConfigurationTest.php:51
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\setThrowsExceptionWithEmptyExtension
‪setThrowsExceptionWithEmptyExtension()
Definition: ExtensionConfigurationTest.php:79
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\getWithPathReturnsGivenPathSegment
‪getWithPathReturnsGivenPathSegment()
Definition: ExtensionConfigurationTest.php:65
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\setRemovesFullExtensionConfiguration
‪setRemovesFullExtensionConfiguration()
Definition: ExtensionConfigurationTest.php:89
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\setWritesFullExtensionConfig
‪setWritesFullExtensionConfig()
Definition: ExtensionConfigurationTest.php:100
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\getWithEmptyPathReturnsEntireExtensionConfiguration
‪getWithEmptyPathReturnsEntireExtensionConfiguration()
Definition: ExtensionConfigurationTest.php:36
‪$extConf
‪$extConf
Definition: ext_localconf.php:59
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Tests\Unit\Configuration
Definition: ConfigurationManagerTest.php:18