[BUGFIX] Incorrect RTE transform of external URL with @ character
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Html / RteHtmlParserTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Html;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011 Stanislas Rolland <typo3@sjbr.ca>
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\RteHtmlParser
29 *
30 * @author Stanislas Rolland <typo3@sjbr.ca>
31 */
32 class RteHtmlParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
33
34 /**
35 * @var \TYPO3\CMS\Core\Html\RteHtmlParser
36 */
37 private $fixture = NULL;
38
39 public function setUp() {
40 $this->fixture = new \TYPO3\CMS\Core\Html\RteHtmlParser();
41 $this->fixture->procOptions = array(
42 'dontConvBRtoParagraph' => '1',
43 'preserveDIVSections' => '1',
44 'allowTagsOutside' => 'hr, address',
45 'overruleMode' => 'ts_css'
46 );
47 }
48
49 public function tearDown() {
50 unset($this->fixture);
51 }
52
53 /**
54 * Data provider for TS_transform_db
55 */
56 static public function hrTagCorrectlyTransformedOnWayToDataBaseDataProvider() {
57 return array(
58 'single hr' => array(
59 '<hr />',
60 '<hr />'
61 ),
62 'non-xhtml single hr' => array(
63 '<hr/>',
64 '<hr />'
65 ),
66 'double hr' => array(
67 '<hr /><hr />',
68 '<hr />' . LF . '<hr />'
69 ),
70 'linefeed followed by hr' => array(
71 LF . '<hr />',
72 '<hr />'
73 ),
74 'white space followed by hr' => array(
75 ' <hr />',
76 ' ' . LF . '<hr />'
77 ),
78 'white space followed linefeed and hr' => array(
79 ' ' . LF . '<hr />',
80 ' ' . LF . '<hr />'
81 ),
82 'br followed by hr' => array(
83 '<br /><hr />',
84 '<br />' . LF . '<hr />'
85 ),
86 'br followed by linefeed and hr' => array(
87 '<br />' . LF . '<hr />',
88 '<br />' . LF . '<hr />'
89 ),
90 'preserved div followed by hr' => array(
91 '<div>Some text</div><hr />',
92 '<div>Some text</div>' . LF . '<hr />'
93 ),
94 'preserved div followed by linefeed and hr' => array(
95 '<div>Some text</div>' . LF . '<hr />',
96 '<div>Some text</div>' . LF . '<hr />'
97 ),
98 'h1 followed by linefeed and hr' => array(
99 '<h1>Some text</h1>' . LF . '<hr />',
100 '<h1>Some text</h1>' . LF . '<hr />'
101 ),
102 'paragraph followed by linefeed and hr' => array(
103 '<p>Some text</p>' . LF . '<hr />',
104 'Some text' . LF . '<hr />'
105 ),
106 'some text followed by hr' => array(
107 'Some text<hr />',
108 'Some text' . LF . '<hr />'
109 ),
110 'some text followed by linefeed and hr' => array(
111 'Some text' . LF . '<hr />',
112 'Some text' . LF . '<hr />'
113 )
114 );
115 }
116
117 /**
118 * @test
119 * @dataProvider hrTagCorrectlyTransformedOnWayToDataBaseDataProvider
120 */
121 public function hrTagCorrectlyTransformedOnWayToDataBase($content, $expectedResult) {
122 // Assume the transformation is ts_css
123 $this->assertEquals($expectedResult, $this->fixture->TS_transform_db($content, TRUE));
124 }
125
126 /**
127 * Data provider for linkWithAtSignCorrectlyTransformedOnWayToRTE
128 */
129 public static function linkWithAtSignCorrectlyTransformedOnWayToRTEProvider() {
130 return array(
131 'external url with @ sign' => array(
132 '<link http://www.example.org/at@sign>link text</link>',
133 '<p><a href="http://www.example.org/at@sign" data-htmlarea-external="1">link text</a></p>'
134 ),
135 'email address with @ sign' => array(
136 '<link name@example.org - mail "Opens window for sending email">link text</link>',
137 '<p><a href="mailto:name@example.org" class="mail" title="Opens window for sending email">link text</a></p>'
138 )
139 );
140 }
141
142 /**
143 * @test
144 * @dataProvider linkWithAtSignCorrectlyTransformedOnWayToRTEProvider
145 */
146 public function linkWithAtSignCorrectlyTransformedOnWayToRTE($content, $expectedResult) {
147 $thisConfig = array('proc.' => $this->fixture->procOptions);
148 $this->assertEquals($expectedResult, $this->fixture->RTE_transform($content, array(), 'rte', $thisConfig));
149 }
150 }
151 ?>