3 use MediaWiki\Content\JavaScriptContent
;
4 use MediaWiki\Content\JavaScriptContentHandler
;
5 use MediaWiki\MainConfigNames
;
6 use MediaWiki\Title\Title
;
9 * @covers \MediaWiki\Content\JavaScriptContentHandler
11 class JavaScriptContentHandlerTest
extends MediaWikiLangTestCase
{
14 * @dataProvider provideMakeRedirectContent
16 public function testMakeRedirectContent( $title, $expected ) {
17 $this->overrideConfigValues( [
18 MainConfigNames
::Server
=> '//example.org',
19 MainConfigNames
::Script
=> '/w/index.php',
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
) );
28 * This is re-used by JavaScriptContentTest to assert roundtrip
30 public static function provideMakeRedirectContent() {
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");'
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");'
42 '/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=Gadget:FooBaz.js&action=raw&ctype=text/javascript");'
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");'
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");'