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