‪TYPO3CMS  ‪main
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 
20 use PHPUnit\Framework\Attributes\Test;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
27 final class ‪FlexFormServiceTest extends UnitTestCase
28 {
29  protected bool ‪$resetSingletonInstances = true;
30 
31  #[Test]
33  {
34  $input = '<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
35 <T3FlexForms>
36  <data>
37  <sheet index="sDEF">
38  <language index="lDEF">
39  <field index="settings.foo">
40  <value index="vDEF">Foo-Value</value>
41  </field>
42  <field index="settings.bar">
43  <el index="el">
44  <section index="1">
45  <itemType index="_arrayContainer">
46  <el>
47  <field index="baz">
48  <value index="vDEF">Baz1-Value</value>
49  </field>
50  <field index="bum">
51  <value index="vDEF">Bum1-Value</value>
52  </field>
53  <field index="dot.one">
54  <value index="vDEF">dot.one-Value</value>
55  </field>
56  <field index="dot.two">
57  <value index="vDEF">dot.two-Value</value>
58  </field>
59  </el>
60  </itemType>
61  </section>
62  <section index="2">
63  <itemType index="_arrayContainer">
64  <el>
65  <field index="baz">
66  <value index="vDEF">Baz2-Value</value>
67  </field>
68  <field index="bum">
69  <value index="vDEF">Bum2-Value</value>
70  </field>
71  </el>
72  </itemType>
73  </section>
74  </el>
75  </field>
76  </language>
77  </sheet>
78  </data>
79 </T3FlexForms>';
80 
81  $expected = [
82  'settings' => [
83  'foo' => 'Foo-Value',
84  'bar' => [
85  1 => [
86  'baz' => 'Baz1-Value',
87  'bum' => 'Bum1-Value',
88  'dot' => [
89  'one' => 'dot.one-Value',
90  'two' => 'dot.two-Value',
91  ],
92  ],
93  2 => [
94  'baz' => 'Baz2-Value',
95  'bum' => 'Bum2-Value',
96  ],
97  ],
98  ],
99  ];
100 
101  // The subject calls xml2array statically, which calls a runtime cache, this need to be mocked.
102  $cacheManagerMock = $this->createMock(CacheManager::class);
103  $cacheMock = $this->createMock(FrontendInterface::class);
104  $cacheManagerMock->method('getCache')->willReturn($cacheMock);
105  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerMock);
106 
107  $flexFormService = new ‪FlexFormService();
108  $convertedFlexFormArray = $flexFormService->convertFlexFormContentToArray($input);
109  self::assertSame($expected, $convertedFlexFormArray);
110  }
111 }
‪TYPO3\CMS\Core\Tests\Unit\Service\FlexFormServiceTest\convertFlexFormContentToArrayResolvesComplexArrayStructure
‪convertFlexFormContentToArrayResolvesComplexArrayStructure()
Definition: FlexFormServiceTest.php:32
‪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:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Tests\Unit\Service
Definition: DependencyOrderingServiceTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Service\FlexFormServiceTest
Definition: FlexFormServiceTest.php:28