[BUGFIX] TSConfig for fields with a dot in the name does not work
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / TypoScript / Parser / TypoScriptParserTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\TypoScript\Parser;
3
4 /***********************************************************************
5 * Copyright notice
6 *
7 * (c) 2012 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
8 * 2012 Oliver Hader <oliver.hader@typo3.org>
9 *
10 * All rights reserved
11 *
12 * This script is part of the TYPO3 project. The TYPO3 project is
13 * free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * The GNU General Public License can be found at
19 * http://www.gnu.org/copyleft/gpl.html.
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 **********************************************************************/
28
29 /**
30 * Testcase for \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
31 *
32 * @author Kai Vogel <kai.vogel@speedprogs.de>
33 * @author Oliver Hader <oliver.hader@typo3.org>
34 */
35 class TypoScriptParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
36
37 /**
38 * @var \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
39 */
40 protected $fixture;
41
42 /**
43 * Sets up the test cases.
44 */
45 protected function setUp() {
46 $this->fixture = new \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser();
47 }
48
49 /**
50 * Tears down the test cases.
51 */
52 protected function tearDown() {
53 unset($this->fixture);
54 }
55
56 /**
57 * @param string $typoScript
58 * @param array $expected
59 * @dataProvider typoScriptIsParsedToArrayDataProvider
60 * @test
61 */
62 public function typoScriptIsParsedToArray($typoScript, array $expected) {
63 $this->fixture->parse($typoScript);
64 $this->assertEquals($expected, $this->fixture->setup);
65 }
66
67 /**
68 * @param string $typoScript
69 * @param array $expected
70 * @dataProvider typoScriptIsParsedToArrayDataProvider
71 * @test
72 */
73 public function typoScriptIsStrictlyParsedToArray($typoScript, array $expected) {
74 $this->fixture->strict = TRUE;
75 $this->fixture->parse($typoScript);
76 $this->assertEquals($expected, $this->fixture->setup);
77 }
78
79 /**
80 * @return array
81 */
82 public function typoScriptIsParsedToArrayDataProvider() {
83 return array(
84 'simple assignment' => array(
85 'key = value',
86 array(
87 'key' => 'value',
88 )
89 ),
90 'nested assignment' => array(
91 'lib.key = value',
92 array(
93 'lib.' => array(
94 'key' => 'value',
95 ),
96 ),
97 ),
98 'nested structured assignment' => array(
99 'lib {' . LF .
100 'key = value' . LF .
101 '}',
102 array(
103 'lib.' => array(
104 'key' => 'value',
105 ),
106 ),
107 ),
108 'multiline assignment' => array(
109 'key (' . LF .
110 'first' . LF .
111 'second' . LF .
112 ')',
113 array(
114 'key' => 'first' . LF . 'second',
115 ),
116 ),
117 'copying values' => array(
118 'lib.default = value' . LF .
119 'lib.copy < lib.default',
120 array(
121 'lib.' => array(
122 'default' => 'value',
123 'copy' => 'value',
124 ),
125 ),
126 ),
127 'one-line hash comment' => array(
128 'first = 1' . LF .
129 '# ignore = me' . LF .
130 'second = 2',
131 array(
132 'first' => '1',
133 'second' => '2',
134 ),
135 ),
136 'one-line slash comment' => array(
137 'first = 1' . LF .
138 '// ignore = me' . LF .
139 'second = 2',
140 array(
141 'first' => '1',
142 'second' => '2',
143 ),
144 ),
145 'multi-line slash comment' => array(
146 'first = 1' . LF .
147 '/*' . LF .
148 'ignore = me' . LF .
149 '*/' . LF .
150 'second = 2',
151 array(
152 'first' => '1',
153 'second' => '2',
154 ),
155 ),
156 );
157 }
158
159 /**
160 * @param string $typoScript
161 * @param array $expected
162 * @dataProvider typoScriptWithQuotedKeysIsParsedToArrayDataProvider
163 * @test
164 */
165 public function typoScriptWithQuotedKeysIsParsedToArray($typoScript, array $expected) {
166 $this->fixture->parse($typoScript);
167 $this->assertEquals($expected, $this->fixture->setup);
168 }
169
170 /**
171 * @param string $typoScript
172 * @param array $expected
173 * @dataProvider typoScriptWithQuotedKeysIsParsedToArrayDataProvider
174 * @test
175 */
176 public function typoScriptWithQuotedKeysIsStrictlyParsedToArray($typoScript, array $expected) {
177 $this->fixture->strict = TRUE;
178 $this->fixture->parse($typoScript);
179 $this->assertEquals($expected, $this->fixture->setup);
180 }
181
182 /**
183 * @return array
184 */
185 public function typoScriptWithQuotedKeysIsParsedToArrayDataProvider() {
186 return array(
187 'quoted key with regular characters' => array(
188 '"key" = value',
189 array(
190 'key' => 'value',
191 ),
192 ),
193 'nested quoted key with regular characters' => array(
194 'lib."key" = value',
195 array(
196 'lib.' => array(
197 'key' => 'value',
198 ),
199 ),
200 ),
201 'nested structured quoted key with regular characters' => array(
202 'lib {' . LF .
203 '"key" = value' . LF .
204 '}',
205 array(
206 'lib.' => array(
207 'key' => 'value',
208 ),
209 ),
210 ),
211 'quoted key containing dash' => array(
212 '"the-key" = value',
213 array(
214 'the-key' => 'value',
215 ),
216 ),
217 'nested quoted key containing dash' => array(
218 'lib."the-key" = value',
219 array(
220 'lib.' => array(
221 'the-key' => 'value',
222 ),
223 ),
224 ),
225 'nested structured quoted key containing dash' => array(
226 'lib {' . LF .
227 '"the-key" = value' . LF .
228 '}',
229 array(
230 'lib.' => array(
231 'the-key' => 'value',
232 ),
233 ),
234 ),
235 'quoted key containing dot' => array(
236 '"the.key" = value',
237 array(
238 'the.key' => 'value',
239 ),
240 ),
241 'nested quoted key containing dot' => array(
242 'lib."the.key" = value',
243 array(
244 'lib.' => array(
245 'the.key' => 'value',
246 ),
247 ),
248 ),
249 'nested structured quoted key containing dot' => array(
250 'lib {' . LF .
251 '"the.key" = value' . LF .
252 '}',
253 array(
254 'lib.' => array(
255 'the.key' => 'value',
256 ),
257 ),
258 ),
259 'quoted key containing equal operator' => array(
260 '"the=key" = value',
261 array(
262 'the=key' => 'value',
263 ),
264 ),
265 'nested quoted key containing equal operator' => array(
266 'lib."the=key" = value',
267 array(
268 'lib.' => array(
269 'the=key' => 'value',
270 ),
271 ),
272 ),
273 'nested structured quoted key containing equal operator' => array(
274 'lib {' . LF .
275 '"the=key" = value' . LF .
276 '}',
277 array(
278 'lib.' => array(
279 'the=key' => 'value',
280 ),
281 ),
282 ),
283 );
284 }
285
286 }
287 ?>