Follow-up to feature #9897: Added unit tests for addFieldsToPalette() and addToAllTCA...
authorOliver Hader <oliver.hader@typo3.org>
Mon, 31 Aug 2009 14:52:15 +0000 (14:52 +0000)
committerOliver Hader <oliver.hader@typo3.org>
Mon, 31 Aug 2009 14:52:15 +0000 (14:52 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@5856 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
tests/t3lib/t3lib_extmgm_testcase.php

index ee64f20..f469f16 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2009-08-31  Oliver Hader  <oliver@typo3.org>
 
        * Cleanup: Set SVN properties and tags
+       * Follow-up to feature #9897: Added unit tests for addFieldsToPalette() and addToAllTCAtypes() in t3lib_extMgm
 
 2009-08-31  Ingo Renner  <ingo@typo3.org>
 
index 96b5da6..be4dca7 100644 (file)
@@ -65,11 +65,158 @@ class t3lib_extmgm_testcase extends tx_phpunit_testcase {
                );
        }
 
+       /**
+        * Tests whether fields can be add to all TCA types and duplicate fields are considered.
+        * @test
+        * @see t3lib_extMgm::addToAllTCAtypes()
+        */
+       public function canAddFieldsToAllTCATypesBeforeExistingOnes() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'] = $this->generateTCAForTable($table);
+
+               t3lib_extMgm::addToAllTCAtypes($table, 'newA, newB, fieldA', '', 'before:fieldD');
+
+                       // Checking typeA:
+               $this->assertEquals(
+                       'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
+                       $GLOBALS['TCA'][$table]['types']['typeA']['showitem']
+               );
+                       // Checking typeB:
+               $this->assertEquals(
+                       'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
+                       $GLOBALS['TCA'][$table]['types']['typeB']['showitem']
+               );
+       }
+
+       /**
+        * Tests whether fields can be add to all TCA types and duplicate fields are considered.
+        * @test
+        * @see t3lib_extMgm::addToAllTCAtypes()
+        */
+       public function canAddFieldsToAllTCATypesAfterExistingOnes() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'] = $this->generateTCAForTable($table);
+
+               t3lib_extMgm::addToAllTCAtypes($table, 'newA, newB, fieldA', '', 'after:fieldC');
+
+                       // Checking typeA:
+               $this->assertEquals(
+                       'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
+                       $GLOBALS['TCA'][$table]['types']['typeA']['showitem']
+               );
+                       // Checking typeB:
+               $this->assertEquals(
+                       'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
+                       $GLOBALS['TCA'][$table]['types']['typeB']['showitem']
+               );
+       }
+
+       /**
+        * Tests whether fields can be add to a TCA type before existing ones
+        * @test
+        * @see t3lib_extMgm::addToAllTCAtypes()
+        */
+       public function canAddFieldsToTCATypeBeforeExistingOnes() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'] = $this->generateTCAForTable($table);
+
+               t3lib_extMgm::addToAllTCAtypes($table, 'newA, newB, fieldA', 'typeA', 'before:fieldD');
+
+                       // Checking typeA:
+               $this->assertEquals(
+                       'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
+                       $GLOBALS['TCA'][$table]['types']['typeA']['showitem']
+               );
+                       // Checking typeB:
+               $this->assertEquals(
+                       'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD',
+                       $GLOBALS['TCA'][$table]['types']['typeB']['showitem']
+               );
+       }
+
+       /**
+        * Tests whether fields can be add to a TCA type after existing ones
+        * @test
+        * @see t3lib_extMgm::addToAllTCAtypes()
+        */
+       public function canAddFieldsToTCATypeAfterExistingOnes() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'] = $this->generateTCAForTable($table);
+
+               t3lib_extMgm::addToAllTCAtypes($table, 'newA, newB, fieldA', 'typeA', 'after:fieldC');
+
+                       // Checking typeA:
+               $this->assertEquals(
+                       'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
+                       $GLOBALS['TCA'][$table]['types']['typeA']['showitem']
+               );
+                       // Checking typeB:
+               $this->assertEquals(
+                       'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD',
+                       $GLOBALS['TCA'][$table]['types']['typeB']['showitem']
+               );
+       }
+
+       /**
+        * Tests whether fields can be added to a palette before existing elements.
+        * @test
+        * @see t3lib_extMgm::addFieldsToPalette()
+        */
+       public function canAddFieldsToPaletteBeforeExistingOnes() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'] = $this->generateTCAForTable($table);
+
+               t3lib_extMgm::addFieldsToPalette($table, 'paletteA', 'newA, newB, fieldX', 'before:fieldY');
+
+               $this->assertEquals(
+                       'fieldX, newA, newB, fieldY',
+                       $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
+               );
+       }
+
+       /**
+        * Tests whether fields can be added to a palette after existing elements.
+        * @test
+        * @see t3lib_extMgm::addFieldsToPalette()
+        */
+       public function canAddFieldsToPaletteAfterExistingOnes() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'] = $this->generateTCAForTable($table);
+
+               t3lib_extMgm::addFieldsToPalette($table, 'paletteA', 'newA, newB, fieldX', 'after:fieldX');
+
+               $this->assertEquals(
+                       'fieldX, newA, newB, fieldY',
+                       $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
+               );
+       }
+
        public function tearDown() {
                foreach ($this->globals as $key => $value) {
                        $GLOBALS[$key] = unserialize($value);
                }
        }
+
+       /**
+        * Generates a basic TCA for a given table.
+        *
+        * @param       string          $table: Name of the table
+        * @return      array           Generated TCA for the given table
+        */
+       private function generateTCAForTable($table) {
+               $tca = array();
+               $tca[$table] = array();
+               $tca[$table]['types'] = array(
+                       'typeA' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD'),
+                       'typeB' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD'),
+               );
+               $tca[$table]['palettes'] = array(
+                       'paletteA' => array('showitem' => 'fieldX, fieldY'),
+                       'paletteB' => array('showitem' => 'fieldX, fieldY'),
+               );
+
+               return $tca;
+       }
 }
 
 ?>
\ No newline at end of file