[FEATURE] Unit test for t3lib_befunc::getCommonSelectFields
authorPhilipp Gampe <forge.typo3.org@philippgampe.info>
Fri, 17 Feb 2012 12:23:48 +0000 (13:23 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 19 Feb 2012 14:38:51 +0000 (15:38 +0100)
Change-Id: I61fa3a31ccdb141c77fb96b0714a2c412380ed0d
Resolves: #34039
Related: #17947
Releases: 4.7
Reviewed-on: http://review.typo3.org/9071
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
tests/t3lib/class.t3lib_befuncTest.php

index 299ba0b..0aebb17 100644 (file)
@@ -62,5 +62,127 @@ class t3lib_befuncTest extends tx_phpunit_testcase {
                        )
                );
        }
+
+
+       ////////////////////////////////////////////
+       // Tests concerning getCommenSelectFields
+       ////////////////////////////////////////////
+
+       /**
+        * Data provider for getCommonSelectFieldsReturnsCorrectFields
+        *
+        * @return array The test data with $table, $prefix, $presetFields, $tca, $expectedFields
+        */
+       public function getCommonSelectFieldsReturnsCorrectFieldsDataProvider() {
+               return array(
+                       'only uid' => array(
+                               'table' => 'test_table',
+                               'prefix' => '',
+                               'presetFields' => array(),
+                               'tca' => array(),
+                               'expectedFields' => 'uid',
+                       ),
+                       'label set' => array(
+                               'table' => 'test_table',
+                               'prefix' => '',
+                               'presetFields' => array(),
+                               'tca' => array(
+                                       'ctrl' => array(
+                                               'label'=> 'label',
+                                       )
+                               ),
+                               'expectedFields' => 'uid,label',
+                       ),
+                       'label_alt set' => array(
+                               'table' => 'test_table',
+                               'prefix' => '',
+                               'presetFields' => array(),
+                               'tca' => array(
+                                       'ctrl' => array(
+                                               'label_alt'=> 'label,label2',
+                                       )
+                               ),
+                               'expectedFields' => 'uid,label,label2',
+                       ),
+                       'versioningWS set' => array(
+                               'table' => 'test_table',
+                               'prefix' => '',
+                               'presetFields' => array(),
+                               'tca' => array(
+                                       'ctrl' => array(
+                                               'versioningWS'=> '2',
+                                       )
+                               ),
+                               'expectedFields' => 'uid,t3ver_id,t3ver_state,t3ver_wsid,t3ver_count',
+                       ),
+                       'selicon_field set' => array(
+                               'table' => 'test_table',
+                               'prefix' => '',
+                               'presetFields' => array(),
+                               'tca' => array(
+                                       'ctrl' => array(
+                                               'selicon_field'=> 'field',
+                                       )
+                               ),
+                               'expectedFields' => 'uid,field',
+                       ),
+                       'typeicon_column set' => array(
+                               'table' => 'test_table',
+                               'prefix' => '',
+                               'presetFields' => array(),
+                               'tca' => array(
+                                       'ctrl' => array(
+                                               'typeicon_column'=> 'field',
+                                       )
+                               ),
+                               'expectedFields' => 'uid,field',
+                       ),
+                       'enablecolumns set' => array(
+                               'table' => 'test_table',
+                               'prefix' => '',
+                               'presetFields' => array(),
+                               'tca' => array(
+                                       'ctrl' => array(
+                                               'enablecolumns'=> array(
+                                                       'disabled' => 'hidden',
+                                                       'starttime' => 'start',
+                                                       'endtime' => 'stop',
+                                                       'fe_group' => 'groups',
+                                               ),
+                                       )
+                               ),
+                               'expectedFields' => 'uid,hidden,start,stop,groups',
+                       ),
+                       'label set to uid' => array(
+                               'table' => 'test_table',
+                               'prefix' => '',
+                               'presetFields' => array(),
+                               'tca' => array(
+                                       'ctrl' => array(
+                                               'label'=> 'uid',
+                                       )
+                               ),
+                               'expectedFields' => 'uid',
+                       ),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider getCommonSelectFieldsReturnsCorrectFieldsDataProvider
+        */
+       public function getCommonSelectFieldsReturnsCorrectFields($table, $prefix = '', array $presetFields, array $tca, $expectedFields = '') {
+               t3lib_div::loadTCA($table);
+               $tcaBackup = $GLOBALS['TCA'][$table];
+               unset($GLOBALS['TCA'][$table]);
+               $GLOBALS['TCA'][$table] = $tca;
+
+               $selectFields = $this->fixture->getCommonSelectFields($table, $prefix, $presetFields);
+
+               unset($GLOBALS['TCA'][$table]);
+               $GLOBALS['TCA'][$table] = $tcaBackup;
+
+               $this->assertEquals($selectFields, $expectedFields);
+       }
 }
 ?>
\ No newline at end of file