5582780fafda217c2b8348378e6d388d93672241
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / UnitDeprecated / Mvc / Configuration / ConfigurationManagerTest.php
1 <?php
2 namespace TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Prophecy\Argument;
18 use TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader;
19 use TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader\Configuration;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Extbase\Object\ObjectManager;
22 use TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager;
23 use TYPO3\CMS\Form\Mvc\Configuration\InheritancesResolverService;
24
25 /**
26 * Test case
27 */
28 class ConfigurationManagerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
29 {
30
31 /**
32 * @var array A backup of registered singleton instances
33 */
34 protected $singletonInstances = [];
35
36 /**
37 * Set up
38 */
39 public function setUp()
40 {
41 $this->singletonInstances = GeneralUtility::getSingletonInstances();
42 }
43
44 /**
45 * Tear down
46 */
47 public function tearDown()
48 {
49 GeneralUtility::resetSingletonInstances($this->singletonInstances);
50 parent::tearDown();
51 }
52
53 /**
54 * @test
55 */
56 public function getConfigurationFromYamlFile()
57 {
58 $mockConfigurationManager = $this->getAccessibleMock(ConfigurationManager::class, [
59 'getYamlSettingsFromCache',
60 'setYamlSettingsIntoCache',
61 'getTypoScriptSettings',
62 'overrideConfigurationByTypoScript',
63 ], [], '', false);
64
65 $objectManagerProphecy = $this->prophesize(ObjectManager::class);
66 GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal());
67
68 $configuration = new Configuration();
69 $objectManagerProphecy
70 ->get(Configuration::class)
71 ->willReturn($configuration);
72
73 $objectManagerProphecy
74 ->get(YamlFileLoader::class, Argument::type(Configuration::class))
75 ->willReturn(new YamlFileLoader($configuration));
76
77 $objectManagerProphecy
78 ->get(InheritancesResolverService::class)
79 ->willReturn(new InheritancesResolverService);
80
81 $mockConfigurationManager->_set('objectManager', $objectManagerProphecy->reveal());
82
83 $mockConfigurationManager
84 ->expects($this->any())
85 ->method('getYamlSettingsFromCache')
86 ->willReturn([]);
87
88 $mockConfigurationManager
89 ->expects($this->any())
90 ->method('getTypoScriptSettings')
91 ->willReturn([
92 'yamlConfigurations' => [
93 10 => 'EXT:form/Tests/Unit/Mvc/Configuration/Fixtures/File1.yaml'
94 ]
95 ]);
96
97 $mockConfigurationManager
98 ->expects($this->any())
99 ->method('setYamlSettingsIntoCache')
100 ->willReturn(null);
101
102 $mockConfigurationManager
103 ->expects($this->any())
104 ->method('overrideConfigurationByTypoScript')
105 ->willReturnArgument(0);
106
107 $input = 'form';
108 $expected = [
109 'config' => [
110 'value9' => 'File 3',
111 'value10' => 'File 4',
112 'value8' => 'File 3',
113 'value1' => 'File 1',
114 'value4' => 'File 1',
115 'value5' => 'File 1',
116 'value7' => 'File 2',
117 'value11' => [
118 'key1' => 'File 1',
119 'key2' => 'File 1',
120 ],
121 'value12' => [
122 'key1' => 'File 2',
123 ],
124 'value3' => 'File 1',
125 ],
126 'mixins' => [
127 'value11Mixin' => [
128 'key1' => 'File 1',
129 'key2' => 'File 1',
130 ],
131 'value12Mixin1' => [
132 'key1' => 'File 2',
133 ],
134 'value12Mixin2' => [
135 'key2' => 'File 2',
136 ],
137 ],
138 ];
139
140 $this->assertSame($expected, $mockConfigurationManager->_call('getConfigurationFromYamlFile', 'form'));
141 }
142 }