TYPO3 CMS  TYPO3_8-7
FlexFormServiceTest.php
Go to the documentation of this file.
1 <?php
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 
18 
22 class FlexFormServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
23 {
27  protected $backupSingletons = [];
28 
32  protected function setUp()
33  {
34  $this->backupSingletons = GeneralUtility::getSingletonInstances();
35  }
36 
40  protected function tearDown()
41  {
42  GeneralUtility::resetSingletonInstances($this->backupSingletons);
43  parent::tearDown();
44  }
45 
50  {
51  $input = '<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
52 <T3FlexForms>
53  <data>
54  <sheet index="sDEF">
55  <language index="lDEF">
56  <field index="settings.foo">
57  <value index="vDEF">Foo-Value</value>
58  </field>
59  <field index="settings.bar">
60  <el index="el">
61  <section index="1">
62  <itemType index="_arrayContainer">
63  <el>
64  <field index="baz">
65  <value index="vDEF">Baz1-Value</value>
66  </field>
67  <field index="bum">
68  <value index="vDEF">Bum1-Value</value>
69  </field>
70  <field index="dot.one">
71  <value index="vDEF">dot.one-Value</value>
72  </field>
73  <field index="dot.two">
74  <value index="vDEF">dot.two-Value</value>
75  </field>
76  </el>
77  </itemType>
78  <itemType index="_TOGGLE">0</itemType>
79  </section>
80  <section index="2">
81  <itemType index="_arrayContainer">
82  <el>
83  <field index="baz">
84  <value index="vDEF">Baz2-Value</value>
85  </field>
86  <field index="bum">
87  <value index="vDEF">Bum2-Value</value>
88  </field>
89  </el>
90  </itemType>
91  <itemType index="_TOGGLE">0</itemType>
92  </section>
93  </el>
94  </field>
95  </language>
96  </sheet>
97  </data>
98 </T3FlexForms>';
99 
100  $expected = [
101  'settings' => [
102  'foo' => 'Foo-Value',
103  'bar' => [
104  1 => [
105  'baz' => 'Baz1-Value',
106  'bum' => 'Bum1-Value',
107  'dot' => [
108  'one' => 'dot.one-Value',
109  'two' => 'dot.two-Value',
110  ],
111  ],
112  2 => [
113  'baz' => 'Baz2-Value',
114  'bum' => 'Bum2-Value'
115  ]
116  ]
117  ]
118  ];
119 
120  // The subject calls xml2array statically, which calls getHash and setHash statically, which uses
121  // caches, those need to be mocked.
122  $cacheManagerMock = $this->createMock(\TYPO3\CMS\Core\Cache\CacheManager::class);
123  $cacheMock = $this->createMock(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class);
124  $cacheManagerMock->expects($this->any())->method('getCache')->will($this->returnValue($cacheMock));
125  GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManagerMock);
126 
127  $flexFormService = $this->getMockBuilder(\TYPO3\CMS\Extbase\Service\FlexFormService::class)
128  ->setMethods(['dummy'])
129  ->disableOriginalConstructor()
130  ->getMock();
131  $convertedFlexFormArray = $flexFormService->convertFlexFormContentToArray($input);
132  $this->assertSame($expected, $convertedFlexFormArray);
133  }
134 }
static setSingletonInstance($className, SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)