summaryrefslogtreecommitdiff
path: root/www/wiki/tests/phpunit/includes/libs/HtmlArmorTest.php
diff options
context:
space:
mode:
authorYaco <franco@reevo.org>2020-06-04 11:01:00 -0300
committerYaco <franco@reevo.org>2020-06-04 11:01:00 -0300
commitfc7369835258467bf97eb64f184b93691f9a9fd5 (patch)
treedaabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/tests/phpunit/includes/libs/HtmlArmorTest.php
first commit
Diffstat (limited to 'www/wiki/tests/phpunit/includes/libs/HtmlArmorTest.php')
-rw-r--r--www/wiki/tests/phpunit/includes/libs/HtmlArmorTest.php55
1 files changed, 55 insertions, 0 deletions
diff --git a/www/wiki/tests/phpunit/includes/libs/HtmlArmorTest.php b/www/wiki/tests/phpunit/includes/libs/HtmlArmorTest.php
new file mode 100644
index 00000000..c5e87e4e
--- /dev/null
+++ b/www/wiki/tests/phpunit/includes/libs/HtmlArmorTest.php
@@ -0,0 +1,55 @@
+<?php
+
+/**
+ * @covers HtmlArmor
+ */
+class HtmlArmorTest extends PHPUnit\Framework\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 )
+ );
+ }
+}