0e9469ad048915597ce5862dcef1e28715a2b0fe
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / HtmlArmorTest.php
1 <?php
2
3 /**
4 * @covers HtmlArmor
5 */
6 class HtmlArmorTest extends PHPUnit_Framework_TestCase {
7
8 public static function provideConstructor() {
9 return [
10 [ 'test' ],
11 [ null ],
12 [ '<em>some html!</em>' ]
13 ];
14 }
15
16 /**
17 * @dataProvider provideConstructor
18 */
19 public function testConstructor( $value ) {
20 $this->assertInstanceOf( HtmlArmor::class, new HtmlArmor( $value ) );
21 }
22
23 public static function provideGetHtml() {
24 return [
25 [
26 'foobar',
27 'foobar',
28 ],
29 [
30 '<script>alert("evil!");</script>',
31 '&lt;script&gt;alert(&quot;evil!&quot;);&lt;/script&gt;',
32 ],
33 [
34 new HtmlArmor( '<script>alert("evil!");</script>' ),
35 '<script>alert("evil!");</script>',
36 ],
37 [
38 new HtmlArmor( null ),
39 null,
40 ]
41 ];
42 }
43
44 /**
45 * @dataProvider provideGetHtml
46 */
47 public function testGetHtml( $input, $expected ) {
48 $this->assertEquals(
49 $expected,
50 HtmlArmor::getHtml( $input )
51 );
52 }
53 }