[TASK] Re-work/simplify copyright header in PHP files - Part 8
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Service / FlexFormServiceTest.php
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
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18
19 /**
20 * Test case
21 */
22 class FlexFormServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
23
24 /**
25 * @var array Backup of singletons
26 */
27 protected $backupSingletons = array();
28
29 /**
30 * Set up
31 */
32 public function setUp() {
33 $this->backupSingletons = GeneralUtility::getSingletonInstances();
34 }
35
36 /**
37 * Tear down
38 */
39 public function tearDown() {
40 GeneralUtility::resetSingletonInstances($this->backupSingletons);
41 parent::tearDown();
42 }
43
44 /**
45 * @test
46 */
47 public function convertFlexFormContentToArrayResolvesComplexArrayStructure() {
48 $input = '<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
49 <T3FlexForms>
50 <data>
51 <sheet index="sDEF">
52 <language index="lDEF">
53 <field index="settings.foo">
54 <value index="vDEF">Foo-Value</value>
55 </field>
56 <field index="settings.bar">
57 <el index="el">
58 <section index="1">
59 <itemType index="_arrayContainer">
60 <el>
61 <field index="baz">
62 <value index="vDEF">Baz1-Value</value>
63 </field>
64 <field index="bum">
65 <value index="vDEF">Bum1-Value</value>
66 </field>
67 </el>
68 </itemType>
69 <itemType index="_TOGGLE">0</itemType>
70 </section>
71 <section index="2">
72 <itemType index="_arrayContainer">
73 <el>
74 <field index="baz">
75 <value index="vDEF">Baz2-Value</value>
76 </field>
77 <field index="bum">
78 <value index="vDEF">Bum2-Value</value>
79 </field>
80 </el>
81 </itemType>
82 <itemType index="_TOGGLE">0</itemType>
83 </section>
84 </el>
85 </field>
86 </language>
87 </sheet>
88 </data>
89 </T3FlexForms>';
90
91 $expected = array(
92 'settings' => array(
93 'foo' => 'Foo-Value',
94 'bar' => array(
95 1 => array(
96 'baz' => 'Baz1-Value',
97 'bum' => 'Bum1-Value'
98 ),
99 2 => array(
100 'baz' => 'Baz2-Value',
101 'bum' => 'Bum2-Value'
102 )
103 )
104 )
105 );
106
107 // The subject calls xml2array statically, which calls getHash and setHash statically, which uses
108 // caches, those need to be mocked.
109 $cacheManagerMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array(), array(), '', FALSE);
110 $cacheMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(), '', FALSE);
111 $cacheManagerMock->expects($this->any())->method('getCache')->will($this->returnValue($cacheMock));
112 GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', $cacheManagerMock);
113
114 $flexFormService = $this->getMock('TYPO3\\CMS\\Extbase\\Service\\FlexFormService', array('dummy'), array(), '', FALSE);
115 $convertedFlexFormArray = $flexFormService->convertFlexFormContentToArray($input);
116 $this->assertSame($expected, $convertedFlexFormArray);
117 }
118 }