Merge "Add tests for WikiMap and WikiReference"
[lhc/web/wiklou.git] / tests / phpunit / includes / SanitizerTest.php
index f960f48..d3dc512 100644 (file)
@@ -6,6 +6,11 @@
  */
 class SanitizerTest extends MediaWikiTestCase {
 
+       protected function tearDown() {
+               MWTidy::destroySingleton();
+               parent::tearDown();
+       }
+
        /**
         * @covers Sanitizer::decodeCharReferences
         */
@@ -79,7 +84,7 @@ class SanitizerTest extends MediaWikiTestCase {
         */
        public function testInvalidNumberedEntities() {
                $this->assertEquals(
-                       UTF8_REPLACEMENT,
+                       UtfNormal\Constants::UTF8_REPLACEMENT,
                        Sanitizer::decodeCharReferences( "�" ),
                        'Invalid numbered entity'
                );
@@ -93,9 +98,7 @@ class SanitizerTest extends MediaWikiTestCase {
         * @param bool $escaped Whether sanitizer let the tag in or escape it (ie: '<video>')
         */
        public function testRemovehtmltagsOnHtml5Tags( $tag, $escaped ) {
-               $this->setMwGlobals( array(
-                       'wgUseTidy' => false
-               ) );
+               MWTidy::setInstance( false );
 
                if ( $escaped ) {
                        $this->assertEquals( "<$tag>",
@@ -157,7 +160,7 @@ class SanitizerTest extends MediaWikiTestCase {
         * @covers Sanitizer::removeHTMLtags
         */
        public function testRemoveHTMLtags( $input, $output, $msg = null ) {
-               $GLOBALS['wgUseTidy'] = false;
+               MWTidy::setInstance( false );
                $this->assertEquals( $output, Sanitizer::removeHTMLtags( $input ), $msg );
        }
 
@@ -340,4 +343,24 @@ class SanitizerTest extends MediaWikiTestCase {
                        $message
                );
        }
+
+       /**
+        * @dataProvider provideEscapeHtmlAllowEntities
+        * @covers Sanitizer::escapeHtmlAllowEntities
+        */
+       public function testEscapeHtmlAllowEntities( $expected, $html ) {
+               $this->assertEquals(
+                       $expected,
+                       Sanitizer::escapeHtmlAllowEntities( $html )
+               );
+       }
+
+       public static function provideEscapeHtmlAllowEntities() {
+               return array(
+                       array( 'foo', 'foo' ),
+                       array( 'a¡b', 'a¡b' ),
+                       array( 'foo'bar', "foo'bar" ),
+                       array( '&lt;script&gt;foo&lt;/script&gt;', '<script>foo</script>' ),
+               );
+       }
 }