[FEATURE] Unit test for t3lib_befunc::getCommonSelectFields
[Packages/TYPO3.CMS.git] / tests / t3lib / class.t3lib_befuncTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Oliver Klee (typo3-coding@oliverklee.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 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Testcase for the t3lib_BEfunc class in the TYPO3 core.
27 *
28 * @package TYPO3
29 * @subpackage t3lib
30 *
31 * @author Oliver Klee <typo3-coding@oliverklee.de>
32 */
33 class t3lib_befuncTest extends tx_phpunit_testcase {
34 /**
35 * @var t3lib_BEfunc
36 */
37 private $fixture;
38
39 public function setUp() {
40 $this->fixture = new t3lib_BEfunc();
41 }
42
43 public function tearDown() {
44 unset($this->fixture);
45 }
46
47
48 ///////////////////////////////////////
49 // Tests concerning getProcessedValue
50 ///////////////////////////////////////
51
52 /**
53 * @test
54 *
55 * @see http://bugs.typo3.org/view.php?id=11875
56 */
57 public function getProcessedValueForZeroStringIsZero() {
58 $this->assertEquals(
59 '0',
60 $this->fixture->getProcessedValue(
61 'tt_content', 'header', '0'
62 )
63 );
64 }
65
66
67 ////////////////////////////////////////////
68 // Tests concerning getCommenSelectFields
69 ////////////////////////////////////////////
70
71 /**
72 * Data provider for getCommonSelectFieldsReturnsCorrectFields
73 *
74 * @return array The test data with $table, $prefix, $presetFields, $tca, $expectedFields
75 */
76 public function getCommonSelectFieldsReturnsCorrectFieldsDataProvider() {
77 return array(
78 'only uid' => array(
79 'table' => 'test_table',
80 'prefix' => '',
81 'presetFields' => array(),
82 'tca' => array(),
83 'expectedFields' => 'uid',
84 ),
85 'label set' => array(
86 'table' => 'test_table',
87 'prefix' => '',
88 'presetFields' => array(),
89 'tca' => array(
90 'ctrl' => array(
91 'label'=> 'label',
92 )
93 ),
94 'expectedFields' => 'uid,label',
95 ),
96 'label_alt set' => array(
97 'table' => 'test_table',
98 'prefix' => '',
99 'presetFields' => array(),
100 'tca' => array(
101 'ctrl' => array(
102 'label_alt'=> 'label,label2',
103 )
104 ),
105 'expectedFields' => 'uid,label,label2',
106 ),
107 'versioningWS set' => array(
108 'table' => 'test_table',
109 'prefix' => '',
110 'presetFields' => array(),
111 'tca' => array(
112 'ctrl' => array(
113 'versioningWS'=> '2',
114 )
115 ),
116 'expectedFields' => 'uid,t3ver_id,t3ver_state,t3ver_wsid,t3ver_count',
117 ),
118 'selicon_field set' => array(
119 'table' => 'test_table',
120 'prefix' => '',
121 'presetFields' => array(),
122 'tca' => array(
123 'ctrl' => array(
124 'selicon_field'=> 'field',
125 )
126 ),
127 'expectedFields' => 'uid,field',
128 ),
129 'typeicon_column set' => array(
130 'table' => 'test_table',
131 'prefix' => '',
132 'presetFields' => array(),
133 'tca' => array(
134 'ctrl' => array(
135 'typeicon_column'=> 'field',
136 )
137 ),
138 'expectedFields' => 'uid,field',
139 ),
140 'enablecolumns set' => array(
141 'table' => 'test_table',
142 'prefix' => '',
143 'presetFields' => array(),
144 'tca' => array(
145 'ctrl' => array(
146 'enablecolumns'=> array(
147 'disabled' => 'hidden',
148 'starttime' => 'start',
149 'endtime' => 'stop',
150 'fe_group' => 'groups',
151 ),
152 )
153 ),
154 'expectedFields' => 'uid,hidden,start,stop,groups',
155 ),
156 'label set to uid' => array(
157 'table' => 'test_table',
158 'prefix' => '',
159 'presetFields' => array(),
160 'tca' => array(
161 'ctrl' => array(
162 'label'=> 'uid',
163 )
164 ),
165 'expectedFields' => 'uid',
166 ),
167 );
168 }
169
170 /**
171 * @test
172 * @dataProvider getCommonSelectFieldsReturnsCorrectFieldsDataProvider
173 */
174 public function getCommonSelectFieldsReturnsCorrectFields($table, $prefix = '', array $presetFields, array $tca, $expectedFields = '') {
175 t3lib_div::loadTCA($table);
176 $tcaBackup = $GLOBALS['TCA'][$table];
177 unset($GLOBALS['TCA'][$table]);
178 $GLOBALS['TCA'][$table] = $tca;
179
180 $selectFields = $this->fixture->getCommonSelectFields($table, $prefix, $presetFields);
181
182 unset($GLOBALS['TCA'][$table]);
183 $GLOBALS['TCA'][$table] = $tcaBackup;
184
185 $this->assertEquals($selectFields, $expectedFields);
186 }
187 }
188 ?>