Merge "Fixed dependencies for jquery.collapsibleTabs"
[lhc/web/wiklou.git] / tests / phpunit / includes / SanitizerTest.php
index c929989..c593d2f 100644 (file)
@@ -2,7 +2,11 @@
 
 class SanitizerTest extends MediaWikiTestCase {
 
-       function setUp() {
+       protected function setUp() {
+               parent::setUp();
+
+               $this->setMwGlobals( 'wgCleanupPresentationalAttributes', true );
+
                AutoLoader::loadClass( 'Sanitizer' );
        }
 
@@ -110,20 +114,22 @@ class SanitizerTest extends MediaWikiTestCase {
                $this->assertEquals( Sanitizer::decodeTagAttributes( 'foo=&foobar;' ), array( 'foo' => '&foobar;' ), 'Entity-like items are accepted' );
        }
 
-       function testDeprecatedAttributesDisabled() {
-               $GLOBALS['wgCleanupPresentationalAttributes'] = false;
-               $this->assertEquals( ' clear="left"', Sanitizer::fixTagAttributes( 'clear="left"', 'br' ), 'Deprecated attributes are not converted to styles when enabled.' );
-       }
-
        /**
         * @dataProvider provideDeprecatedAttributes
         */
        function testDeprecatedAttributes( $input, $tag, $expected, $message = null ) {
-               $GLOBALS['wgCleanupPresentationalAttributes'] = true;
                $this->assertEquals( $expected, Sanitizer::fixTagAttributes( $input, $tag ), $message );
        }
 
-       function provideDeprecatedAttributes() {
+       function testDeprecatedAttributesDisabled() {
+               global $wgCleanupPresentationalAttributes;
+
+               $wgCleanupPresentationalAttributes = false;
+
+               $this->assertEquals( ' clear="left"', Sanitizer::fixTagAttributes( 'clear="left"', 'br' ), 'Deprecated attributes are not converted to styles when enabled.' );
+       }
+
+       public static function provideDeprecatedAttributes() {
                return array(
                        array( 'clear="left"', 'br', ' style="clear: left;"', 'Deprecated attributes are converted to styles when enabled.' ),
                        array( 'clear="all"', 'br', ' style="clear: both;"', 'clear=all is converted to clear: both; not clear: all;' ),
@@ -136,10 +142,26 @@ class SanitizerTest extends MediaWikiTestCase {
                        array( 'nowrap=""', 'td', ' style="white-space: nowrap;"', 'nowrap="" is considered true, not false' ),
                        array( 'NOWRAP="true"', 'td', ' style="white-space: nowrap;"', 'nowrap attribute works when uppercase.' ),
                        array( 'NoWrAp="true"', 'td', ' style="white-space: nowrap;"', 'nowrap attribute works when mixed-case.' ),
-                       array( 'align="right"', 'td', ' style="text-align: right;"', 'align on table cells gets converted to text-align' ),
-                       array( 'align="center"', 'td', ' style="text-align: center;"', 'align on table cells gets converted to text-align' ),
-                       array( 'align="left"', 'div', ' style="float: left;"', 'align=(left|right) on non-cells gets converted to float' ),
-                       array( 'align="center"', 'div', ' style="margin-left: auto; margin-right: auto;"', 'align="center" on non-cells' ),
+                       array( 'align="right"', 'td', ' style="text-align: right;"'   , 'align on table cells gets converted to text-align' ),
+                       array( 'align="center"', 'td', ' style="text-align: center;"' , 'align on table cells gets converted to text-align' ),
+                       array( 'align="left"'  , 'div', ' style="text-align: left;"'  , 'align=(left|right) on div elements gets converted to text-align' ),
+                       array( 'align="center"', 'div', ' style="text-align: center;"', 'align="center" on div elements gets converted to text-align' ),
+                       array( 'align="left"'  , 'p',   ' style="text-align: left;"'  , 'align on p elements gets converted to text-align' ),
+                       array( 'align="left"'  , 'h1',  ' style="text-align: left;"'  , 'align on h1 elements gets converted to text-align' ),
+                       array( 'align="left"'  , 'h1',  ' style="text-align: left;"'  , 'align on h1 elements gets converted to text-align' ),
+                       array( 'align="left"'  , 'caption',' style="text-align: left;"','align on caption elements gets converted to text-align' ),
+                       array( 'align="left"'  , 'tfoot',' style="text-align: left;"' , 'align on tfoot elements gets converted to text-align' ),
+                       array( 'align="left"'  , 'tbody',' style="text-align: left;"' , 'align on tbody elements gets converted to text-align' ),
+
+                       # <tr>
+                       array( 'align="right"' , 'tr', ' style="text-align: right;"' , 'align on table row get converted to text-align' ),
+                       array( 'align="center"', 'tr', ' style="text-align: center;"', 'align on table row get converted to text-align' ),
+                       array( 'align="left"'  , 'tr', ' style="text-align: left;"'  , 'align on table row get converted to text-align' ),
+
+                       #table
+                       array( 'align="left"'  , 'table', ' style="float: left;"'    , 'align on table converted to float' ),
+                       array( 'align="center"', 'table', ' style="margin-left: auto; margin-right: auto;"', 'align center on table converted to margins' ),
+                       array( 'align="right"' , 'table', ' style="float: right;"'   , 'align on table converted to float' ),
                );
        }
 
@@ -154,7 +176,7 @@ class SanitizerTest extends MediaWikiTestCase {
                );
        }
 
-       function provideCssCommentsFixtures() {
+       public static function provideCssCommentsFixtures() {
                /** array( <expected>, <css>, [message] ) */
                return array(
                        array( ' ', '/**/' ),
@@ -166,6 +188,12 @@ class SanitizerTest extends MediaWikiTestCase {
                                'Remove anything after a comment-start token' ),
                        array( '', "\\2f\\2a unifinished comment'",
                                'Remove anything after a backslash-escaped comment-start token' ),
+                       array( '/* insecure input */', 'filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'asdf.png\',sizingMethod=\'scale\');'),
+                       array( '/* insecure input */', '-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'asdf.png\',sizingMethod=\'scale\')";'),
+                       array( '/* insecure input */', 'width: expression(1+1);'),
+                       array( '/* insecure input */', 'background-image: image(asdf.png);'),
+                       array( '/* insecure input */', 'background-image: -webkit-image(asdf.png);'),
+                       array( '/* insecure input */', 'background-image: -moz-image(asdf.png);'),
                );
        }
 }