TYPO3 CMS  TYPO3_6-2
FlexFormServiceTest.php
Go to the documentation of this file.
1 <?php
3 
18 
23 
27  protected $backupSingletons = array();
28 
32  public function setUp() {
33  $this->backupSingletons = GeneralUtility::getSingletonInstances();
34  }
35 
39  public function tearDown() {
40  GeneralUtility::resetSingletonInstances($this->backupSingletons);
41  parent::tearDown();
42  }
43 
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 }
static setSingletonInstance($className, \TYPO3\CMS\Core\SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)