‪TYPO3CMS  ‪main
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 PHPUnit\Framework\Attributes\Test;
21 use TYPO3\CMS\Core\Configuration\ConfigurationManager;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
26 final class ‪ExtensionConfigurationTest extends UnitTestCase
27 {
28  #[Test]
30  {
31  $extConf = [
32  'aFeature' => 'iAmEnabled',
33  'aFlagCategory' => [
34  'someFlag' => 'foo',
35  ],
36  ];
37  ‪$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['someExtension'] = $extConf;
38  self::assertSame((new ‪ExtensionConfiguration())->get('someExtension'), $extConf);
39  }
40 
41  #[Test]
42  public function ‪getWithPathReturnsGivenValue(): void
43  {
44  ‪$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['someExtension'] = [
45  'aFeature' => 'iAmEnabled',
46  'aFlagCategory' => [
47  'someFlag' => 'foo',
48  ],
49  ];
50  self::assertSame((new ‪ExtensionConfiguration())->get('someExtension', 'aFeature'), 'iAmEnabled');
51  }
52 
53  #[Test]
54  public function ‪getWithPathReturnsGivenPathSegment(): void
55  {
56  ‪$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['someExtension'] = [
57  'aFeature' => 'iAmEnabled',
58  'aFlagCategory' => [
59  'someFlag' => 'foo',
60  ],
61  ];
62  self::assertSame((new ‪ExtensionConfiguration())->get('someExtension', 'aFlagCategory'), ['someFlag' => 'foo']);
63  }
64 
65  #[Test]
67  {
68  $this->expectException(\RuntimeException::class);
69  $this->expectExceptionCode(1509715852);
70  (new ‪ExtensionConfiguration())->set('');
71  }
72 
73  #[Test]
75  {
76  $configurationManagerMock = $this->createMock(ConfigurationManager::class);
77  GeneralUtility::addInstance(ConfigurationManager::class, $configurationManagerMock);
78  $configurationManagerMock->expects(self::once())->method('removeLocalConfigurationKeysByPath')->with(['EXTENSIONS/foo']);
79  ‪$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['foo'] = [
80  'bar' => 'baz',
81  ];
82  (new ‪ExtensionConfiguration())->set('foo');
83  self::assertFalse(isset(‪$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['foo']));
84  }
85 
86  #[Test]
87  public function ‪setWritesFullExtensionConfig(): void
88  {
89  $value = ['bar' => 'baz'];
90  $configurationManagerMock = $this->createMock(ConfigurationManager::class);
91  GeneralUtility::addInstance(ConfigurationManager::class, $configurationManagerMock);
92  $configurationManagerMock->expects(self::once())->method('setLocalConfigurationValueByPath')->with('EXTENSIONS/foo', $value);
93  ‪$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['foo'] = [
94  'bar' => 'fizz',
95  'bee' => 'boo',
96  ];
97  (new ‪ExtensionConfiguration())->set('foo', $value);
98  self::assertSame($value, ‪$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['foo']);
99  }
100 }
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:47
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest
Definition: ExtensionConfigurationTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\getWithPathReturnsGivenValue
‪getWithPathReturnsGivenValue()
Definition: ExtensionConfigurationTest.php:42
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\setThrowsExceptionWithEmptyExtension
‪setThrowsExceptionWithEmptyExtension()
Definition: ExtensionConfigurationTest.php:66
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\getWithPathReturnsGivenPathSegment
‪getWithPathReturnsGivenPathSegment()
Definition: ExtensionConfigurationTest.php:54
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\setRemovesFullExtensionConfiguration
‪setRemovesFullExtensionConfiguration()
Definition: ExtensionConfigurationTest.php:74
‪TYPO3\CMS\Core\Tests\Unit\Configuration\ExtensionConfigurationTest\setWritesFullExtensionConfig
‪setWritesFullExtensionConfig()
Definition: ExtensionConfigurationTest.php:87
‪$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:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Tests\Unit\Configuration
Definition: CKEditor5MigratorTest.php:18