build: Updating mediawiki/mediawiki-codesniffer to 16.0.0
[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 use MediaWikiCoversValidator;
9
10 public static function provideConstructor() {
11 return [
12 [ 'test' ],
13 [ null ],
14 [ '<em>some html!</em>' ]
15 ];
16 }
17
18 /**
19 * @dataProvider provideConstructor
20 */
21 public function testConstructor( $value ) {
22 $this->assertInstanceOf( HtmlArmor::class, new HtmlArmor( $value ) );
23 }
24
25 public static function provideGetHtml() {
26 return [
27 [
28 'foobar',
29 'foobar',
30 ],
31 [
32 '<script>alert("evil!");</script>',
33 '&lt;script&gt;alert(&quot;evil!&quot;);&lt;/script&gt;',
34 ],
35 [
36 new HtmlArmor( '<script>alert("evil!");</script>' ),
37 '<script>alert("evil!");</script>',
38 ],
39 [
40 new HtmlArmor( null ),
41 null,
42 ]
43 ];
44 }
45
46 /**
47 * @dataProvider provideGetHtml
48 */
49 public function testGetHtml( $input, $expected ) {
50 $this->assertEquals(
51 $expected,
52 HtmlArmor::getHtml( $input )
53 );
54 }
55 }