‪TYPO3CMS  11.5
ConfigurationManagerTest.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\PhpUnit\ProphecyTrait;
21 use Psr\Http\Message\ServerRequestInterface;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
30 class ‪ConfigurationManagerTest extends UnitTestCase
31 {
32  use ProphecyTrait;
33 
37  protected ‪$resetSingletonInstances = true;
38 
39  public function ‪tearDown(): void
40  {
41  unset(‪$GLOBALS['TYPO3_REQUEST']);
42  parent::tearDown();
43  }
44 
49  {
50  $yamlSettings = [
51  'prototypes' => [
52  'standard' => [
53  'formElementsDefinition' => [
54  'Form' => [
55  'renderingOptions' => [
56  'submitButtonLabel' => 'Foo',
57  'templateVariant' => 'version1',
58  'addQueryString' => [
59  'value' => 'Baz',
60  '_typoScriptNodeValue' => 'TEXT',
61  ],
62  ],
63  ],
64  ],
65  ],
66  ],
67  ];
68 
69  $formTypoScript = [
70  'settings' => [
71  'yamlSettingsOverrides' => [
72  'prototypes' => [
73  'standard' => [
74  'formElementsDefinition' => [
75  'Form' => [
76  'renderingOptions' => [
77  'submitButtonLabel' => [
78  'value' => 'Bar',
79  '_typoScriptNodeValue' => 'TEXT',
80  ],
81  ],
82  ],
83  ],
84  ],
85  ],
86  ],
87  ],
88  ];
89 
90  $evaluatedFormTypoScript = [
91  'prototypes' => [
92  'standard' => [
93  'formElementsDefinition' => [
94  'Form' => [
95  'renderingOptions' => [
96  'submitButtonLabel' => 'Bar',
97  ],
98  ],
99  ],
100  ],
101  ],
102  ];
103 
104  $expected = [
105  'prototypes' => [
106  'standard' => [
107  'formElementsDefinition' => [
108  'Form' => [
109  'renderingOptions' => [
110  'submitButtonLabel' => 'Bar',
111  'templateVariant' => 'version1',
112  'addQueryString' => [
113  'value' => 'Baz',
114  '_typoScriptNodeValue' => 'TEXT',
115  ],
116  ],
117  ],
118  ],
119  ],
120  ],
121  ];
122 
123  $configurationManagerMock = $this->getAccessibleMock(ConfigurationManager::class, [
124  'getTypoScriptSettings',
125  'getYamlSettingsFromCache',
126  ], [], '', false);
127  $configurationManagerMock->method('getYamlSettingsFromCache')->with(self::anything())->willReturn($yamlSettings);
128 
129  $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
130  $serverRequestProphecy->getAttribute('applicationType')->willReturn(‪SystemEnvironmentBuilder::REQUESTTYPE_FE);
131  ‪$GLOBALS['TYPO3_REQUEST'] = $serverRequestProphecy->reveal();
132 
133  $typoScriptServiceProphecy = $this->prophesize(TypoScriptService::class);
134  $typoScriptServiceProphecy->resolvePossibleTypoScriptConfiguration($formTypoScript['settings']['yamlSettingsOverrides'])->willReturn($evaluatedFormTypoScript);
135  GeneralUtility::addInstance(TypoScriptService::class, $typoScriptServiceProphecy->reveal());
136 
137  $concreteConfigurationManagerProphecy = $this->prophesize(FrontendConfigurationManager::class);
138  $concreteConfigurationManagerProphecy->getConfiguration('form', null)->willReturn($formTypoScript);
139 
140  $configurationManagerMock->_set('concreteConfigurationManager', $concreteConfigurationManagerProphecy->reveal());
141  $configurationManagerMock->method('getTypoScriptSettings')->with(self::anything())->willReturn([]);
142 
143  self::assertSame($expected, $configurationManagerMock->getConfiguration(‪ConfigurationManagerInterface::CONFIGURATION_TYPE_YAML_SETTINGS, 'form'));
144  }
145 }
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration
Definition: ConfigurationManagerTest.php:18
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\ConfigurationManagerTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: ConfigurationManagerTest.php:35
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\ConfigurationManagerTest\getConfigurationDoesNotEvaluateTypoScriptLookalikeInstructionsFromYamlSettingsInFrontendContext
‪getConfigurationDoesNotEvaluateTypoScriptLookalikeInstructionsFromYamlSettingsInFrontendContext()
Definition: ConfigurationManagerTest.php:46
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\ConfigurationManagerTest\tearDown
‪tearDown()
Definition: ConfigurationManagerTest.php:37
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager
Definition: FrontendConfigurationManager.php:33
‪TYPO3\CMS\Form\Mvc\Configuration\TypoScriptService
Definition: TypoScriptService.php:29
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\ConfigurationManagerTest
Definition: ConfigurationManagerTest.php:31
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_YAML_SETTINGS
‪const CONFIGURATION_TYPE_YAML_SETTINGS
Definition: ConfigurationManagerInterface.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_FE
‪const REQUESTTYPE_FE
Definition: SystemEnvironmentBuilder.php:43
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager
Definition: ConfigurationManager.php:36
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:29