overrideConfigValues( [ MainConfigNames::TextModelsToParse => [ 'sanitized-css' ], 'TemplateStylesMaxStylesheetSize' => 1024000, ] ); } public function newContent( $text ) { return new TemplateStylesContent( $text ); } public static function dataGetParserOutput() { return [ [ 'Template:Test/styles.css', 'sanitized-css', ".hello { content: 'world'; color: bogus; }\n\n\n", // phpcs:ignore Generic.Files.LineLength "
\n.hello { content: 'world'; color: bogus; }\n\n<ok>\n\n
", [ 'Warnings' => [ 'Unexpected end of stylesheet in rule at line 4 character 1.', 'Invalid or unsupported value for property color at line 1 character 35.', ] ] ], [ 'Template:Test/styles.css', 'sanitized-css', "/* hello [[world]] */\n", "
\n/* hello [[world]] */\n\n
", [ 'Links' => [ [ 'World' => 0 ] ] ] ], ]; } public static function dataPreSaveTransform() { return [ [ 'hello this is ~~~', 'hello this is ~~~', ], [ 'hello \'\'this\'\' is ~~~', 'hello \'\'this\'\' is ~~~', ], [ " Foo \n ", " Foo", ], ]; } public static function dataPreloadTransform() { return [ [ 'hello this is ~~~', 'hello this is ~~~', ], [ 'hello \'\'this\'\' is foobar', 'hello \'\'this\'\' is foobar', ], ]; } public function testGetModel() { $content = $this->newContent( 'hello world.' ); $this->assertEquals( 'sanitized-css', $content->getModel() ); } public function testGetContentHandler() { $content = $this->newContent( 'hello world.' ); $this->assertEquals( 'sanitized-css', $content->getContentHandler()->getModelID() ); } /** * Redirects aren't supported */ public static function provideUpdateRedirect() { // phpcs:disable Generic.Files.LineLength return [ [ '#REDIRECT [[Someplace]]', '#REDIRECT [[Someplace]]', ], // The style supported by CssContent [ '/* #REDIRECT */@import url(//example.org/w/index.php?title=MediaWiki:MonoBook.css&action=raw&ctype=text/css);', '/* #REDIRECT */@import url(//example.org/w/index.php?title=MediaWiki:MonoBook.css&action=raw&ctype=text/css);', ], ]; // phpcs:enable } /** * @dataProvider provideGetRedirectTarget */ public function testGetRedirectTarget( $title, $text ) { $this->overrideConfigValues( [ MainConfigNames::Server => '//example.org', MainConfigNames::ScriptPath => '/w', MainConfigNames::Script => '/w/index.php', ] ); $content = $this->newContent( $text ); $target = $content->getRedirectTarget(); $this->assertEquals( $title, $target ? $target->getPrefixedText() : null ); } public static function provideGetRedirectTarget() { // phpcs:disable Generic.Files.LineLength return [ [ null, "/* #REDIRECT */@import url(//example.org/w/index.php?title=MediaWiki:MonoBook.css&action=raw&ctype=text/css);" ], [ null, "/* #REDIRECT */@import url(//example.org/w/index.php?title=User:FooBar/common.css&action=raw&ctype=text/css);" ], [ null, "/* #REDIRECT */@import url(//example.org/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ], [ null, "@import url(//example.org/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ], [ null, "/* #REDIRECT */@import url(//example.com/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ], ]; // phpcs:enable } public static function dataEquals() { return [ [ new TemplateStylesContent( 'hallo' ), null, false ], [ new TemplateStylesContent( 'hallo' ), new TemplateStylesContent( 'hallo' ), true ], [ new TemplateStylesContent( 'hallo' ), new CssContent( 'hallo' ), false ], [ new TemplateStylesContent( 'hallo' ), new WikitextContent( 'hallo' ), false ], [ new TemplateStylesContent( 'hallo' ), new TemplateStylesContent( 'HALLO' ), false ], ]; } /** * @dataProvider dataEquals */ public function testEquals( Content $a, ?Content $b = null, $equal = false ) { $this->assertEquals( $equal, $a->equals( $b ) ); } }