From b6a238e6bf005face83d85fc39775df6b2f1fa81 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Mon, 20 Mar 2017 20:34:21 +0100 Subject: [PATCH] resourceloader: Add unit tests for ResourceLoaderImage Follows-up I5b14d65a and I5a563c59. Change-Id: Id42e1b868c9fe97cdb14b4bc7328947820a7fd94 --- tests/phpunit/ResourceLoaderTestCase.php | 3 +- .../oouiimagemodule/apex/icons.json | 6 ++ .../apex/images/icons/search.svg | 6 ++ .../oouiimagemodule/mediawiki/icons.json | 6 ++ .../mediawiki/images/icons/search.svg | 6 ++ .../ResourceLoaderOOUIImageModuleTest.php | 65 +++++++++++++++++++ 6 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/data/resourceloader/oouiimagemodule/apex/icons.json create mode 100644 tests/phpunit/data/resourceloader/oouiimagemodule/apex/images/icons/search.svg create mode 100644 tests/phpunit/data/resourceloader/oouiimagemodule/mediawiki/icons.json create mode 100644 tests/phpunit/data/resourceloader/oouiimagemodule/mediawiki/images/icons/search.svg create mode 100644 tests/phpunit/includes/resourceloader/ResourceLoaderOOUIImageModuleTest.php diff --git a/tests/phpunit/ResourceLoaderTestCase.php b/tests/phpunit/ResourceLoaderTestCase.php index 68b91bf3a4..a8a8f4d730 100644 --- a/tests/phpunit/ResourceLoaderTestCase.php +++ b/tests/phpunit/ResourceLoaderTestCase.php @@ -27,6 +27,7 @@ abstract class ResourceLoaderTestCase extends MediaWikiTestCase { $options += [ 'lang' => 'en', 'dir' => 'ltr', + 'skin' => 'vector', 'modules' => 'startup', 'only' => 'scripts', ]; @@ -35,7 +36,7 @@ abstract class ResourceLoaderTestCase extends MediaWikiTestCase { 'lang' => $options['lang'], 'modules' => $options['modules'], 'only' => $options['only'], - 'skin' => 'vector', + 'skin' => $options['skin'], 'target' => 'phpunit', ] ); $ctx = $this->getMockBuilder( 'ResourceLoaderContext' ) diff --git a/tests/phpunit/data/resourceloader/oouiimagemodule/apex/icons.json b/tests/phpunit/data/resourceloader/oouiimagemodule/apex/icons.json new file mode 100644 index 0000000000..4fe3d81982 --- /dev/null +++ b/tests/phpunit/data/resourceloader/oouiimagemodule/apex/icons.json @@ -0,0 +1,6 @@ +{ + "prefix": "oo-ui-icon", + "images": { + "search": { "file": "images/icons/search.svg" } + } +} diff --git a/tests/phpunit/data/resourceloader/oouiimagemodule/apex/images/icons/search.svg b/tests/phpunit/data/resourceloader/oouiimagemodule/apex/images/icons/search.svg new file mode 100644 index 0000000000..6952997131 --- /dev/null +++ b/tests/phpunit/data/resourceloader/oouiimagemodule/apex/images/icons/search.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/phpunit/data/resourceloader/oouiimagemodule/mediawiki/icons.json b/tests/phpunit/data/resourceloader/oouiimagemodule/mediawiki/icons.json new file mode 100644 index 0000000000..4fe3d81982 --- /dev/null +++ b/tests/phpunit/data/resourceloader/oouiimagemodule/mediawiki/icons.json @@ -0,0 +1,6 @@ +{ + "prefix": "oo-ui-icon", + "images": { + "search": { "file": "images/icons/search.svg" } + } +} diff --git a/tests/phpunit/data/resourceloader/oouiimagemodule/mediawiki/images/icons/search.svg b/tests/phpunit/data/resourceloader/oouiimagemodule/mediawiki/images/icons/search.svg new file mode 100644 index 0000000000..40438ea2cf --- /dev/null +++ b/tests/phpunit/data/resourceloader/oouiimagemodule/mediawiki/images/icons/search.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderOOUIImageModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderOOUIImageModuleTest.php new file mode 100644 index 0000000000..4e482c8933 --- /dev/null +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderOOUIImageModuleTest.php @@ -0,0 +1,65 @@ + 'ResourceLoaderOOUIImageModule', + 'name' => 'icons', + 'rootPath' => 'tests/phpunit/data/resourceloader/oouiimagemodule', + ] ); + + // Pretend that 'fakemonobook' is a real skin using the Apex theme + SkinFactory::getDefaultInstance()->register( + 'fakemonobook', + 'FakeMonoBook', + function () { + } + ); + $r = new ReflectionMethod( 'ExtensionRegistry', 'exportExtractedData' ); + $r->setAccessible( true ); + $r->invoke( ExtensionRegistry::getInstance(), [ + 'globals' => [], + 'defines' => [], + 'callbacks' => [], + 'credits' => [], + 'autoloaderPaths' => [], + 'attributes' => [ + 'SkinOOUIThemes' => [ + 'fakemonobook' => 'Apex', + ], + ], + ] ); + + $styles = $module->getStyles( $this->getResourceLoaderContext( [ 'skin' => 'fakemonobook' ] ) ); + $this->assertRegExp( + '/magnifying-glass-apex/', + $styles['all'], + 'Generated styles use the non-default image (embed)' + ); + $this->assertRegExp( + '/fakemonobook/', + $styles['all'], + 'Generated styles use the non-default image (link)' + ); + + $styles = $module->getStyles( $this->getResourceLoaderContext() ); + $this->assertRegExp( + '/magnifying-glass-mediawiki/', + $styles['all'], + 'Generated styles use the default image (embed)' + ); + $this->assertRegExp( + '/vector/', + $styles['all'], + 'Generated styles use the default image (link)' + ); + } + +} -- 2.20.1