[TASK] Mark several parts within RteHtmlParser as internal
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Html / RteHtmlParserTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\Unit\Html;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Core\Html\RteHtmlParser;
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20
21 /**
22 * Test case
23 */
24 class RteHtmlParserTest extends UnitTestCase
25 {
26 /**
27 * @var bool Reset singletons created by subject
28 */
29 protected $resetSingletonInstances = true;
30
31 protected $procOptions = ['overruleMode' => 'default'];
32
33 /**
34 * Data provider for hrTagCorrectlyTransformedOnWayToDataBase
35 */
36 public static function hrTagCorrectlyTransformedOnWayToDataBaseDataProvider()
37 {
38 return [
39 'Single hr' => [
40 '<hr />',
41 '<hr />',
42 ],
43 'Non-xhtml single hr' => [
44 '<hr/>',
45 '<hr />',
46 ],
47 'Double hr' => [
48 '<hr /><hr />',
49 '<hr />' . CRLF . '<hr />',
50 ],
51 'Linebreak followed by hr' => [
52 CRLF . '<hr />',
53 '<hr />',
54 ],
55 'White space followed by hr' => [
56 ' <hr />',
57 ' ' . CRLF . '<hr />',
58 ],
59 'White space followed linebreak and hr' => [
60 ' ' . CRLF . '<hr />',
61 ' ' . CRLF . '<hr />',
62 ],
63 'br followed by hr' => [
64 '<br /><hr />',
65 '<br />' . CRLF . '<hr />',
66 ],
67 'br followed by linebreak and hr' => [
68 '<br />' . CRLF . '<hr />',
69 '<br />' . CRLF . '<hr />',
70 ],
71 'Preserved div followed by hr' => [
72 '<div>Some text</div><hr />',
73 '<div>Some text</div>' . CRLF . '<hr />',
74 ],
75 'Preserved div followed by linebreak and hr' => [
76 '<div>Some text</div>' . CRLF . '<hr />',
77 '<div>Some text</div>' . CRLF . '<hr />',
78 ],
79 'h1 followed by linebreak and hr' => [
80 '<h1>Some text</h1>' . CRLF . '<hr />',
81 '<h1>Some text</h1>' . CRLF . '<hr />',
82 ],
83 'Paragraph followed by linebreak and hr' => [
84 '<p>Some text</p>' . CRLF . '<hr />',
85 '<p>Some text</p>' . CRLF . '<hr />',
86 ],
87 'Some text without HTML tags' => [
88 'Some text',
89 'Some text',
90 ],
91 'Some text followed by hr' => [
92 'Some text<hr />',
93 'Some text' . CRLF . '<hr />',
94 ],
95 'Some text followed by linebreak and hr' => [
96 'Some text' . CRLF . '<hr />',
97 'Some text' . CRLF . '<hr />',
98 ],
99 ];
100 }
101
102 /**
103 * @test
104 * @dataProvider hrTagCorrectlyTransformedOnWayToDataBaseDataProvider
105 */
106 public function hrTagCorrectlyTransformedOnWayToDataBase($content, $expectedResult)
107 {
108 $subject = new RteHtmlParser();
109 $thisConfig = ['proc.' => $this->procOptions];
110 $this->assertEquals($expectedResult, $subject->RTE_transform($content, [], 'db', $thisConfig));
111 }
112
113 /**
114 * Data provider for hrTagCorrectlyTransformedOnWayToDatabaseAndBackToRteProvider
115 */
116 public static function hrTagCorrectlyTransformedOnWayToDatabaseAndBackToRteProvider()
117 {
118 return [
119 'Single hr' => [
120 '<hr />',
121 '<hr />',
122 ],
123 'Non-xhtml single hr' => [
124 '<hr/>',
125 '<hr />',
126 ],
127 'Double hr' => [
128 '<hr /><hr />',
129 '<hr />' . CRLF . '<hr />',
130 ],
131 'Linebreak followed by hr' => [
132 CRLF . '<hr />',
133 '<hr />',
134 ],
135 'White space followed by hr' => [
136 ' <hr />',
137 '<p>&nbsp;</p>' . CRLF . '<hr />',
138 ],
139 'White space followed by linebreak and hr' => [
140 ' ' . CRLF . '<hr />',
141 '<p>&nbsp;</p>' . CRLF . '<hr />',
142 ],
143 'br followed by hr' => [
144 '<br /><hr />',
145 '<p><br /></p>' . CRLF . '<hr />',
146 ],
147 'br followed by linebreak and hr' => [
148 '<br />' . CRLF . '<hr />',
149 '<p><br /></p>' . CRLF . '<hr />',
150 ],
151 'Preserved div followed by hr' => [
152 '<div>Some text</div>' . '<hr />',
153 '<div><p>Some text</p></div>' . CRLF . '<hr />',
154 ],
155 'Preserved div followed by linebreak and hr' => [
156 '<div>Some text</div>' . CRLF . '<hr />',
157 '<div><p>Some text</p></div>' . CRLF . '<hr />',
158 ],
159 'h1 followed by linebreak and hr' => [
160 '<h1>Some text</h1>' . CRLF . '<hr />',
161 '<h1>Some text</h1>' . CRLF . '<hr />',
162 ],
163 'Paragraph followed by linebreak and hr' => [
164 '<p>Some text</p>' . CRLF . '<hr />',
165 '<p>Some text</p>' . CRLF . '<hr />',
166 ],
167 'Some text followed by hr' => [
168 'Some text<hr />',
169 '<p>Some text</p>' . CRLF . '<hr />',
170 ],
171 'Some text followed by linebreak and hr' => [
172 'Some text' . CRLF . '<hr />',
173 '<p>Some text</p>' . CRLF . '<hr />',
174 ],
175 ];
176 }
177
178 /**
179 * @test
180 * @dataProvider hrTagCorrectlyTransformedOnWayToDatabaseAndBackToRteProvider
181 */
182 public function hrTagCorrectlyTransformedOnWayToDatabaseAndBackToRte($content, $expectedResult)
183 {
184 $subject = new RteHtmlParser();
185 $thisConfig = ['proc.' => $this->procOptions];
186 $this->assertEquals($expectedResult, $subject->RTE_transform($subject->RTE_transform($content, [], 'db', $thisConfig), [], 'rte', $thisConfig));
187 }
188
189 /**
190 * Data provider for paragraphCorrectlyTransformedOnWayToDatabase
191 */
192 public static function paragraphCorrectlyTransformedOnWayToDatabaseProvider()
193 {
194 return [
195 'Empty string' => [
196 '',
197 '',
198 ],
199 'Linebreak' => [
200 CRLF,
201 '',
202 ],
203 'Double linebreak' => [
204 CRLF . CRLF,
205 '',
206 ],
207 'Empty paragraph' => [
208 '<p></p>',
209 CRLF,
210 ],
211 'Double empty paragraph' => [
212 '<p></p><p></p>',
213 CRLF . CRLF,
214 ],
215 'Spacing paragraph' => [
216 '<p>&nbsp;</p>',
217 CRLF,
218 ],
219 'Double spacing paragraph' => [
220 '<p>&nbsp;</p>' . '<p>&nbsp;</p>',
221 CRLF . CRLF,
222 ],
223 'Plain text' => [
224 'plain text',
225 'plain text',
226 ],
227 'Plain text followed by linebreak' => [
228 'plain text' . CRLF,
229 'plain text ',
230 ],
231 'Paragraph' => [
232 '<p>paragraph</p>',
233 '<p>paragraph</p>',
234 ],
235 'Paragraph followed by paragraph' => [
236 '<p>paragraph1</p>' . '<p>paragraph2</p>',
237 '<p>paragraph1</p>' . CRLF . '<p>paragraph2</p>',
238 ],
239 'Paragraph followed by paragraph, linebreak-separated' => [
240 '<p>paragraph1</p>' . CRLF . '<p>paragraph2</p>',
241 '<p>paragraph1</p>' . CRLF . '<p>paragraph2</p>',
242 ],
243 'Double spacing paragraph with text' => [
244 '<p>&nbsp;</p><p>&nbsp;</p><p>paragraph1</p>',
245 CRLF . CRLF . '<p>paragraph1</p>',
246 ],
247 'Paragraph followed by linebreak' => [
248 '<p>paragraph</p>' . CRLF,
249 '<p>paragraph</p>',
250 ],
251 'Paragraph followed by spacing paragraph' => [
252 '<p>paragraph</p>' . '<p>&nbsp;</p>',
253 '<p>paragraph</p>' . CRLF . CRLF,
254 ],
255 'Paragraph followed by spacing paragraph, linebreak-separated' => [
256 '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>',
257 '<p>paragraph</p>' . CRLF . CRLF,
258 ],
259 'Paragraph followed by double spacing paragraph' => [
260 '<p>paragraph</p>' . '<p>&nbsp;</p>' . '<p>&nbsp;</p>',
261 '<p>paragraph</p>' . CRLF . CRLF . CRLF,
262 ],
263 'Paragraph followed by double spacing paragraph, linebreak-separated' => [
264 '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>',
265 '<p>paragraph</p>' . CRLF . CRLF . CRLF,
266 ],
267 'Paragraph followed by spacing paragraph and by paragraph' => [
268 '<p>paragraph1</p>' . '<p>&nbsp;</p>' . '<p>paragraph2</p>',
269 '<p>paragraph1</p>' . CRLF . CRLF . '<p>paragraph2</p>',
270 ],
271 'Paragraph followed by spacing paragraph and by paragraph, linebreak-separated' => [
272 '<p>paragraph1</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>paragraph2</p>',
273 '<p>paragraph1</p>' . CRLF . CRLF . '<p>paragraph2</p>',
274 ],
275 'Paragraph followed by double spacing paragraph and by paragraph' => [
276 '<p>paragraph1</p>' . '<p>&nbsp;</p>' . '<p>&nbsp;</p>' . '<p>paragraph2</p>',
277 '<p>paragraph1</p>' . CRLF . CRLF . CRLF . '<p>paragraph2</p>',
278 ],
279 'Paragraph followed by double spacing paragraph and by paragraph, linebreak-separated' => [
280 '<p>paragraph1</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>paragraph2</p>',
281 '<p>paragraph1</p>' . CRLF . CRLF . CRLF . '<p>paragraph2</p>',
282 ],
283 'Paragraph followed by block' => [
284 '<p>paragraph</p>' . '<h1>block</h1>',
285 '<p>paragraph</p>' . CRLF . '<h1>block</h1>',
286 ],
287 'Paragraph followed by block, linebreak-separated' => [
288 '<p>paragraph</p>' . CRLF . '<h1>block</h1>',
289 '<p>paragraph</p>' . CRLF . '<h1>block</h1>',
290 ],
291 'Paragraph followed by spacing paragraph and block' => [
292 '<p>paragraph</p>' . '<p>&nbsp;</p>' . '<h1>block</h1>',
293 '<p>paragraph</p>' . CRLF . CRLF . '<h1>block</h1>',
294 ],
295 'Paragraph followed by spacing paragraph and block, linebreak-separated' => [
296 '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block</h1>',
297 '<p>paragraph</p>' . CRLF . CRLF . '<h1>block</h1>',
298 ],
299 'Paragraph followed by double spacing paragraph and block' => [
300 '<p>paragraph</p>' . '<p>&nbsp;</p>' . '<p>&nbsp;</p>' . '<h1>block</h1>',
301 '<p>paragraph</p>' . CRLF . CRLF . CRLF . '<h1>block</h1>',
302 ],
303 'Paragraph followed by double spacing paragraph and block, linebreak-separated' => [
304 '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block</h1>',
305 '<p>paragraph</p>' . CRLF . CRLF . CRLF . '<h1>block</h1>',
306 ],
307 'Block followed by block' => [
308 '<h1>block1</h1>' . '<h1>block2</h1>',
309 '<h1>block1</h1>' . CRLF . '<h1>block2</h1>',
310 ],
311 'Block followed by block, linebreak-separated' => [
312 '<h1>block1</h1>' . CRLF . '<h1>block2</h1>',
313 '<h1>block1</h1>' . CRLF . '<h1>block2</h1>',
314 ],
315 'Block followed by empty paragraph and block' => [
316 '<h1>block1</h1>' . '<p></p>' . '<h1>block2</h1>',
317 '<h1>block1</h1>' . CRLF . CRLF . '<h1>block2</h1>',
318 ],
319 'Block followed by empty paragraph aand block, linebreak-separated' => [
320 '<h1>block1</h1>' . CRLF . '<p></p>' . CRLF . '<h1>block2</h1>',
321 '<h1>block1</h1>' . CRLF . CRLF . '<h1>block2</h1>',
322 ],
323 'Block followed by spacing paragraph' => [
324 '<h1>block1</h1>' . '<p>&nbsp;</p>',
325 '<h1>block1</h1>' . CRLF . CRLF,
326 ],
327 'Block followed by spacing paragraph, linebreak-separated' => [
328 '<h1>block1</h1>' . CRLF . '<p>&nbsp;</p>',
329 '<h1>block1</h1>' . CRLF . CRLF,
330 ],
331 'Block followed by spacing paragraph and block' => [
332 '<h1>block1</h1>' . '<p>&nbsp;</p>' . '<h1>block2</h1>',
333 '<h1>block1</h1>' . CRLF . CRLF . '<h1>block2</h1>',
334 ],
335 'Block followed by spacing paragraph and block, linebreak-separated' => [
336 '<h1>block1</h1>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block2</h1>',
337 '<h1>block1</h1>' . CRLF . CRLF . '<h1>block2</h1>',
338 ],
339 'Block followed by double spacing paragraph and by block' => [
340 '<h1>block1</h1>' . '<p>&nbsp;</p>' . '<p>&nbsp;</p>' . '<h1>block2</h1>',
341 '<h1>block1</h1>' . CRLF . CRLF . CRLF . '<h1>block2</h1>',
342 ],
343 'Block followed by double spacing paragraph and by block, linebreak-separated' => [
344 '<h1>block1</h1>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block2</h1>',
345 '<h1>block1</h1>' . CRLF . CRLF . CRLF . '<h1>block2</h1>',
346 ],
347 'Block followed by paragraph and block' => [
348 '<h1>block1</h1>' . '<p>paragraph</p>' . '<h1>block2</h1>',
349 '<h1>block1</h1>' . CRLF . '<p>paragraph</p>' . CRLF . '<h1>block2</h1>',
350 ],
351 'Block followed by paragraph and block, linebreak-separated' => [
352 '<h1>block1</h1>' . CRLF . '<p>paragraph</p>' . CRLF . '<h1>block2</h1>',
353 '<h1>block1</h1>' . CRLF . '<p>paragraph</p>' . CRLF . '<h1>block2</h1>',
354 ],
355 'Block followed by paragraph, spacing paragraph and block' => [
356 '<h1>block1</h1>' . '<p>paragraph</p>' . '<p>&nbsp;</p>' . '<h1>block2</h1>',
357 '<h1>block1</h1>' . CRLF . '<p>paragraph</p>' . CRLF . CRLF . '<h1>block2</h1>',
358 ],
359 'Block followed by paragraph, spacing paragraph and block, linebreak-separated' => [
360 '<h1>block1</h1>' . CRLF . '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block2</h1>',
361 '<h1>block1</h1>' . CRLF . '<p>paragraph</p>' . CRLF . CRLF . '<h1>block2</h1>',
362 ],
363 ];
364 }
365
366 /**
367 * @test
368 * @dataProvider paragraphCorrectlyTransformedOnWayToDatabaseProvider
369 */
370 public function paragraphCorrectlyTransformedOnWayToDatabase($content, $expectedResult)
371 {
372 $subject = new RteHtmlParser();
373 $thisConfig = ['proc.' => $this->procOptions];
374 $this->assertEquals($expectedResult, $subject->RTE_transform($content, [], 'db', $thisConfig));
375 }
376
377 /**
378 * Data provider for lineBreakCorrectlyTransformedOnWayToRte
379 */
380 public static function lineBreakCorrectlyTransformedOnWayToRteProvider()
381 {
382 return [
383 'Empty string' => [
384 '',
385 '',
386 ],
387 'Single linebreak' => [
388 CRLF,
389 '<p>&nbsp;</p>',
390 ],
391 'Double linebreak' => [
392 CRLF . CRLF,
393 '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>',
394 ],
395 'Triple linebreak' => [
396 CRLF . CRLF . CRLF,
397 '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>',
398 ],
399 'Paragraph' => [
400 'paragraph',
401 '<p>paragraph</p>',
402 ],
403 'Paragraph followed by single linebreak' => [
404 'paragraph' . CRLF,
405 '<p>paragraph</p>',
406 ],
407 'Paragraph followed by double linebreak' => [
408 'paragraph' . CRLF . CRLF,
409 '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>',
410 ],
411 'Paragraph followed by triple linebreak' => [
412 'paragraph' . CRLF . CRLF . CRLF,
413 '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>',
414 ],
415 'Paragraph followed by paragraph' => [
416 'paragraph1' . CRLF . 'paragraph2',
417 '<p>paragraph1</p>' . CRLF . '<p>paragraph2</p>',
418 ],
419 'Paragraph followed by double linebreak and paragraph' => [
420 'paragraph1' . CRLF . CRLF . 'paragraph2',
421 '<p>paragraph1</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>paragraph2</p>',
422 ],
423 'Paragraph followed by triple linebreak and paragraph' => [
424 'paragraph1' . CRLF . CRLF . CRLF . 'paragraph2',
425 '<p>paragraph1</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>paragraph2</p>',
426 ],
427 'Paragraph followed by block' => [
428 'paragraph' . '<h1>block</h1>',
429 '<p>paragraph</p>' . CRLF . '<h1>block</h1>',
430 ],
431 'Paragraph followed by linebreak and block' => [
432 'paragraph' . CRLF . '<h1>block</h1>',
433 '<p>paragraph</p>' . CRLF . '<h1>block</h1>',
434 ],
435 'Paragraph followed by double linebreak and block' => [
436 'paragraph' . CRLF . CRLF . '<h1>block</h1>',
437 '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block</h1>',
438 ],
439 'Paragraph followed by triple linebreak and block' => [
440 'paragraph' . CRLF . CRLF . CRLF . '<h1>block</h1>',
441 '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block</h1>',
442 ],
443 'Block followed by block' => [
444 '<h1>block1</h1>' . '<h1>block2</h1>',
445 '<h1>block1</h1>' . CRLF . '<h1>block2</h1>',
446 ],
447 'Block followed by single linebreak and block' => [
448 '<h1>block1</h1>' . CRLF . '<h1>block2</h1>',
449 '<h1>block1</h1>' . CRLF . '<h1>block2</h1>',
450 ],
451 'Block followed by double linebreak and block' => [
452 '<h1>block1</h1>' . CRLF . CRLF . '<h1>block2</h1>',
453 '<h1>block1</h1>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block2</h1>',
454 ],
455 'Block followed by triple linebreak and block' => [
456 '<h1>block1</h1>' . CRLF . CRLF . CRLF . '<h1>block2</h1>',
457 '<h1>block1</h1>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block2</h1>',
458 ],
459 'Block followed by paragraph and block' => [
460 '<h1>block1</h1>' . CRLF . 'paragraph' . CRLF . '<h1>block2</h1>',
461 '<h1>block1</h1>' . CRLF . '<p>paragraph</p>' . CRLF . '<h1>block2</h1>',
462 ],
463 ];
464 }
465
466 /**
467 * @test
468 * @dataProvider lineBreakCorrectlyTransformedOnWayToRTEProvider
469 */
470 public function lineBreakCorrectlyTransformedOnWayToRTE($content, $expectedResult)
471 {
472 $subject = new RteHtmlParser();
473 $thisConfig = ['proc.' => $this->procOptions];
474 $this->assertEquals($expectedResult, $subject->RTE_transform($content, [], 'rte', $thisConfig));
475 }
476
477 /**
478 * Data provider for paragraphCorrectlyTransformedOnWayToDatabaseAndBackToRte
479 */
480 public static function paragraphCorrectlyTransformedOnWayToDatabaseAndBackToRteProvider()
481 {
482 return [
483 'Empty string' => [
484 '',
485 '',
486 ],
487 'Empty paragraph' => [
488 '<p></p>',
489 '<p>&nbsp;</p>',
490 ],
491 'Double empty paragraph' => [
492 '<p></p><p></p>',
493 '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>',
494 ],
495 'Triple empty paragraph' => [
496 '<p></p><p></p><p></p>',
497 '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>',
498 ],
499 'Plain text' => [
500 'plain text',
501 '<p>plain text</p>',
502 ],
503 'Plain text followed by linebreak' => [
504 'plain text' . CRLF,
505 '<p>plain text </p>',
506 ],
507 'Plain text followed by paragraph' => [
508 'plain text' . '<p>paragraph</p>',
509 '<p>plain text</p>' . CRLF . '<p>paragraph</p>',
510 ],
511 'Spacing paragraph' => [
512 '<p>&nbsp;</p>',
513 '<p>&nbsp;</p>',
514 ],
515 'Double spacing paragraph' => [
516 '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>',
517 '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>',
518 ],
519 'Paragraph' => [
520 '<p>paragraph</p>',
521 '<p>paragraph</p>',
522 ],
523 'Paragraph followed by linebreak' => [
524 '<p>paragraph</p>' . CRLF,
525 '<p>paragraph</p>',
526 ],
527 'Paragraph followed by spacing paragraph' => [
528 '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>',
529 '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>',
530 ],
531 'Paragraph followed by double spacing paragraph' => [
532 '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>',
533 '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>',
534 ],
535 'Paragraph followed by paragraph' => [
536 '<p>paragraph1</p>' . '<p>paragraph2</p>',
537 '<p>paragraph1</p>' . CRLF . '<p>paragraph2</p>',
538 ],
539 'Paragraph followed by paragraph, linebreak-separated' => [
540 '<p>paragraph1</p>' . CRLF . '<p>paragraph2</p>',
541 '<p>paragraph1</p>' . CRLF . '<p>paragraph2</p>',
542 ],
543 'Paragraph followed by spacing paragraph and by paragraph' => [
544 '<p>paragraph1</p>' . '<p>&nbsp;</p>' . '<p>paragraph2</p>',
545 '<p>paragraph1</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>paragraph2</p>',
546 ],
547 'Paragraph followed by spacing paragraph and by paragraph, linebreak-separated' => [
548 '<p>paragraph1</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>paragraph2</p>',
549 '<p>paragraph1</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>paragraph2</p>',
550 ],
551 'Paragraph followed by double spacing paragraph and by paragraph' => [
552 '<p>paragraph1</p>' . '<p>&nbsp;</p>' . '<p>&nbsp;</p>' . '<p>paragraph2</p>',
553 '<p>paragraph1</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>paragraph2</p>',
554 ],
555 'Paragraph followed by double spacing paragraph and by paragraph, linebreak-separated' => [
556 '<p>paragraph1</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>paragraph2</p>',
557 '<p>paragraph1</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>paragraph2</p>',
558 ],
559 'Paragraph followed by block' => [
560 '<p>paragraph</p>' . '<h1>block</h1>',
561 '<p>paragraph</p>' . CRLF . '<h1>block</h1>',
562 ],
563 'Paragraph followed by block, linebreak-separated' => [
564 '<p>paragraph</p>' . CRLF . '<h1>block</h1>',
565 '<p>paragraph</p>' . CRLF . '<h1>block</h1>',
566 ],
567 'Paragraph followed by spacing paragraph and by block' => [
568 '<p>paragraph</p>' . '<p>&nbsp;</p>' . '<h1>block</h1>',
569 '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block</h1>',
570 ],
571 'Paragraph followed by spacing paragraph and by block, linebreak-separated' => [
572 '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block</h1>',
573 '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block</h1>',
574 ],
575 'Paragraph followed by double spacing paragraph and by block' => [
576 '<p>paragraph</p>' . '<p>&nbsp;</p>' . '<p>&nbsp;</p>' . '<h1>block</h1>',
577 '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block</h1>',
578 ],
579 'Paragraph followed by double spacing paragraph and by block, linebreak-separated' => [
580 '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block</h1>',
581 '<p>paragraph</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block</h1>',
582 ],
583 'Block followed by block' => [
584 '<h1>block1</h1>' . '<h1>block2</h1>',
585 '<h1>block1</h1>' . CRLF . '<h1>block2</h1>',
586 ],
587 'Block followed by block, linebreak-separated' => [
588 '<h1>block1</h1>' . CRLF . '<h1>block2</h1>',
589 '<h1>block1</h1>' . CRLF . '<h1>block2</h1>',
590 ],
591 'Block followed by empty paragraph and by block' => [
592 '<h1>block1</h1>' . '<p></p>' . '<h1>block2</h1>',
593 '<h1>block1</h1>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block2</h1>',
594 ],
595 'Block followed by empty paragraph and by block, linebreak-separated' => [
596 '<h1>block1</h1>' . CRLF . '<p></p>' . CRLF . '<h1>block2</h1>',
597 '<h1>block1</h1>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block2</h1>',
598 ],
599 'Block followed by spacing paragraph and by block' => [
600 '<h1>block1</h1>' . '<p>&nbsp;</p>' . '<h1>block2</h1>',
601 '<h1>block1</h1>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block2</h1>',
602 ],
603 'Block followed by spacing paragraph and by block, linebreak-separated' => [
604 '<h1>block1</h1>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block2</h1>',
605 '<h1>block1</h1>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block2</h1>',
606 ],
607 'Block followed by double spacing paragraph and by block' => [
608 '<h1>block1</h1>' . '<p>&nbsp;</p>' . '<p>&nbsp;</p>' . '<h1>block2</h1>',
609 '<h1>block1</h1>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block2</h1>',
610 ],
611 'Block followed by double spacing paragraph and by block, linebreak-separated' => [
612 '<h1>block1</h1>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block2</h1>',
613 '<h1>block1</h1>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<p>&nbsp;</p>' . CRLF . '<h1>block2</h1>',
614 ],
615 ];
616 }
617
618 /**
619 * @test
620 * @dataProvider paragraphCorrectlyTransformedOnWayToDatabaseAndBackToRteProvider
621 */
622 public function paragraphCorrectlyTransformedOnWayToDatabaseAndBackToRte($content, $expectedResult)
623 {
624 $subject = new RteHtmlParser();
625 $thisConfig = ['proc.' => $this->procOptions];
626 $this->assertEquals($expectedResult, $subject->RTE_transform($subject->RTE_transform($content, [], 'db', $thisConfig), [], 'rte', $thisConfig));
627 }
628 }