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