TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
FlexFormServiceTest.php
Go to the documentation of this file.
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 
18 
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  </el>
71  </itemType>
72  <itemType index="_TOGGLE">0</itemType>
73  </section>
74  <section index="2">
75  <itemType index="_arrayContainer">
76  <el>
77  <field index="baz">
78  <value index="vDEF">Baz2-Value</value>
79  </field>
80  <field index="bum">
81  <value index="vDEF">Bum2-Value</value>
82  </field>
83  </el>
84  </itemType>
85  <itemType index="_TOGGLE">0</itemType>
86  </section>
87  </el>
88  </field>
89  </language>
90  </sheet>
91  </data>
92 </T3FlexForms>';
93 
94  $expected = [
95  'settings' => [
96  'foo' => 'Foo-Value',
97  'bar' => [
98  1 => [
99  'baz' => 'Baz1-Value',
100  'bum' => 'Bum1-Value'
101  ],
102  2 => [
103  'baz' => 'Baz2-Value',
104  'bum' => 'Bum2-Value'
105  ]
106  ]
107  ]
108  ];
109 
110  // The subject calls xml2array statically, which calls getHash and setHash statically, which uses
111  // caches, those need to be mocked.
112  $cacheManagerMock = $this->createMock(\TYPO3\CMS\Core\Cache\CacheManager::class);
113  $cacheMock = $this->createMock(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class);
114  $cacheManagerMock->expects($this->any())->method('getCache')->will($this->returnValue($cacheMock));
115  GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManagerMock);
116 
117  $flexFormService = $this->getMockBuilder(\TYPO3\CMS\Extbase\Service\FlexFormService::class)
118  ->setMethods(['dummy'])
119  ->disableOriginalConstructor()
120  ->getMock();
121  $convertedFlexFormArray = $flexFormService->convertFlexFormContentToArray($input);
122  $this->assertSame($expected, $convertedFlexFormArray);
123  }
124 }
static setSingletonInstance($className, SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)