1 | <?php |
||
6 | use SilverStripe\Dev\SapphireTest; |
||
7 | |||
8 | /** |
||
9 | * @package framework |
||
10 | * @subpackage tests |
||
11 | */ |
||
12 | class HTML5ValueTest extends SapphireTest |
||
13 | { |
||
14 | public function testInvalidHTMLParsing() |
||
15 | { |
||
16 | $value = new HTML5Value(); |
||
17 | |||
18 | $invalid = [ |
||
19 | '<p>Enclosed Value</p></p>' => '<p>Enclosed Value</p><p></p>', |
||
20 | '<meta content="text/html"></meta>' => '<meta content="text/html">', |
||
21 | '<p><div class="example"></div></p>' => '<p></p><div class="example"></div><p></p>' |
||
22 | ]; |
||
23 | |||
24 | foreach ($invalid as $input => $expected) { |
||
25 | $value->setContent($input); |
||
26 | $this->assertEquals($expected, $value->getContent(), 'Invalid HTML can be parsed'); |
||
27 | } |
||
28 | } |
||
29 | |||
30 | public function testUtf8Saving() |
||
31 | { |
||
32 | $value = new HTML5Value(); |
||
33 | |||
34 | $value->setContent('<p>ö ß ā い 家</p>'); |
||
35 | $this->assertEquals('<p>ö ß ā い 家</p>', $value->getContent()); |
||
36 | } |
||
37 | |||
38 | public function testWhitespaceHandling() |
||
39 | { |
||
40 | $value = new HTML5Value(); |
||
41 | |||
42 | $value->setContent('<p></p> <p></p>'); |
||
43 | $this->assertEquals('<p></p> <p></p>', $value->getContent()); |
||
44 | } |
||
45 | |||
46 | public function testInvalidHTMLTagNames() |
||
62 | ); |
||
63 | } |
||
64 | } |
||
65 | |||
66 | public function testMixedNewlines() |
||
67 | { |
||
68 | $value = new HTML5Value(); |
||
69 | |||
70 | $value->setContent("<p>paragraph</p>\n<ul><li>1</li>\r\n</ul>"); |
||
71 | $this->assertEquals( |
||
72 | "<p>paragraph</p>\n<ul><li>1</li>\n</ul>", |
||
78 |