Merge "Changed quoting function for oracleDB."
[lhc/web/wiklou.git] / tests / phpunit / includes / SanitizerTest.php
index f5aacab..38c15ee 100644 (file)
@@ -71,8 +71,6 @@ class SanitizerTest extends MediaWikiTestCase {
         */
        function testRemovehtmltagsOnHtml5Tags( $tag, $escaped ) {
                $this->setMwGlobals( array(
-                       # Enable HTML5 mode
-                       'wgHtml5' => true,
                        'wgUseTidy' => false
                ) );
 
@@ -101,18 +99,43 @@ class SanitizerTest extends MediaWikiTestCase {
                );
        }
 
-       function testSelfClosingTag() {
-               $this->setMwGlobals( array(
-                       'wgUseTidy' => false
-               ) );
-
-               $this->assertEquals(
-                       '<div>Hello world</div>',
-                       Sanitizer::removeHTMLtags( '<div>Hello world</div />' ),
-                       'Self-closing closing div'
+       function dataRemoveHTMLtags() {
+               return array(
+                       // former testSelfClosingTag
+                       array(
+                               '<div>Hello world</div />',
+                               '<div>Hello world</div>',
+                               'Self-closing closing div'
+                       ),
+                       // Make sure special nested HTML5 semantics are not broken
+                       // http://www.whatwg.org/html/text-level-semantics.html#the-kbd-element
+                       array(
+                               '<kbd><kbd>Shift</kbd>+<kbd>F3</kbd></kbd>',
+                               '<kbd><kbd>Shift</kbd>+<kbd>F3</kbd></kbd>',
+                               'Nested <kbd>.'
+                       ),
+                       // http://www.whatwg.org/html/text-level-semantics.html#the-sub-and-sup-elements
+                       array(
+                               '<var>x<sub><var>i</var></sub></var>, <var>y<sub><var>i</var></sub></var>',
+                               '<var>x<sub><var>i</var></sub></var>, <var>y<sub><var>i</var></sub></var>',
+                               'Nested <var>.'
+                       ),
+                       // http://www.whatwg.org/html/text-level-semantics.html#the-dfn-element
+                       array(
+                               '<dfn><abbr title="Garage Door Opener">GDO</abbr></dfn>',
+                               '<dfn><abbr title="Garage Door Opener">GDO</abbr></dfn>',
+                               '<abbr> inside <dfn>',
+                       ),
                );
        }
 
+       /**
+        * @dataProvider dataRemoveHTMLtags
+        */
+       function testRemoveHTMLtags( $input, $output, $msg = null ) {
+               $GLOBALS['wgUseTidy'] = false;
+               $this->assertEquals( $output, Sanitizer::removeHTMLtags( $input ), $msg );
+       }
 
        /**
         * @dataProvider provideTagAttributesToDecode
@@ -148,7 +171,6 @@ class SanitizerTest extends MediaWikiTestCase {
                        array( array( 'foo.' => 'baz' ), 'foo.=baz', 'A . is allowed as last character' ),
                        array( array( 'foo6' => 'baz' ), 'foo6=baz', 'Numbers are allowed' ),
 
-
                        # This bit is more relaxed than XML rules, but some extensions use
                        # it, like ProofreadPage (see bug 27539)
                        array( array( '1foo' => 'baz' ), '1foo=baz', 'Leading numbers are allowed' ),
@@ -205,10 +227,14 @@ class SanitizerTest extends MediaWikiTestCase {
        public static function provideCssCommentsFixtures() {
                /** array( <expected>, <css>, [message] ) */
                return array(
-                       array( ' ', '/**/' ),
+                       // Valid comments spanning entire input
+                       array( '/**/', '/**/' ),
+                       array( '/* comment */', '/* comment */' ),
+                       // Weird stuff
                        array( ' ', '/****/' ),
-                       array( ' ', '/* comment */' ),
-                       array( ' ', "\\2f\\2a foo \\2a\\2f",
+                       array( ' ', '/* /* */' ),
+                       array( 'display: block;', "display:/* foo */block;" ),
+                       array( 'display: block;', "display:\\2f\\2a foo \\2a\\2f block;",
                                'Backslash-escaped comments must be stripped (bug 28450)' ),
                        array( '', '/* unfinished comment structure',
                                'Remove anything after a comment-start token' ),
@@ -246,5 +272,4 @@ class SanitizerTest extends MediaWikiTestCase {
                        $message
                );
        }
-
 }