wiki.techinc.nl/tests/phpunit/unit/includes/libs/HtmlArmorTest.php
Reedy c14dd609a7 tests: Move Wikimedia tests into Wikimedia\Tests
Change-Id: I9c64a631b0b4e8e4fef8a72ee0f749d35f918052
2024-02-17 02:09:08 +00:00

61 lines
1 KiB
PHP

<?php
namespace Wikimedia\Tests;
use HtmlArmor;
use MediaWikiCoversValidator;
use PHPUnit\Framework\TestCase;
/**
* @covers \HtmlArmor
*/
class HtmlArmorTest extends TestCase {
use MediaWikiCoversValidator;
public static function provideConstructor() {
return [
[ 'test' ],
[ null ],
[ '<em>some html!</em>' ]
];
}
/**
* @dataProvider provideConstructor
*/
public function testConstructor( $value ) {
$this->assertInstanceOf( HtmlArmor::class, new HtmlArmor( $value ) );
}
public static function provideGetHtml() {
return [
[
'foobar',
'foobar',
],
[
'<script>alert("evil!");</script>',
'&lt;script&gt;alert(&quot;evil!&quot;);&lt;/script&gt;',
],
[
new HtmlArmor( '<script>alert("evil!");</script>' ),
'<script>alert("evil!");</script>',
],
[
new HtmlArmor( null ),
null,
]
];
}
/**
* @dataProvider provideGetHtml
*/
public function testGetHtml( $input, $expected ) {
$this->assertEquals(
$expected,
HtmlArmor::getHtml( $input )
);
}
}