SanitizerTest: Add tests for stripAllTags
authorRoan Kattouw <roan.kattouw@gmail.com>
Tue, 14 Nov 2017 22:16:14 +0000 (14:16 -0800)
committerRoan Kattouw <roan.kattouw@gmail.com>
Wed, 15 Nov 2017 23:16:36 +0000 (15:16 -0800)
Bug: T179978
Change-Id: I9776cfd51b1b3ec772d4216168fbe466f48f5892

tests/phpunit/includes/SanitizerTest.php

index 6fc25df..269575b 100644 (file)
@@ -512,6 +512,34 @@ class SanitizerTest extends MediaWikiTestCase {
                ];
        }
 
+       /**
+        * @dataProvider provideStripAllTags
+        *
+        * @covers Sanitizer::stripAllTags()
+        *
+        * @param string $input
+        * @param string $expected
+        */
+       public function testStripAllTags( $input, $expected ) {
+               $this->assertEquals( $expected, Sanitizer::stripAllTags( $input ) );
+       }
+
+       public function provideStripAllTags() {
+               return [
+                       [ '<p>Foo</p>', 'Foo' ],
+                       [ '<p id="one">Foo</p><p id="two">Bar</p>', 'FooBar' ],
+                       [ "<p>Foo</p>\n<p>Bar</p>", 'Foo Bar' ],
+                       [ '<p>Hello &lt;strong&gt; wor&#x6c;&#100; caf&eacute;</p>', 'Hello <strong> world cafĂ©' ],
+                       // This one is broken, see T179978
+                       //[
+                       //      '<p><small data-foo=\'bar"&lt;baz>quux\'><a href="./Foo">Bar</a></small> Whee!</p>',
+                       //      'Bar Whee!'
+                       //],
+                       [ '1<span class="<?php">2</span>3', '123' ],
+                       [ '1<span class="<?">2</span>3', '123' ],
+               ];
+       }
+
        /**
         * @expectedException InvalidArgumentException
         * @covers Sanitizer::escapeIdInternal()