1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GitHub\Tests\Phpunit; |
4
|
|
|
|
5
|
|
|
use GitHub\ContentPurifier; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers \GitHub\ContentPurifier |
10
|
|
|
*/ |
11
|
|
|
class ContentPurifierTest extends TestCase { |
12
|
|
|
|
13
|
|
|
public function testReturnsAllAllowedTags() { |
14
|
|
|
$this->assertSame( |
15
|
|
|
'<h1>my <u>test</u> <em>site</em></h1> |
16
|
|
|
<p>lorem</p> |
17
|
|
|
<ul><li>item <strong>1</strong></li> |
18
|
|
|
</ul><img src="/logo.png" alt="wikimedia" /> |
19
|
|
|
some<br /> |
20
|
|
|
thing<br /><hr /> |
21
|
|
|
new |
22
|
|
|
<table class="bobby"><tr><td>1</td></tr></table> |
23
|
|
|
dolor |
24
|
|
|
<a href="http://wikipedia.org" target="_blank" rel="noreferrer noopener">opening in new window, rel added by HtmlPurifier</a> |
25
|
|
|
amet |
26
|
|
|
<a href="http://wikimedia.de">ordinary link</a>', |
27
|
|
|
$this->newPurifier()->purify( |
28
|
|
|
'<h1>my <u>test</u> <em>site</em></h1> |
29
|
|
|
<p>lorem</p> |
30
|
|
|
<ul> |
31
|
|
|
<li>item <strong>1</strong></li> |
32
|
|
|
</ul> |
33
|
|
|
|
34
|
|
|
<img src="/logo.png" alt="wikimedia" /> |
35
|
|
|
some<br> |
36
|
|
|
thing<br/><hr /> |
37
|
|
|
new |
38
|
|
|
<table class="bobby"><tr><td>1</td></tr></table> |
39
|
|
|
dolor |
40
|
|
|
<a href="http://wikipedia.org" target="_blank">opening in new window, rel added by HtmlPurifier</a> |
41
|
|
|
amet |
42
|
|
|
<a href="http://wikimedia.de">ordinary link</a>' |
43
|
|
|
) |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
private function newPurifier(): ContentPurifier { |
48
|
|
|
return new ContentPurifier(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testStripsDisallowedTags() { |
52
|
|
|
$this->assertSame( 'invalid div', $this->newPurifier()->purify( '<div>invalid div</div>' ) ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testRepairsDamagedTags() { |
56
|
|
|
$this->assertSame( '<p>dangling paragraph</p>', $this->newPurifier()->purify( '<p>dangling paragraph' ) ); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testRemovesInvalidAttributes() { |
60
|
|
|
$this->assertSame( '<p>BIG</p>', $this->newPurifier()->purify( '<p style="font-size:100000px">BIG</p>' ) ); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|