aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php
diff options
context:
space:
mode:
authorTimo Tijhof <krinklemail@gmail.com>2015-09-23 02:35:38 +0100
committerOri.livneh <ori@wikimedia.org>2015-09-30 00:25:27 +0000
commit047b60b96d8218eec5122dbca38e367773267d4b (patch)
tree1b47a74d435512e1e7523fafa32f6e8dabc672df /tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php
parent2910861d05b397aa1f5f2aa9ba05fefc015ee95d (diff)
downloadmediawikicore-047b60b96d8218eec5122dbca38e367773267d4b.tar.gz
mediawikicore-047b60b96d8218eec5122dbca38e367773267d4b.zip
resourceloader: Store relative instead of absolute paths in module_deps
Make paths stored in the module_deps table relative to $IP. This ensures that when the MediaWiki install path changes and/or if the location of the extension or skins directory changes, that ResourceLoader's internal model is still accurate. Previously when these paths change, ResourceLoader would exhibit various bugs. 1. Unable to detect changes in the module (if the directory no longer exists). 2. Point #1 is usually preceeded by one last cache invalidation as the content hash of the file path changes (from a valid hash to an empty string). 3. Unnecessary cache invalidation (if both old and new directories exist). This happens when a file is both an entry point (in the 'scripts' or 'styles' array) and also a file dependency. At first they are de-duplicated by array_unique. But after the disk path changes, the next check will result in the old path being fetched from module_deps, and the new path from the live configuration. This causes two changes that result in needless cache invalidation: - The hash list contains one more item (T111481). - The hash list contains both the old and new version of a file. (or even alternate versions, e.g. when a change is backported to the old wmf branch; it also affects wikis on the new branch due to the stale file path still in the database). It seems unusual to move a MediaWiki install, and usually we recommend third parties to run update.php if site administrators do move their wiki. However Wikimedia's deployment system implicitly moves the MediaWiki install continously from e.g. "/srv/mediawiki/php-1.26wmf5" to "/srv/mediawiki/php-1.26wmf6". This caused virtually all ResourceLoader caching layers to get invalidated every week when another wmf-branch is deployed, thus breaking these file paths, which changes the version hash, which then invalidates the cache. Bug: T111481 Change-Id: I173a9820b3067c4a6598a4c8d77e239797d2659c
Diffstat (limited to 'tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php')
-rw-r--r--tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php
index e8ca2a3042fc..145698cfeb8b 100644
--- a/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php
+++ b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php
@@ -91,4 +91,41 @@ class ResourceLoaderModuleTest extends ResourceLoaderTestCase {
'Leave valid scripts as-is'
);
}
+
+ /**
+ * @covers ResourceLoaderModule::getRelativePaths
+ * @covers ResourceLoaderModule::expandRelativePaths
+ */
+ public function testPlaceholderize() {
+ $getRelativePaths = new ReflectionMethod( 'ResourceLoaderModule', 'getRelativePaths' );
+ $getRelativePaths->setAccessible( true );
+ $expandRelativePaths = new ReflectionMethod( 'ResourceLoaderModule', 'expandRelativePaths' );
+ $expandRelativePaths->setAccessible( true );
+
+ $this->setMwGlobals( array(
+ 'IP' => '/srv/example/mediawiki/core',
+ ) );
+ $raw = array(
+ '/srv/example/mediawiki/core/resources/foo.js',
+ '/srv/example/mediawiki/core/extensions/Example/modules/bar.js',
+ '/srv/example/mediawiki/skins/Example/baz.css',
+ '/srv/example/mediawiki/skins/Example/images/quux.png',
+ );
+ $canonical = array(
+ 'resources/foo.js',
+ 'extensions/Example/modules/bar.js',
+ '../skins/Example/baz.css',
+ '../skins/Example/images/quux.png',
+ );
+ $this->assertEquals(
+ $getRelativePaths->invoke( null, $raw ),
+ $canonical,
+ 'Insert placeholders'
+ );
+ $this->assertEquals(
+ $expandRelativePaths->invoke( null, $canonical ),
+ $raw,
+ 'Substitute placeholders'
+ );
+ }
}