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