‪TYPO3CMS  10.4
FlexFormServiceTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪FlexFormServiceTest extends UnitTestCase
28 {
32  protected ‪$resetSingletonInstances = true;
33 
38  {
39  $input = '<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
40 <T3FlexForms>
41  <data>
42  <sheet index="sDEF">
43  <language index="lDEF">
44  <field index="settings.foo">
45  <value index="vDEF">Foo-Value</value>
46  </field>
47  <field index="settings.bar">
48  <el index="el">
49  <section index="1">
50  <itemType index="_arrayContainer">
51  <el>
52  <field index="baz">
53  <value index="vDEF">Baz1-Value</value>
54  </field>
55  <field index="bum">
56  <value index="vDEF">Bum1-Value</value>
57  </field>
58  <field index="dot.one">
59  <value index="vDEF">dot.one-Value</value>
60  </field>
61  <field index="dot.two">
62  <value index="vDEF">dot.two-Value</value>
63  </field>
64  </el>
65  </itemType>
66  <itemType index="_TOGGLE">0</itemType>
67  </section>
68  <section index="2">
69  <itemType index="_arrayContainer">
70  <el>
71  <field index="baz">
72  <value index="vDEF">Baz2-Value</value>
73  </field>
74  <field index="bum">
75  <value index="vDEF">Bum2-Value</value>
76  </field>
77  </el>
78  </itemType>
79  <itemType index="_TOGGLE">0</itemType>
80  </section>
81  </el>
82  </field>
83  </language>
84  </sheet>
85  </data>
86 </T3FlexForms>';
87 
88  $expected = [
89  'settings' => [
90  'foo' => 'Foo-Value',
91  'bar' => [
92  1 => [
93  'baz' => 'Baz1-Value',
94  'bum' => 'Bum1-Value',
95  'dot' => [
96  'one' => 'dot.one-Value',
97  'two' => 'dot.two-Value',
98  ],
99  ],
100  2 => [
101  'baz' => 'Baz2-Value',
102  'bum' => 'Bum2-Value'
103  ]
104  ]
105  ]
106  ];
107 
108  // The subject calls xml2array statically, which calls a runtime cache, this need to be mocked.
109  $cacheManagerMock = $this->createMock(CacheManager::class);
110  $cacheMock = $this->createMock(FrontendInterface::class);
111  $cacheManagerMock->expects(self::any())->method('getCache')->willReturn($cacheMock);
112  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerMock);
113 
114  $flexFormService = $this->getMockBuilder(FlexFormService::class)
115  ->setMethods(['dummy'])
116  ->disableOriginalConstructor()
117  ->getMock();
118  $convertedFlexFormArray = $flexFormService->convertFlexFormContentToArray($input);
119  self::assertSame($expected, $convertedFlexFormArray);
120  }
121 }
‪TYPO3\CMS\Core\Tests\Unit\Service\FlexFormServiceTest\convertFlexFormContentToArrayResolvesComplexArrayStructure
‪convertFlexFormContentToArrayResolvesComplexArrayStructure()
Definition: FlexFormServiceTest.php:36
‪TYPO3\CMS\Core\Service\FlexFormService
Definition: FlexFormService.php:25
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\Tests\Unit\Service\FlexFormServiceTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: FlexFormServiceTest.php:31
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Tests\Unit\Service
Definition: DependencyOrderingServiceTest.php:16
‪TYPO3\CMS\Core\Tests\Unit\Service\FlexFormServiceTest
Definition: FlexFormServiceTest.php:28