1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package framework |
4
|
|
|
* @subpackage tests |
5
|
|
|
*/ |
6
|
|
|
class SS_HTML5ValueTest extends SapphireTest |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
public function testInvalidHTMLParsing() |
9
|
|
|
{ |
10
|
|
|
$value = new SS_HTML5Value(); |
11
|
|
|
|
12
|
|
|
$invalid = array( |
13
|
|
|
'<p>Enclosed Value</p></p>' => '<p>Enclosed Value</p><p></p>', |
14
|
|
|
'<meta content="text/html"></meta>' => '<meta content="text/html">', |
15
|
|
|
'<p><div class="example"></div></p>' => '<p></p><div class="example"></div><p></p>' |
16
|
|
|
); |
17
|
|
|
|
18
|
|
|
foreach ($invalid as $input => $expected) { |
19
|
|
|
$value->setContent($input); |
20
|
|
|
$this->assertEquals($expected, $value->getContent(), 'Invalid HTML can be parsed'); |
|
|
|
|
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testUtf8Saving() |
25
|
|
|
{ |
26
|
|
|
$value = new SS_HTML5Value(); |
27
|
|
|
|
28
|
|
|
$value->setContent('<p>ö ß ā い 家</p>'); |
29
|
|
|
$this->assertEquals('<p>ö ß ā い 家</p>', $value->getContent()); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testWhitespaceHandling() |
33
|
|
|
{ |
34
|
|
|
$value = new SS_HTML5Value(); |
35
|
|
|
|
36
|
|
|
$value->setContent('<p></p> <p></p>'); |
37
|
|
|
$this->assertEquals('<p></p> <p></p>', $value->getContent()); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testInvalidHTMLTagNames() |
41
|
|
|
{ |
42
|
|
|
$value = new SS_HTML5Value(); |
43
|
|
|
|
44
|
|
|
$invalid = array( |
45
|
|
|
'<p><div><a href="test-link"></p></div>', |
46
|
|
|
'<html><div><a href="test-link"></a></a></html_>' |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
foreach ($invalid as $input) { |
50
|
|
|
$value->setContent($input); |
51
|
|
|
|
52
|
|
|
$this->assertEquals( |
|
|
|
|
53
|
|
|
'test-link', |
54
|
|
|
$value->getElementsByTagName('a')->item(0)->getAttribute('href'), |
|
|
|
|
55
|
|
|
'Link data can be extraced from malformed HTML' |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testMixedNewlines() |
61
|
|
|
{ |
62
|
|
|
$value = new SS_HTML5Value(); |
63
|
|
|
|
64
|
|
|
$value->setContent("<p>paragraph</p>\n<ul><li>1</li>\r\n</ul>"); |
65
|
|
|
$this->assertEquals( |
|
|
|
|
66
|
|
|
"<p>paragraph</p>\n<ul><li>1</li>\n</ul>", |
67
|
|
|
$value->getContent(), |
68
|
|
|
'Newlines get converted' |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.