wiki.techinc.nl/tests/phpunit/includes/content/JavaScriptContentHandlerTest.php
Ebrahim Byagowi ccde5085de Add namespace and deprecation alias to JavaScriptContent
This patch introduces a namespace declaration for the
MediaWiki\Content to JavaScriptContent and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I87c17327911e28a461feaf2ff46242454cff257a
2024-05-17 13:51:18 +03:30

52 lines
1.7 KiB
PHP

<?php
use MediaWiki\Content\JavaScriptContent;
use MediaWiki\MainConfigNames;
use MediaWiki\Title\Title;
class JavaScriptContentHandlerTest extends MediaWikiLangTestCase {
/**
* @dataProvider provideMakeRedirectContent
* @covers \JavaScriptContentHandler::makeRedirectContent
*/
public function testMakeRedirectContent( $title, $expected ) {
$this->overrideConfigValues( [
MainConfigNames::Server => '//example.org',
MainConfigNames::Script => '/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() {
return [
[
'MediaWiki:MonoBook.js',
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=MediaWiki:MonoBook.js&action=raw&ctype=text/javascript");'
],
[
'User:FooBar/common.js',
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=User:FooBar/common.js&action=raw&ctype=text/javascript");'
],
[
'Gadget:FooBaz.js',
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=Gadget:FooBaz.js&action=raw&ctype=text/javascript");'
],
[
'User:😂/unicode.js',
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=User:%F0%9F%98%82/unicode.js&action=raw&ctype=text/javascript");'
],
[
'User:A&B/ampersand.js',
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=User:A%26B/ampersand.js&action=raw&ctype=text/javascript");'
],
];
// phpcs:enable
}
}