aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/ResourceLoader/ModuleTest.php
diff options
context:
space:
mode:
authorTim Starling <tstarling@wikimedia.org>2023-08-02 13:40:54 +1000
committerTim Starling <tstarling@wikimedia.org>2023-08-03 14:10:16 +1000
commit8a4134ed21d0e472358bf2ea1ed4e57368e3f9eb (patch)
treef78acc9efde9ddfa4f9a17ae7300571411ac20aa /tests/phpunit/includes/ResourceLoader/ModuleTest.php
parent4a27e538c30368a50d0de9f825f719202223a30e (diff)
downloadmediawikicore-8a4134ed21d0e472358bf2ea1ed4e57368e3f9eb.tar.gz
mediawikicore-8a4134ed21d0e472358bf2ea1ed4e57368e3f9eb.zip
ResourceLoader: deliver deprecation warnings as strings
It's awkward to construct a source map when the file contents is modified after loading. Delivering deprecation warnings as JS code seems like an odd convention anyway. So, send the module deprecation warning as an additional parameter to mediawiki.loader.implement(). Deprecation warnings are no longer displayed in only=scripts mode. Remove deprecation tests from FileModuleTest since FileModule no longer has any relevant deprecation code. Add tests to ModuleTest. Deprecate Module::getDeprecationInformation(). Bug: T47514 Change-Id: I20938cf4ab78afc9a2d72fbd163a7c5f21755820
Diffstat (limited to 'tests/phpunit/includes/ResourceLoader/ModuleTest.php')
-rw-r--r--tests/phpunit/includes/ResourceLoader/ModuleTest.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/phpunit/includes/ResourceLoader/ModuleTest.php b/tests/phpunit/includes/ResourceLoader/ModuleTest.php
index d057de1efe69..6f0148ae5652 100644
--- a/tests/phpunit/includes/ResourceLoader/ModuleTest.php
+++ b/tests/phpunit/includes/ResourceLoader/ModuleTest.php
@@ -304,4 +304,47 @@ class ModuleTest extends ResourceLoaderTestCase {
'Preload two resources'
);
}
+
+ public static function provideGetDeprecationWarning() {
+ return [
+ [
+ null,
+ 'normalModule',
+ null,
+ ],
+ [
+ true,
+ 'deprecatedModule',
+ 'This page is using the deprecated ResourceLoader module "deprecatedModule".',
+ ],
+ [
+ 'Will be removed tomorrow.',
+ 'deprecatedTomorrow',
+ "This page is using the deprecated ResourceLoader module \"deprecatedTomorrow\".\n" .
+ "Will be removed tomorrow.",
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider provideGetDeprecationWarning
+ *
+ * @param string|bool|null $deprecated
+ * @param string $name
+ * @param string $expected
+ */
+ public function testGetDeprecationWarning( $deprecated, $name, $expected ) {
+ $module = new ResourceLoaderTestModule( [ 'deprecated' => $deprecated ] );
+ $module->setName( $name );
+ $this->assertSame( $expected, $module->getDeprecationWarning() );
+
+ $this->hideDeprecated( 'MediaWiki\ResourceLoader\Module::getDeprecationInformation' );
+ $info = $module->getDeprecationInformation( $this->getResourceLoaderContext() );
+ if ( !$expected ) {
+ $this->assertSame( '', $info );
+ } else {
+ $this->assertSame( 'mw.log.warn(' . json_encode( $expected ) . ');', $info );
+ }
+ }
+
}