aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php
diff options
context:
space:
mode:
authorTimo Tijhof <krinklemail@gmail.com>2018-04-10 18:29:50 +0100
committerTimo Tijhof <krinklemail@gmail.com>2018-04-10 19:44:40 +0100
commitdfb754cbc633b7b653ae94bf9d64a88d6adad7c7 (patch)
tree230ee02a77b1c81603efc88f623485afbc5c192f /tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php
parent045e6b87383bed5551bdc3d205b7813b69ea64a5 (diff)
downloadmediawikicore-dfb754cbc633b7b653ae94bf9d64a88d6adad7c7.tar.gz
mediawikicore-dfb754cbc633b7b653ae94bf9d64a88d6adad7c7.zip
resourceloader: Improve titleInfo docs and simplify title key
* Document the structure of the in-process $titleInfo cache. Specifically, specify that it is not the value from getTitleInfo(), but rather a container for zero or more versions of such values. The reason this is fragmented is because ResourceLoaderContext is a parameter to most methods and as such, makes everything variable. Tracked as T99107. * Make various bits easier to understand by consistently refering to the container keys as "batchKey", and referring to the internal keys as "titleKey". * Centralise title key logic by moving to private method. * Replace the internal creation of titleKey to be based on LinkTarget with plain namespace IDs and db keys, instead of invoking the expensive getPrefixedTitle function which involves quite a lot of overhead (TitleCodec, GenderCache, Database, Language, LocalisationCache, ..). Change-Id: I701e5156ef7815a0e36caefae5871524eff3f688
Diffstat (limited to 'tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php')
-rw-r--r--tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php19
1 files changed, 14 insertions, 5 deletions
diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php
index 0aa37d23d3a8..d4b9c1651252 100644
--- a/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php
+++ b/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php
@@ -15,6 +15,15 @@ class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase {
$this->assertInstanceOf( ResourceLoaderWikiModule::class, $module );
}
+ private function prepareTitleInfo( array $mockInfo ) {
+ $module = TestingAccessWrapper::newFromClass( ResourceLoaderWikiModule::class );
+ $info = [];
+ foreach ( $mockInfo as $key => $val ) {
+ $info[ $module->makeTitleKey( Title::newFromText( $key ) ) ] = $val;
+ }
+ return $info;
+ }
+
public static function provideConstructor() {
return [
// Nothing
@@ -102,7 +111,7 @@ class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase {
->getMock();
$module->expects( $this->any() )
->method( 'getTitleInfo' )
- ->will( $this->returnValue( $titleInfo ) );
+ ->will( $this->returnValue( $this->prepareTitleInfo( $titleInfo ) ) );
$module->expects( $this->any() )
->method( 'getGroup' )
->will( $this->returnValue( $group ) );
@@ -151,10 +160,10 @@ class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase {
'MediaWiki:Common.css' => [ 'type' => 'styles' ],
'mediawiki: fallback.css' => [ 'type' => 'styles' ],
];
- $titleInfo = [
+ $titleInfo = $this->prepareTitleInfo( [
'MediaWiki:Common.css' => [ 'page_len' => 1234 ],
'MediaWiki:Fallback.css' => [ 'page_len' => 0 ],
- ];
+ ] );
$expected = $titleInfo;
$module = $this->getMockBuilder( TestResourceLoaderWikiModule::class )
@@ -186,10 +195,10 @@ class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase {
// doing an intersect on the canonical result, producing an empty array.
'mediawiki: fallback.css' => [ 'type' => 'styles' ],
];
- $titleInfo = [
+ $titleInfo = $this->prepareTitleInfo( [
'MediaWiki:Common.css' => [ 'page_len' => 1234 ],
'MediaWiki:Fallback.css' => [ 'page_len' => 0 ],
- ];
+ ] );
$expected = $titleInfo;
$module = $this->getMockBuilder( TestResourceLoaderWikiModule::class )