| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Content\JavaScriptContent; |
| 4 |
use MediaWiki\Content\JavaScriptContentHandler; |
| 5 |
use MediaWiki\MainConfigNames; |
| 6 |
use MediaWiki\Title\Title; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
class JavaScriptContentHandlerTest extends MediaWikiLangTestCase { |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
public function testMakeRedirectContent( $title, $expected ) { |
| 17 |
$this->overrideConfigValues( [ |
| 18 |
MainConfigNames::Server => '//example.org', |
| 19 |
MainConfigNames::Script => '/w/index.php', |
| 20 |
] ); |
| 21 |
$ch = new JavaScriptContentHandler(); |
| 22 |
$content = $ch->makeRedirectContent( Title::newFromText( $title ) ); |
| 23 |
$this->assertInstanceOf( JavaScriptContent::class, $content ); |
| 24 |
$this->assertEquals( $expected, $content->serialize( CONTENT_FORMAT_JAVASCRIPT ) ); |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public static function provideMakeRedirectContent() { |
| 31 |
return [ |
| 32 |
'MediaWiki namespace page' => [ |
| 33 |
'MediaWiki:MonoBook.js', |
| 34 |
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=MediaWiki:MonoBook.js&action=raw&ctype=text/javascript");' |
| 35 |
], |
| 36 |
'User subpage' => [ |
| 37 |
'User:FooBar/common.js', |
| 38 |
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=User:FooBar/common.js&action=raw&ctype=text/javascript");' |
| 39 |
], |
| 40 |
'Gadget page' => [ |
| 41 |
'Gadget:FooBaz.js', |
| 42 |
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=Gadget:FooBaz.js&action=raw&ctype=text/javascript");' |
| 43 |
], |
| 44 |
'Unicode basename' => [ |
| 45 |
'User:😂/unicode.js', |
| 46 |
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=User:%F0%9F%98%82/unicode.js&action=raw&ctype=text/javascript");' |
| 47 |
], |
| 48 |
'Ampersand basename' => [ |
| 49 |
'User:Penn & Teller/ampersand.js', |
| 50 |
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=User:Penn_%26_Teller/ampersand.js&action=raw&ctype=text/javascript");' |
| 51 |
], |
| 52 |
]; |
| 53 |
} |
| 54 |
} |