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