‪TYPO3CMS  ‪main
BackendConfigurationManagerTest.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;
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
27 final class ‪BackendConfigurationManagerTest extends FunctionalTestCase
28 {
29  #[Test]
31  {
32  $subject = $this->get(BackendConfigurationManager::class);
33  $subject->setConfiguration([
34  'extensionName' => 'SomeExtensionName',
35  'pluginName' => 'SomePluginName',
36  ]);
37  self::assertEquals('SomeExtensionName', (new \ReflectionProperty($subject, 'extensionName'))->getValue($subject));
38  self::assertEquals('SomePluginName', (new \ReflectionProperty($subject, 'pluginName'))->getValue($subject));
39  }
40 
41  #[Test]
43  {
44  $configuration = [
45  'foo' => 'bar',
46  'settings.' => ['foo' => 'bar'],
47  'view.' => ['subkey.' => ['subsubkey' => 'subsubvalue']],
48  ];
49  $expectedResult = [
50  'foo' => 'bar',
51  'settings' => ['foo' => 'bar'],
52  'view' => ['subkey' => ['subsubkey' => 'subsubvalue']],
53  ];
54  $subject = $this->get(BackendConfigurationManager::class);
55  $subject->setConfiguration($configuration);
56  self::assertEquals($expectedResult, (new \ReflectionProperty($subject, 'configuration'))->getValue($subject));
57  }
58 
59  #[Test]
61  {
62  $this->importCSVDataSet(__DIR__ . '/Fixtures/BackendConfigurationManagerTestTypoScript.csv');
63  ‪$GLOBALS['TYPO3_REQUEST'] = new ‪ServerRequest();
64  $subject = $this->get(BackendConfigurationManager::class);
65  $expectedResult = [
66  'settings' => [
67  'setting1' => 'overriddenValue1',
68  'setting2' => 'value2',
69  'setting3' => 'additionalValue1',
70  ],
71  'view' => [
72  'viewSub' => [
73  'key1' => 'overridden1',
74  'key2' => 'value2',
75  'key3' => 'new key1',
76  ],
77  ],
78  'persistence' => [
79  'storagePid' => '123',
80  'enableAutomaticCacheClearing' => '1',
81  'updateReferenceIndex' => '0',
82  ],
83  'controllerConfiguration' => [],
84  'mvc' => [
85  'throwPageNotFoundExceptionIfActionCantBeResolved' => '0',
86  ],
87  ];
88  self::assertEquals($expectedResult, $subject->getConfiguration('CurrentExtensionName'));
89  }
90 
91  #[Test]
93  {
94  $this->importCSVDataSet(__DIR__ . '/Fixtures/BackendConfigurationManagerTestTypoScript.csv');
95  ‪$GLOBALS['TYPO3_REQUEST'] = new ‪ServerRequest();
96  $subject = $this->get(BackendConfigurationManager::class);
97  $expectedResult = [
98  'settings' => [
99  'setting1' => 'overriddenValue2',
100  'setting2' => 'value2',
101  'setting3' => 'additionalValue2',
102  ],
103  'view' => [
104  'viewSub' => [
105  'key1' => 'overridden2',
106  'key2' => 'value2',
107  'key3' => 'new key2',
108  ],
109  ],
110  'persistence' => [
111  'storagePid' => '456',
112  'enableAutomaticCacheClearing' => '1',
113  'updateReferenceIndex' => '0',
114  ],
115  'controllerConfiguration' => [],
116  'mvc' => [
117  'throwPageNotFoundExceptionIfActionCantBeResolved' => '0',
118  ],
119  ];
120  self::assertEquals($expectedResult, $subject->getConfiguration('CurrentExtensionName', 'CurrentPluginName'));
121  }
122 
123  #[Test]
125  {
126  $request = (new ‪ServerRequest())->withQueryParams(['id' => 123]);
127  $subject = $this->get(BackendConfigurationManager::class);
128  $subject->setRequest($request);
129  $getCurrentPageIdReflectionMethod = (new \ReflectionMethod($subject, 'getCurrentPageId'));
130  $actualResult = $getCurrentPageIdReflectionMethod->invoke($subject);
131  self::assertEquals(123, $actualResult);
132  }
133 
134  #[Test]
136  {
137  $request = (new ‪ServerRequest())->withQueryParams(['id' => 123])->withParsedBody(['id' => 321]);
138  $subject = $this->get(BackendConfigurationManager::class);
139  $subject->setRequest($request);
140  $getCurrentPageIdReflectionMethod = (new \ReflectionMethod($subject, 'getCurrentPageId'));
141  $actualResult = $getCurrentPageIdReflectionMethod->invoke($subject);
142  self::assertEquals(321, $actualResult);
143  }
144 
145  #[Test]
147  {
148  (new ‪ConnectionPool())->getConnectionForTable('sys_template')->insert(
149  'sys_template',
150  [
151  'pid' => 123,
152  'deleted' => 0,
153  'hidden' => 0,
154  'root' => 1,
155  ]
156  );
157  $subject = $this->get(BackendConfigurationManager::class);
158  $subject->setRequest(new ‪ServerRequest());
159  $getCurrentPageIdReflectionMethod = (new \ReflectionMethod($subject, 'getCurrentPageId'));
160  $actualResult = $getCurrentPageIdReflectionMethod->invoke($subject);
161  self::assertEquals(123, $actualResult);
162  }
163 
164  #[Test]
166  {
167  (new ‪ConnectionPool())->getConnectionForTable('pages')->insert(
168  'pages',
169  [
170  'deleted' => 0,
171  'hidden' => 0,
172  'is_siteroot' => 1,
173  ]
174  );
175  $subject = $this->get(BackendConfigurationManager::class);
176  $subject->setRequest(new ‪ServerRequest());
177  $getCurrentPageIdReflectionMethod = (new \ReflectionMethod($subject, 'getCurrentPageId'));
178  $actualResult = $getCurrentPageIdReflectionMethod->invoke($subject);
179  self::assertEquals(1, $actualResult);
180  }
181 
182  #[Test]
184  {
185  $subject = $this->get(BackendConfigurationManager::class);
186  $subject->setRequest(new ‪ServerRequest());
187  $getCurrentPageIdReflectionMethod = (new \ReflectionMethod($subject, 'getCurrentPageId'));
188  $actualResult = $getCurrentPageIdReflectionMethod->invoke($subject);
189  self::assertEquals(0, $actualResult);
190  }
191 
192  #[Test]
194  {
195  $this->importCSVDataSet(__DIR__ . '/Fixtures/BackendConfigurationManagerRecursivePids.csv');
196  ‪$GLOBALS['BE_USER'] = new ‪BackendUserAuthentication();
197  ‪$GLOBALS['BE_USER']->user = ['admin' => true];
198  $subject = $this->get(BackendConfigurationManager::class);
199  $getCurrentPageIdReflectionMethod = (new \ReflectionMethod($subject, 'getRecursiveStoragePids'));
200  $actualResult = $getCurrentPageIdReflectionMethod->invoke($subject, [1, -6], 4);
201  self::assertEquals([1, 2, 4, 5, 3, 6, 7], $actualResult);
202  }
203 }
‪TYPO3\CMS\Extbase\Tests\Functional\Configuration\BackendConfigurationManagerTest
Definition: BackendConfigurationManagerTest.php:28
‪TYPO3\CMS\Extbase\Tests\Functional\Configuration\BackendConfigurationManagerTest\getConfigurationRecursivelyMergesCurrentPluginConfigurationWithFrameworkConfiguration
‪getConfigurationRecursivelyMergesCurrentPluginConfigurationWithFrameworkConfiguration()
Definition: BackendConfigurationManagerTest.php:92
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager
Definition: BackendConfigurationManager.php:69
‪TYPO3\CMS\Extbase\Tests\Functional\Configuration\BackendConfigurationManagerTest\getCurrentPageIdReturnsPidFromFirstRootTemplateIfIdIsNotSetAndNoRootPageWasFound
‪getCurrentPageIdReturnsPidFromFirstRootTemplateIfIdIsNotSetAndNoRootPageWasFound()
Definition: BackendConfigurationManagerTest.php:146
‪TYPO3\CMS\Extbase\Tests\Functional\Configuration\BackendConfigurationManagerTest\getRecursiveStoragePidsReturnsListOfPages
‪getRecursiveStoragePidsReturnsListOfPages()
Definition: BackendConfigurationManagerTest.php:193
‪TYPO3\CMS\Extbase\Tests\Functional\Configuration\BackendConfigurationManagerTest\getCurrentPageIdReturnsUidFromFirstRootPageIfIdIsNotSet
‪getCurrentPageIdReturnsUidFromFirstRootPageIfIdIsNotSet()
Definition: BackendConfigurationManagerTest.php:165
‪TYPO3\CMS\Extbase\Tests\Functional\Configuration\BackendConfigurationManagerTest\getCurrentPageIdReturnsPageIdFromGet
‪getCurrentPageIdReturnsPageIdFromGet()
Definition: BackendConfigurationManagerTest.php:124
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Extbase\Tests\Functional\Configuration\BackendConfigurationManagerTest\getCurrentPageIdReturnsPageIdFromPost
‪getCurrentPageIdReturnsPageIdFromPost()
Definition: BackendConfigurationManagerTest.php:135
‪TYPO3\CMS\Extbase\Tests\Functional\Configuration\BackendConfigurationManagerTest\getCurrentPageIdReturnsDefaultStoragePidIfIdIsNotSetNoRootTemplateAndRootPageWasFound
‪getCurrentPageIdReturnsDefaultStoragePidIfIdIsNotSetNoRootTemplateAndRootPageWasFound()
Definition: BackendConfigurationManagerTest.php:183
‪TYPO3\CMS\Extbase\Tests\Functional\Configuration\BackendConfigurationManagerTest\getConfigurationRecursivelyMergesCurrentExtensionConfigurationWithFrameworkConfiguration
‪getConfigurationRecursivelyMergesCurrentExtensionConfigurationWithFrameworkConfiguration()
Definition: BackendConfigurationManagerTest.php:60
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Extbase\Tests\Functional\Configuration\BackendConfigurationManagerTest\setConfigurationConvertsTypoScriptArrayToPlainArray
‪setConfigurationConvertsTypoScriptArrayToPlainArray()
Definition: BackendConfigurationManagerTest.php:42
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Extbase\Tests\Functional\Configuration
Definition: BackendConfigurationManagerTest.php:18
‪TYPO3\CMS\Extbase\Tests\Functional\Configuration\BackendConfigurationManagerTest\setConfigurationSetsExtensionAndPluginName
‪setConfigurationSetsExtensionAndPluginName()
Definition: BackendConfigurationManagerTest.php:30