[BUGFIX] Empty subpart template if no data given
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Html / HtmlParserTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Html;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Nicole Cordes <typo3@cordes.co>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Testcase for \TYPO3\CMS\Core\Html\HtmlParser
29 *
30 * @author Nicole Cordes <typo3@cordes.co>
31 */
32 class HtmlParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
33
34 /**
35 * @var \TYPO3\CMS\Core\Html\HtmlParser
36 */
37 protected $fixture = NULL;
38
39 public function setUp() {
40 $this->fixture = new \TYPO3\CMS\Core\Html\HtmlParser();
41 }
42
43 public function tearDown() {
44 unset($this->fixture);
45 }
46
47 /**
48 * Data provider for substituteMarkerAndSubpartArrayRecursiveResolvesMarkersAndSubpartsArray
49 */
50 public function substituteMarkerAndSubpartArrayRecursiveResolvesMarkersAndSubpartsArrayDataProvider() {
51 $template = '###SINGLEMARKER1###
52 <!-- ###FOO### begin -->
53 <!-- ###BAR### begin -->
54 ###SINGLEMARKER2###
55 <!-- ###BAR### end -->
56 <!-- ###FOOTER### begin -->
57 ###SINGLEMARKER3###
58 <!-- ###FOOTER### end -->
59 <!-- ###FOO### end -->';
60
61 $expected ='Value 1
62
63
64 Value 2.1
65
66 Value 2.2
67
68
69 Value 3.1
70
71 Value 3.2
72
73 ';
74
75 return array(
76 'Single marker' => array(
77 '###SINGLEMARKER###',
78 array(
79 '###SINGLEMARKER###' => 'Value 1'
80 ),
81 '',
82 FALSE,
83 FALSE,
84 'Value 1'
85 ),
86 'Subpart marker' => array(
87 $template,
88 array(
89 '###SINGLEMARKER1###' => 'Value 1',
90 '###FOO###' => array(
91 array(
92 '###BAR###' => array(
93 array(
94 '###SINGLEMARKER2###' => 'Value 2.1'
95 ),
96 array(
97 '###SINGLEMARKER2###' => 'Value 2.2'
98 )
99 ),
100 '###FOOTER###' => array(
101 array(
102 '###SINGLEMARKER3###' => 'Value 3.1'
103 ),
104 array(
105 '###SINGLEMARKER3###' => 'Value 3.2'
106 )
107 )
108 )
109 )
110 ),
111 '',
112 FALSE,
113 FALSE,
114 $expected
115 ),
116 'Subpart marker with wrap' => array(
117 $template,
118 array(
119 'SINGLEMARKER1' => 'Value 1',
120 'FOO' => array(
121 array(
122 'BAR' => array(
123 array(
124 'SINGLEMARKER2' => 'Value 2.1'
125 ),
126 array(
127 'SINGLEMARKER2' => 'Value 2.2'
128 )
129 ),
130 'FOOTER' => array(
131 array(
132 'SINGLEMARKER3' => 'Value 3.1'
133 ),
134 array(
135 'SINGLEMARKER3' => 'Value 3.2'
136 )
137 )
138 )
139 )
140 ),
141 '###|###',
142 FALSE,
143 FALSE,
144 $expected
145 ),
146 'Subpart marker with lower marker array keys' => array(
147 $template,
148 array(
149 '###singlemarker1###' => 'Value 1',
150 '###foo###' => array(
151 array(
152 '###bar###' => array(
153 array(
154 '###singlemarker2###' => 'Value 2.1'
155 ),
156 array(
157 '###singlemarker2###' => 'Value 2.2'
158 )
159 ),
160 '###footer###' => array(
161 array(
162 '###singlemarker3###' => 'Value 3.1'
163 ),
164 array(
165 '###singlemarker3###' => 'Value 3.2'
166 )
167 )
168 )
169 )
170 ),
171 '',
172 TRUE,
173 FALSE,
174 $expected
175 ),
176 'Subpart marker with unused markers' => array(
177 $template,
178 array(
179 '###FOO###' => array(
180 array(
181 '###BAR###' => array(
182 array(
183 '###SINGLEMARKER2###' => 'Value 2.1'
184 )
185 ),
186 '###FOOTER###' => array(
187 array(
188 '###SINGLEMARKER3###' => 'Value 3.1'
189 )
190 )
191 )
192 )
193 ),
194 '',
195 FALSE,
196 TRUE,
197 '
198
199
200 Value 2.1
201
202
203 Value 3.1
204
205 '
206 ),
207 'Subpart marker with empty subpart' => array(
208 $template,
209 array(
210 '###SINGLEMARKER1###' => 'Value 1',
211 '###FOO###' => array(
212 array(
213 '###BAR###' => array(
214 array(
215 '###SINGLEMARKER2###' => 'Value 2.1'
216 ),
217 array(
218 '###SINGLEMARKER2###' => 'Value 2.2'
219 )
220 ),
221 '###FOOTER###' => array()
222 )
223 )
224 ),
225 '',
226 FALSE,
227 FALSE,
228 'Value 1
229
230
231 Value 2.1
232
233 Value 2.2
234
235
236 '
237 )
238 );
239 }
240
241 /**
242 * @test
243 * @dataProvider substituteMarkerAndSubpartArrayRecursiveResolvesMarkersAndSubpartsArrayDataProvider
244 */
245 public function substituteMarkerAndSubpartArrayRecursiveResolvesMarkersAndSubpartsArray($template, $markersAndSubparts, $wrap, $uppercase, $deleteUnused, $expected) {
246 $this->assertSame($expected, $this->fixture->substituteMarkerAndSubpartArrayRecursive($template, $markersAndSubparts, $wrap, $uppercase, $deleteUnused));
247 }
248 }
249 ?>