Debian Codegraph @

tests/phpunit/unit/includes/libs/HtmlArmorTest.php

raw symbols SCIP
1 <?php
2
3 namespace Wikimedia\Tests;
4
5 use HtmlArmor;
6 use MediaWikiCoversValidator;
7 use PHPUnit\Framework\TestCase;
8
9 /**
10 * @covers \HtmlArmor
11 */
12 class HtmlArmorTest extends TestCase {
13
14 use MediaWikiCoversValidator;
15
16 public static function provideConstructor() {
17 return [
18 [ 'test' ],
19 [ null ],
20 [ '<em>some html!</em>' ]
21 ];
22 }
23
24 /**
25 * @dataProvider provideConstructor
26 */
27 public function testConstructor( $value ) {
28 $this->assertInstanceOf( HtmlArmor::class, new HtmlArmor( $value ) );
29 }
30
31 public static function provideGetHtml() {
32 return [
33 [
34 'foobar',
35 'foobar',
36 ],
37 [
38 '<script>alert("evil!");</script>',
39 '&lt;script&gt;alert(&quot;evil!&quot;);&lt;/script&gt;',
40 ],
41 [
42 new HtmlArmor( '<script>alert("evil!");</script>' ),
43 '<script>alert("evil!");</script>',
44 ],
45 [
46 new HtmlArmor( null ),
47 null,
48 ]
49 ];
50 }
51
52 /**
53 * @dataProvider provideGetHtml
54 */
55 public function testGetHtml( $input, $expected ) {
56 $this->assertEquals(
57 $expected,
58 HtmlArmor::getHtml( $input )
59 );
60 }
61 }