wiki.techinc.nl/tests/phpunit/includes/content/JavaScriptContentHandlerTest.php
Kunal Mehta 674e486cb5 Recognize CSS/JS redirects with non-ASCII targets
The regex in JavaScriptContent and CssContent was trying to pass
urlencoded stuff to Title::newFromText(), which would fail. Make sure we
urldecode it first.

Bug: T208264
Change-Id: I189c4c308da2875839ad8c1061332500f0e6d244
2018-10-31 23:09:50 -07:00

45 lines
1.5 KiB
PHP

<?php
class JavaScriptContentHandlerTest extends MediaWikiLangTestCase {
/**
* @dataProvider provideMakeRedirectContent
* @covers JavaScriptContentHandler::makeRedirectContent
*/
public function testMakeRedirectContent( $title, $expected ) {
$this->setMwGlobals( [
'wgServer' => '//example.org',
'wgScript' => '/w/index.php',
] );
$ch = new JavaScriptContentHandler();
$content = $ch->makeRedirectContent( Title::newFromText( $title ) );
$this->assertInstanceOf( JavaScriptContent::class, $content );
$this->assertEquals( $expected, $content->serialize( CONTENT_FORMAT_JAVASCRIPT ) );
}
/**
* Keep this in sync with JavaScriptContentTest::provideGetRedirectTarget()
*/
public static function provideMakeRedirectContent() {
// phpcs:disable Generic.Files.LineLength
return [
[
'MediaWiki:MonoBook.js',
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=MediaWiki:MonoBook.js\u0026action=raw\u0026ctype=text/javascript");'
],
[
'User:FooBar/common.js',
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=User:FooBar/common.js\u0026action=raw\u0026ctype=text/javascript");'
],
[
'Gadget:FooBaz.js',
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=Gadget:FooBaz.js\u0026action=raw\u0026ctype=text/javascript");'
],
[
'User:😂/unicode.js',
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=User:%F0%9F%98%82/unicode.js\u0026action=raw\u0026ctype=text/javascript");'
],
];
// phpcs:enable
}
}