[TASK] Correctly initialize environment for DataHandler in tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Service / FlexFormServiceTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Service;
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 TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
19
20 /**
21 * Test case
22 */
23 class FlexFormServiceTest extends UnitTestCase
24 {
25 /**
26 * @var bool Reset singletons created by subject
27 */
28 protected $resetSingletonInstances = true;
29
30 /**
31 * @test
32 */
33 public function convertFlexFormContentToArrayResolvesComplexArrayStructure()
34 {
35 $input = '<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
36 <T3FlexForms>
37 <data>
38 <sheet index="sDEF">
39 <language index="lDEF">
40 <field index="settings.foo">
41 <value index="vDEF">Foo-Value</value>
42 </field>
43 <field index="settings.bar">
44 <el index="el">
45 <section index="1">
46 <itemType index="_arrayContainer">
47 <el>
48 <field index="baz">
49 <value index="vDEF">Baz1-Value</value>
50 </field>
51 <field index="bum">
52 <value index="vDEF">Bum1-Value</value>
53 </field>
54 <field index="dot.one">
55 <value index="vDEF">dot.one-Value</value>
56 </field>
57 <field index="dot.two">
58 <value index="vDEF">dot.two-Value</value>
59 </field>
60 </el>
61 </itemType>
62 <itemType index="_TOGGLE">0</itemType>
63 </section>
64 <section index="2">
65 <itemType index="_arrayContainer">
66 <el>
67 <field index="baz">
68 <value index="vDEF">Baz2-Value</value>
69 </field>
70 <field index="bum">
71 <value index="vDEF">Bum2-Value</value>
72 </field>
73 </el>
74 </itemType>
75 <itemType index="_TOGGLE">0</itemType>
76 </section>
77 </el>
78 </field>
79 </language>
80 </sheet>
81 </data>
82 </T3FlexForms>';
83
84 $expected = [
85 'settings' => [
86 'foo' => 'Foo-Value',
87 'bar' => [
88 1 => [
89 'baz' => 'Baz1-Value',
90 'bum' => 'Bum1-Value',
91 'dot' => [
92 'one' => 'dot.one-Value',
93 'two' => 'dot.two-Value',
94 ],
95 ],
96 2 => [
97 'baz' => 'Baz2-Value',
98 'bum' => 'Bum2-Value'
99 ]
100 ]
101 ]
102 ];
103
104 // The subject calls xml2array statically, which calls getHash and setHash statically, which uses
105 // caches, those need to be mocked.
106 $cacheManagerMock = $this->createMock(\TYPO3\CMS\Core\Cache\CacheManager::class);
107 $cacheMock = $this->createMock(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class);
108 $cacheManagerMock->expects($this->any())->method('getCache')->will($this->returnValue($cacheMock));
109 GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManagerMock);
110
111 $flexFormService = $this->getMockBuilder(\TYPO3\CMS\Extbase\Service\FlexFormService::class)
112 ->setMethods(['dummy'])
113 ->disableOriginalConstructor()
114 ->getMock();
115 $convertedFlexFormArray = $flexFormService->convertFlexFormContentToArray($input);
116 $this->assertSame($expected, $convertedFlexFormArray);
117 }
118 }