PageRenderTime 100ms CodeModel.GetById 22ms RepoModel.GetById 2ms app.codeStats 0ms

/tests/t3lib/tca/datastructure/t3lib_tca_datastructure_flexformsresolverTest.php

https://github.com/andreaswolf/typo3-tceforms
PHP | 223 lines | 136 code | 29 blank | 58 comment | 0 complexity | 08f968a77010d13378a38632383a0561 MD5 | raw file
Possible License(s): Apache-2.0, BSD-2-Clause, LGPL-3.0
  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 2011 Andreas Wolf <andreas.wolf@ikt-werk.de>
  6. * All rights reserved
  7. *
  8. * This script is part of the TYPO3 project. The TYPO3 project is
  9. * free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * The GNU General Public License can be found at
  15. * http://www.gnu.org/copyleft/gpl.html.
  16. * A copy is found in the textfile GPL.txt and important notices to the license
  17. * from the author is found in LICENSE.txt distributed with these scripts.
  18. *
  19. *
  20. * This script is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * This copyright notice MUST APPEAR in all copies of the script!
  26. ***************************************************************/
  27. /**
  28. * Testcase for the FlexForm resolver class in TCA.
  29. *
  30. * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
  31. * @package TYPO3
  32. * @subpackage t3lib
  33. */
  34. class t3lib_TCA_DataStructure_FlexFormsResolverTest extends Tx_Phpunit_TestCase {
  35. protected $dataStructureMock;
  36. /**
  37. * @test
  38. * @covers t3lib_TCA_DataStructure_FlexFormsResolver::extractColumnsFromDataStructureArray
  39. */
  40. public function fieldTypeIsCorrectlyRecognized() {
  41. $dataStructureMock = array('sheets' => array(
  42. 'defaultSheet' => array('ROOT' => array('el' => array(
  43. 'sectionField' => array(
  44. 'section' => 1
  45. ),
  46. 'nonSectionField' => array(
  47. 'TCEforms' => array()
  48. )
  49. )))
  50. ));
  51. $fixture = new t3lib_TCA_DataStructure_FlexFormsResolver();
  52. $TcaEntry = $fixture->extractInformationFromDataStructureArray($dataStructureMock);
  53. $fields = $TcaEntry['columns'];
  54. $this->assertEquals('section', $fields['sectionField']['_type']);
  55. $this->assertEquals('field', $fields['nonSectionField']['_type']);
  56. }
  57. public function sectionFieldsAreRecognized_createDataStructureObject_callback($TCAentry) {
  58. }
  59. /**
  60. * @test
  61. * @covers t3lib_TCA_DataStructure_FlexFormsResolver::extractSheetInformation
  62. */
  63. public function fieldNamesAreExtractedForSheets() {
  64. $dataStructureMock = array('sheets' => array(
  65. 'defaultSheet' => array('ROOT' => array('el' => array(
  66. uniqid('el-') => array(),
  67. uniqid('el-') => array()
  68. ))),
  69. 'sheet_' . uniqid() => array('ROOT' => array('el' => array(
  70. uniqid('el-') => array(),
  71. uniqid('el-') => array()
  72. ))),
  73. ));
  74. $fixture = new t3lib_TCA_DataStructure_FlexFormsResolver();
  75. $TcaEntry = $fixture->extractInformationFromDataStructureArray($dataStructureMock);
  76. $sheets = $TcaEntry['sheets'];
  77. foreach ($sheets as $sheet) {
  78. $sheetName = $sheet['name'];
  79. $mockedElements = array_keys($dataStructureMock['sheets'][$sheetName]['ROOT']['el']);
  80. $this->assertNotEmpty($mockedElements);
  81. foreach ($mockedElements as $element) {
  82. $this->assertContains($element, $sheet['elements']);
  83. }
  84. }
  85. }
  86. /**
  87. * @test
  88. * @covers t3lib_TCA_DataStructure_FlexFormsResolver::extractSheetInformation
  89. */
  90. public function fieldConfigIsCorrectlyExtracted() {
  91. $dataStructureMock = array('sheets' => array(
  92. 'defaultSheet' => array('ROOT' => array('el' => array(
  93. uniqid('el-') => array(
  94. 'TCEforms' => array(
  95. 'label' => uniqid(),
  96. 'config' => array('type' => uniqid())
  97. )
  98. ),
  99. uniqid('el-') => array(
  100. 'TCEforms' => array(
  101. 'config' => array('type' => uniqid())
  102. )
  103. )
  104. ))),
  105. ));
  106. $fixture = new t3lib_TCA_DataStructure_FlexFormsResolver();
  107. $TcaEntry = $fixture->extractInformationFromDataStructureArray($dataStructureMock);
  108. $elements = $dataStructureMock['sheets']['defaultSheet']['ROOT']['el'];
  109. $elementNames = array_keys($elements);
  110. foreach ($elementNames as $elementName) {
  111. $this->assertArrayHasKey($elementName, $TcaEntry['columns']);
  112. $this->assertEquals(array_merge($elements[$elementName]['TCEforms'], array('_type' => 'field')),
  113. $TcaEntry['columns'][$elementName]);
  114. }
  115. }
  116. protected function mockContainerDataStructure() {
  117. return array(
  118. 'tx_templavoila' => array('title' => uniqid()),
  119. 'el' => array(
  120. 'TCEforms' => array(
  121. uniqid() => array()
  122. )
  123. )
  124. );
  125. }
  126. protected function getMockedDataStructureWithContainer() {
  127. return array('sheets' => array(
  128. 'defaultSheet' => array('ROOT' => array('el' => array(
  129. 'sectionField' => array(
  130. 'section' => 1,
  131. 'el' => array(
  132. 'containerOne' => $this->mockContainerDataStructure(),
  133. 'containerTwo' => $this->mockContainerDataStructure(),
  134. )
  135. )
  136. )))
  137. ));
  138. }
  139. /**
  140. * @test
  141. * @covers t3lib_TCA_DataStructure_FlexFormsResolver::extractContainersFromFlexformSection
  142. */
  143. public function containersAreRecognizedWhileResolvingDataStructure() {
  144. $dataStructure = $this->getMockedDataStructureWithContainer();
  145. $container1 = $dataStructure['sheets']['defaultSheet']['ROOT']['el']['sectionField']['el']['containerOne'];
  146. $container2 = $dataStructure['sheets']['defaultSheet']['ROOT']['el']['sectionField']['el']['containerTwo'];
  147. /** @var $fixture t3lib_TCA_DataStructure_FlexFormsResolver */
  148. $fixture = $this->getMock('t3lib_TCA_DataStructure_FlexFormsResolver', array('extractFieldInformationFromFlexformContainer'));
  149. $fixture->expects($this->at(0))->method('extractFieldInformationFromFlexformContainer')->with($this->equalTo($container1));
  150. $fixture->expects($this->at(1))->method('extractFieldInformationFromFlexformContainer')->with($this->equalTo($container2));
  151. $TcaEntry = $fixture->extractInformationFromDataStructureArray($dataStructure);
  152. $sectionField = $TcaEntry['columns']['sectionField'];
  153. $this->assertArrayHasKey('containerOne', $sectionField['containers']);
  154. $this->assertArrayHasKey('containerTwo', $sectionField['containers']);
  155. $this->assertEquals($container1['tx_templavoila']['title'], $sectionField['containers']['containerOne']['title']);
  156. }
  157. /**
  158. * @test
  159. * @covers t3lib_TCA_DataStructure_FlexFormsResolver::extractFieldInformationFromFlexformContainer
  160. */
  161. public function containerFieldsAreCorrectlyExtractedFromDataStructure() {
  162. $dataStructure = $this->getMockedDataStructureWithContainer();
  163. $containers = $dataStructure['sheets']['defaultSheet']['ROOT']['el']['sectionField']['el'];
  164. $fixture = new t3lib_TCA_DataStructure_FlexFormsResolver();
  165. $TcaEntry = $fixture->extractInformationFromDataStructureArray($dataStructure);
  166. $sectionField = $TcaEntry['columns']['sectionField'];
  167. foreach ($containers as $containerName => $containerDataStructure) {
  168. $containerTca = $sectionField['containers'][$containerName];
  169. foreach ($containerDataStructure['el'] as $fieldName => $fieldConfig) {
  170. $this->assertEquals($fieldConfig['TCEforms'], $containerTca['columns'][$fieldName]);
  171. }
  172. }
  173. }
  174. /**
  175. * @test
  176. * @covers t3lib_TCA_DataStructure_FlexFormsResolver::extractColumnsFromDataStructureArray
  177. */
  178. public function configArrayIsCorrectlySetForSectionFields() {
  179. $dataStructureMock = array('sheets' => array(
  180. 'defaultSheet' => array('ROOT' => array('el' => array(
  181. 'sectionField' => array(
  182. 'section' => 1
  183. )
  184. )))
  185. ));
  186. /** @var $fixture t3lib_TCA_DataStructure_FlexFormsResolver */
  187. $fixture = $this->getMock('t3lib_TCA_DataStructure_FlexFormsResolver', array('resolveDataStructureXml', 'createDataStructureObject'));
  188. $TcaEntry = $fixture->extractInformationFromDataStructureArray($dataStructureMock);
  189. $column = array_shift($TcaEntry['columns']);
  190. $this->assertArrayHasKey('config', $column);
  191. $this->assertEquals('flexsection', $column['config']['type']);
  192. }
  193. }
  194. ?>