From faf4cb33846978c32e6157682a8b06dd00faf3b1 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 1 Nov 2023 00:44:47 +0000 Subject: content: Improve roundtrip tests for JavaScriptContent * Re-use the same data provider explicitly instead of manually keeping them in sync. * Add test case names as array keys to improve debugging. * Widen `@covers` annotations in unit tests. Bug: T107289 Change-Id: I9a321400855ddd1f56334f6ecf85590fd8ed4aaf --- .../content/JavaScriptContentHandlerTest.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'tests/phpunit/includes/content/JavaScriptContentHandlerTest.php') diff --git a/tests/phpunit/includes/content/JavaScriptContentHandlerTest.php b/tests/phpunit/includes/content/JavaScriptContentHandlerTest.php index 7e257da65291..a71b08f28b95 100644 --- a/tests/phpunit/includes/content/JavaScriptContentHandlerTest.php +++ b/tests/phpunit/includes/content/JavaScriptContentHandlerTest.php @@ -5,11 +5,13 @@ use MediaWiki\Content\JavaScriptContentHandler; use MediaWiki\MainConfigNames; use MediaWiki\Title\Title; +/** + * @covers \JavaScriptContentHandler + */ class JavaScriptContentHandlerTest extends MediaWikiLangTestCase { /** * @dataProvider provideMakeRedirectContent - * @covers \MediaWiki\Content\JavaScriptContentHandler::makeRedirectContent */ public function testMakeRedirectContent( $title, $expected ) { $this->overrideConfigValues( [ @@ -23,31 +25,30 @@ class JavaScriptContentHandlerTest extends MediaWikiLangTestCase { } /** - * Keep this in sync with JavaScriptContentTest::provideGetRedirectTarget() + * This is re-used by JavaScriptContentTest to assert roundtrip */ public static function provideMakeRedirectContent() { return [ - [ + 'MediaWiki namespace page' => [ 'MediaWiki:MonoBook.js', '/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=MediaWiki:MonoBook.js&action=raw&ctype=text/javascript");' ], - [ + 'User subpage' => [ 'User:FooBar/common.js', '/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=User:FooBar/common.js&action=raw&ctype=text/javascript");' ], - [ + 'Gadget page' => [ 'Gadget:FooBaz.js', '/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=Gadget:FooBaz.js&action=raw&ctype=text/javascript");' ], - [ + 'Unicode basename' => [ '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");' + 'Ampersand basename' => [ + 'User:Penn & Teller/ampersand.js', + '/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=User:Penn_%26_Teller/ampersand.js&action=raw&ctype=text/javascript");' ], ]; - // phpcs:enable } } -- cgit v1.2.3