From 77f4bab8b749ed43438cc77dd6b2330ef0f99b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Fri, 17 Mar 2017 03:14:05 +0100 Subject: Allow skins/extensions to define custom OOUI themes This change follows I39cc2a735d9625c87bf4ede6f5fb0ec441d47dcc. docs/extension.schema.v1.json docs/extension.schema.v2.json includes/registration/ExtensionProcessor.php * The new extension attribute 'OOUIThemePaths' can be used to define custom OOUI themes. See I9187a63e509b601b8558ea82850fa828e5c8cc0a for an example usage. includes/resourceloader/ResourceLoaderOOUIModule.php * Add support for 'OOUIThemePaths'. * Defining 'images' is now optional. I figure custom themes are unlikely to have or need them. * Use ResourceLoaderFilePath objects to allow skin-/extension-defined OOUI module files to use skin/extension's base paths. This was previously used to support $wgResourceModuleSkinStyles, but only for 'skinStyles' - now ResourceLoaderFileModule needs to also handle it for 'skinScripts', and ResourceLoaderImageModule for 'images'). includes/resourceloader/ResourceLoaderFilePath.php * Add getters for local/remote base paths, for when we need to construct a new ResourceLoaderFilePath based on existing one. includes/resourceloader/ResourceLoaderFileModule.php includes/resourceloader/ResourceLoaderImageModule.php includes/resourceloader/ResourceLoaderOOUIImageModule.php * Add or improve handling of ResourceLoaderFilePaths: * Replace `(array)` casts with explicit array wrapping, to avoid casting objects into associative arrays. * Use getLocalPath() instead of string concatenation. tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php * Some basic checks for the above. Bug: T100896 Change-Id: I74362f0fc215b26f1f104ce7bdbbac1e106736ad --- .../ResourceLoaderImageModuleTest.php | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php') diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php index 3f5704d6f4d1..dad9f1ed4fe6 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php @@ -144,6 +144,55 @@ class ResourceLoaderImageModuleTest extends ResourceLoaderTestCase { ]; } + /** + * Test reading files from elsewhere than localBasePath using ResourceLoaderFilePath. + * + * This mimics modules modified by skins using 'ResourceModuleSkinStyles' and 'OOUIThemePaths' + * skin attributes. + * + * @covers ResourceLoaderFilePath::getLocalBasePath + * @covers ResourceLoaderFilePath::getRemoteBasePath + */ + public function testResourceLoaderFilePath() { + $basePath = __DIR__ . '/../../data/blahblah'; + $filePath = __DIR__ . '/../../data/rlfilepath'; + $testModule = new ResourceLoaderImageModule( [ + 'localBasePath' => $basePath, + 'remoteBasePath' => 'blahblah', + 'prefix' => 'foo', + 'images' => [ + 'eye' => new ResourceLoaderFilePath( 'eye.svg', $filePath, 'rlfilepath' ), + 'flag' => [ + 'file' => [ + 'ltr' => new ResourceLoaderFilePath( 'flag-ltr.svg', $filePath, 'rlfilepath' ), + 'rtl' => new ResourceLoaderFilePath( 'flag-rtl.svg', $filePath, 'rlfilepath' ), + ], + ], + ], + ] ); + $expectedModule = new ResourceLoaderImageModule( [ + 'localBasePath' => $filePath, + 'remoteBasePath' => 'rlfilepath', + 'prefix' => 'foo', + 'images' => [ + 'eye' => 'eye.svg', + 'flag' => [ + 'file' => [ + 'ltr' => 'flag-ltr.svg', + 'rtl' => 'flag-rtl.svg', + ], + ], + ], + ] ); + + $context = $this->getResourceLoaderContext(); + $this->assertEquals( + $expectedModule->getModuleContent( $context ), + $testModule->getModuleContent( $context ), + "Using ResourceLoaderFilePath works correctly" + ); + } + /** * @dataProvider providerGetModules * @covers ResourceLoaderImageModule::getStyles -- cgit v1.2.3