1<?php
2
3class JavaScriptContentHandlerTest extends MediaWikiLangTestCase {
4
5	/**
6	 * @dataProvider provideMakeRedirectContent
7	 * @covers JavaScriptContentHandler::makeRedirectContent
8	 */
9	public function testMakeRedirectContent( $title, $expected ) {
10		$this->setMwGlobals( [
11			'wgServer' => '//example.org',
12			'wgScript' => '/w/index.php',
13		] );
14		$ch = new JavaScriptContentHandler();
15		$content = $ch->makeRedirectContent( Title::newFromText( $title ) );
16		$this->assertInstanceOf( JavaScriptContent::class, $content );
17		$this->assertEquals( $expected, $content->serialize( CONTENT_FORMAT_JAVASCRIPT ) );
18	}
19
20	/**
21	 * Keep this in sync with JavaScriptContentTest::provideGetRedirectTarget()
22	 */
23	public static function provideMakeRedirectContent() {
24		// phpcs:disable Generic.Files.LineLength
25		return [
26			[
27				'MediaWiki:MonoBook.js',
28				'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=MediaWiki:MonoBook.js\u0026action=raw\u0026ctype=text/javascript");'
29			],
30			[
31				'User:FooBar/common.js',
32				'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=User:FooBar/common.js\u0026action=raw\u0026ctype=text/javascript");'
33			],
34			[
35				'Gadget:FooBaz.js',
36				'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=Gadget:FooBaz.js\u0026action=raw\u0026ctype=text/javascript");'
37			],
38			[
39				'User:��/unicode.js',
40				'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=User:%F0%9F%98%82/unicode.js\u0026action=raw\u0026ctype=text/javascript");'
41			],
42		];
43		// phpcs:enable
44	}
45}
46