PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/t3lib/tca/t3lib_tca_datastructureTest.php

https://github.com/andreaswolf/typo3-tceforms
PHP | 220 lines | 109 code | 34 blank | 77 comment | 0 complexity | adc5823019a1f0d00fff4ad6a094cbdb 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 data structure abstraction class in TCA.
  29. *
  30. * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
  31. * @package TYPO3
  32. * @subpackage t3lib
  33. */
  34. class t3lib_TCA_DataStructureTest extends Tx_Phpunit_TestCase {
  35. /**
  36. * @test
  37. * @covers t3lib_TCA_DataStructure::hasControlValue
  38. * @covers t3lib_TCA_DataStructure::getControlValue
  39. */
  40. public function controlValuesCanBeRetrievedFromDataStructure() {
  41. $TcaFixture = array(
  42. 'ctrl' => array(
  43. 'some' => uniqid(),
  44. 'random' => uniqid(),
  45. 'config' => uniqid(),
  46. 'values' => uniqid()
  47. )
  48. );
  49. $fixture = new t3lib_TCA_DataStructure($TcaFixture);
  50. foreach ($TcaFixture['ctrl'] as $key => $value) {
  51. $this->assertTrue($fixture->hasControlValue($key));
  52. $this->assertEquals($value, $fixture->getControlValue($key));
  53. }
  54. $this->assertFalse($fixture->hasControlValue(uniqid()));
  55. }
  56. /**
  57. * @test
  58. * @covers t3lib_TCA_DataStructure::getFieldObject
  59. */
  60. public function getFieldObjectReturnsProperFieldObject() {
  61. /** @var $mockedField t3lib_TCA_DataStructure_Field */
  62. $mockedField = $this->getMock('t3lib_TCA_DataStructure_Field', array(), array(), '', FALSE);
  63. t3lib_div::addInstance('t3lib_TCA_DataStructure_Field', $mockedField);
  64. /** @var $fixture t3lib_TCA_DataStructure */
  65. $fixture = $this->getMock('t3lib_TCA_DataStructure', NULL, array(), '', FALSE);
  66. $this->assertSame($mockedField, $fixture->getFieldObject(uniqid()));
  67. }
  68. /**
  69. * @test
  70. * @covers t3lib_TCA_DataStructure::getFieldObject
  71. */
  72. public function getFieldObjectCachesObjects() {
  73. /** @var $mockedField t3lib_TCA_DataStructure_Field */
  74. $mockedField = $this->getMock('t3lib_TCA_DataStructure_Field', array(), array(), '', FALSE);
  75. t3lib_div::addInstance('t3lib_TCA_DataStructure_Field', $mockedField);
  76. $fieldName1 = uniqid();
  77. /** @var $mockedField t3lib_TCA_DataStructure_Field */
  78. $mockedField2 = $this->getMock('t3lib_TCA_DataStructure_Field', array(), array(), '', FALSE);
  79. t3lib_div::addInstance('t3lib_TCA_DataStructure_Field', $mockedField2);
  80. $fieldName2 = uniqid();
  81. /** @var $fixture t3lib_TCA_DataStructure */
  82. $fixture = $this->getMock('t3lib_TCA_DataStructure', NULL, array(), '', FALSE);
  83. $obj1 = $fixture->getFieldObject($fieldName1);
  84. $obj2 = $fixture->getFieldObject($fieldName1);
  85. $obj3 = $fixture->getFieldObject($fieldName2);
  86. $this->assertSame($mockedField, $obj1);
  87. $this->assertSame($obj1, $obj2);
  88. $this->assertNotSame($obj1, $obj3);
  89. }
  90. /**
  91. * @test
  92. * @covers t3lib_TCA_DataStructure::hasTypeField
  93. * @covers t3lib_TCA_DataStructure::getTypeField
  94. */
  95. public function typeFieldIsCorrectlyHandled() {
  96. $TcaFixture = array(
  97. 'ctrl' => array(
  98. 'type' => uniqid()
  99. )
  100. );
  101. $fixture = new t3lib_TCA_DataStructure($TcaFixture);
  102. $this->assertTrue($fixture->hasTypeField());
  103. $this->assertEquals($TcaFixture['ctrl']['type'], $fixture->getTypeField());
  104. }
  105. /**
  106. * @test
  107. * @covers t3lib_TCA_DataStructure::hasLanguageField
  108. * @covers t3lib_TCA_DataStructure::getLanguageField
  109. */
  110. public function languageFieldIsCorrectlyHandled() {
  111. $TcaFixture = array(
  112. 'ctrl' => array(
  113. 'languageField' => uniqid()
  114. )
  115. );
  116. $fixture = new t3lib_TCA_DataStructure($TcaFixture);
  117. $this->assertTrue($fixture->hasLanguageField());
  118. $this->assertEquals($TcaFixture['ctrl']['languageField'], $fixture->getLanguageField());
  119. }
  120. /**
  121. * @test
  122. */
  123. public function hasFieldReturnsProperValues() {
  124. $TcaFixture = array(
  125. 'columns' => array(
  126. 'some' => array('foo' => uniqid()),
  127. 'random' => array('bar' => uniqid()),
  128. 'columns' => array('baz' => uniqid())
  129. )
  130. );
  131. $fixture = new t3lib_TCA_DataStructure($TcaFixture);
  132. foreach (array_keys($TcaFixture['columns']) as $fieldName) {
  133. $this->assertTrue($fixture->hasField($fieldName));
  134. }
  135. $this->assertFalse($fixture->hasField(uniqid('foo')));
  136. }
  137. /**
  138. * @test
  139. */
  140. public function fieldConfigurationsCanBeRetrievedFromDataStructure() {
  141. $TcaFixture = array(
  142. 'columns' => array(
  143. 'some' => array('foo' => uniqid()),
  144. 'random' => array('bar' => uniqid()),
  145. 'columns' => array('baz' => uniqid())
  146. )
  147. );
  148. $fixture = new t3lib_TCA_DataStructure($TcaFixture);
  149. $fieldConfigurations = $fixture->getFieldConfigurations();
  150. foreach ($TcaFixture['columns'] as $fieldName => $configuration) {
  151. $this->assertArrayHasKey($fieldName, $fieldConfigurations);
  152. $this->assertEquals($configuration, $fieldConfigurations[$fieldName]);
  153. $this->assertEquals($configuration, $fixture->getFieldConfiguration($fieldName));
  154. }
  155. }
  156. /**
  157. * @test
  158. * @covers t3lib_TCA_DataStructure::getTypeConfiguration
  159. */
  160. public function getTypeConfigurationFallsBackToDefaultTypeNumberForInvalidTypeNumbers() {
  161. /** @var $fixture t3lib_TCA_DataStructure */
  162. $fixture = $this->getMock('t3lib_TCA_DataStructure', array('typeExists', 'createTypeObject'), array(), '', FALSE);
  163. $fixture->expects($this->once())->method('typeExists')->will($this->returnValue(FALSE));
  164. $fixture->expects($this->once())->method('createTypeObject')->with($this->equalTo(1));
  165. $fixture->getTypeConfiguration(0);
  166. }
  167. /**
  168. * @test
  169. * @covers t3lib_TCA_DataStructure::getTypeConfiguration
  170. * @covers t3lib_TCA_DataStructure::createTypeObject
  171. */
  172. public function getTypeConfiurationCachesCreatedObjects() {
  173. $mockedType = $this->getMock('t3lib_TCA_DataStructure_Type', array(), array(), '', FALSE);
  174. t3lib_div::addInstance('t3lib_TCA_DataStructure_Type', $mockedType);
  175. $mockedTca = array('types' => array(
  176. '1' => array()
  177. ));
  178. /** @var $fixture t3lib_TCA_DataStructure */
  179. $fixture = $this->getMock('t3lib_TCA_DataStructure', array('typeExists'), array($mockedTca));
  180. $fixture->expects($this->any())->method('typeExists')->will($this->returnValue(FALSE));
  181. $obj1 = $fixture->getTypeConfiguration(1);
  182. $obj2 = $fixture->getTypeConfiguration(1);
  183. $this->assertSame($obj1, $obj2);
  184. }
  185. }
  186. ?>