[BUGFIX] Exclude CDATA from t3lib_parsehtml->XHTML_clean
[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 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Testcase for \TYPO3\CMS\Core\Html\HtmlParser
19 *
20 * @author Nicole Cordes <typo3@cordes.co>
21 */
22 class HtmlParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
23
24 /**
25 * @var \TYPO3\CMS\Core\Html\HtmlParser
26 */
27 protected $fixture = NULL;
28
29 public function setUp() {
30 $this->fixture = new \TYPO3\CMS\Core\Html\HtmlParser();
31 }
32
33 /**
34 * Data provider for substituteMarkerAndSubpartArrayRecursiveResolvesMarkersAndSubpartsArray
35 */
36 public function substituteMarkerAndSubpartArrayRecursiveResolvesMarkersAndSubpartsArrayDataProvider() {
37 $template = '###SINGLEMARKER1###
38 <!-- ###FOO### begin -->
39 <!-- ###BAR### begin -->
40 ###SINGLEMARKER2###
41 <!-- ###BAR### end -->
42 <!-- ###FOOTER### begin -->
43 ###SINGLEMARKER3###
44 <!-- ###FOOTER### end -->
45 <!-- ###FOO### end -->';
46
47 $expected ='Value 1
48
49
50 Value 2.1
51
52 Value 2.2
53
54
55 Value 3.1
56
57 Value 3.2
58
59 ';
60
61 return array(
62 'Single marker' => array(
63 '###SINGLEMARKER###',
64 array(
65 '###SINGLEMARKER###' => 'Value 1'
66 ),
67 '',
68 FALSE,
69 FALSE,
70 'Value 1'
71 ),
72 'Subpart marker' => array(
73 $template,
74 array(
75 '###SINGLEMARKER1###' => 'Value 1',
76 '###FOO###' => array(
77 array(
78 '###BAR###' => array(
79 array(
80 '###SINGLEMARKER2###' => 'Value 2.1'
81 ),
82 array(
83 '###SINGLEMARKER2###' => 'Value 2.2'
84 )
85 ),
86 '###FOOTER###' => array(
87 array(
88 '###SINGLEMARKER3###' => 'Value 3.1'
89 ),
90 array(
91 '###SINGLEMARKER3###' => 'Value 3.2'
92 )
93 )
94 )
95 )
96 ),
97 '',
98 FALSE,
99 FALSE,
100 $expected
101 ),
102 'Subpart marker with wrap' => array(
103 $template,
104 array(
105 'SINGLEMARKER1' => 'Value 1',
106 'FOO' => array(
107 array(
108 'BAR' => array(
109 array(
110 'SINGLEMARKER2' => 'Value 2.1'
111 ),
112 array(
113 'SINGLEMARKER2' => 'Value 2.2'
114 )
115 ),
116 'FOOTER' => array(
117 array(
118 'SINGLEMARKER3' => 'Value 3.1'
119 ),
120 array(
121 'SINGLEMARKER3' => 'Value 3.2'
122 )
123 )
124 )
125 )
126 ),
127 '###|###',
128 FALSE,
129 FALSE,
130 $expected
131 ),
132 'Subpart marker with lower marker array keys' => array(
133 $template,
134 array(
135 '###singlemarker1###' => 'Value 1',
136 '###foo###' => array(
137 array(
138 '###bar###' => array(
139 array(
140 '###singlemarker2###' => 'Value 2.1'
141 ),
142 array(
143 '###singlemarker2###' => 'Value 2.2'
144 )
145 ),
146 '###footer###' => array(
147 array(
148 '###singlemarker3###' => 'Value 3.1'
149 ),
150 array(
151 '###singlemarker3###' => 'Value 3.2'
152 )
153 )
154 )
155 )
156 ),
157 '',
158 TRUE,
159 FALSE,
160 $expected
161 ),
162 'Subpart marker with unused markers' => array(
163 $template,
164 array(
165 '###FOO###' => array(
166 array(
167 '###BAR###' => array(
168 array(
169 '###SINGLEMARKER2###' => 'Value 2.1'
170 )
171 ),
172 '###FOOTER###' => array(
173 array(
174 '###SINGLEMARKER3###' => 'Value 3.1'
175 )
176 )
177 )
178 )
179 ),
180 '',
181 FALSE,
182 TRUE,
183 '
184
185
186 Value 2.1
187
188
189 Value 3.1
190
191 '
192 ),
193 'Subpart marker with empty subpart' => array(
194 $template,
195 array(
196 '###SINGLEMARKER1###' => 'Value 1',
197 '###FOO###' => array(
198 array(
199 '###BAR###' => array(
200 array(
201 '###SINGLEMARKER2###' => 'Value 2.1'
202 ),
203 array(
204 '###SINGLEMARKER2###' => 'Value 2.2'
205 )
206 ),
207 '###FOOTER###' => array()
208 )
209 )
210 ),
211 '',
212 FALSE,
213 FALSE,
214 'Value 1
215
216
217 Value 2.1
218
219 Value 2.2
220
221
222 '
223 )
224 );
225 }
226
227 /**
228 * @test
229 * @dataProvider substituteMarkerAndSubpartArrayRecursiveResolvesMarkersAndSubpartsArrayDataProvider
230 */
231 public function substituteMarkerAndSubpartArrayRecursiveResolvesMarkersAndSubpartsArray($template, $markersAndSubparts, $wrap, $uppercase, $deleteUnused, $expected) {
232 $this->assertSame($expected, $this->fixture->substituteMarkerAndSubpartArrayRecursive($template, $markersAndSubparts, $wrap, $uppercase, $deleteUnused));
233 }
234
235 /**
236 * @return array
237 */
238 public function cDataWillRemainUnmodifiedDataProvider() {
239 return array(
240 'single-line CDATA' => array(
241 '/*<![CDATA[*/ <hello world> /*]]>*/',
242 '/*<![CDATA[*/ <hello world> /*]]>*/',
243 ),
244 'multi-line CDATA #1' => array(
245 '/*<![CDATA[*/' . LF . '<hello world> /*]]>*/',
246 '/*<![CDATA[*/' . LF . '<hello world> /*]]>*/',
247 ),
248 'multi-line CDATA #2' => array(
249 '/*<![CDATA[*/ <hello world>' . LF . '/*]]>*/',
250 '/*<![CDATA[*/ <hello world>' . LF . '/*]]>*/',
251 ),
252 'multi-line CDATA #3' => array(
253 '/*<![CDATA[*/' . LF . '<hello world>' . LF . '/*]]>*/',
254 '/*<![CDATA[*/' . LF . '<hello world>' . LF . '/*]]>*/',
255 ),
256 );
257 }
258
259 /**
260 * @test
261 * @param string $source
262 * @param string $expected
263 * @dataProvider cDataWillRemainUnmodifiedDataProvider
264 */
265 public function xHtmlCleaningDoesNotModifyCDATA($source, $expected) {
266 $result = $this->fixture->XHTML_clean($source);
267 $this->assertSame($expected, $result);
268 }
269
270 }