resourceloader: Add unit tests for ResourceLoaderImage
authorBartosz Dziewoński <matma.rex@gmail.com>
Mon, 20 Mar 2017 19:34:21 +0000 (20:34 +0100)
committerKrinkle <krinklemail@gmail.com>
Tue, 11 Apr 2017 21:55:59 +0000 (21:55 +0000)
Follows-up I5b14d65a and I5a563c59.

Change-Id: Id42e1b868c9fe97cdb14b4bc7328947820a7fd94

tests/phpunit/ResourceLoaderTestCase.php
tests/phpunit/data/resourceloader/oouiimagemodule/apex/icons.json [new file with mode: 0644]
tests/phpunit/data/resourceloader/oouiimagemodule/apex/images/icons/search.svg [new file with mode: 0644]
tests/phpunit/data/resourceloader/oouiimagemodule/mediawiki/icons.json [new file with mode: 0644]
tests/phpunit/data/resourceloader/oouiimagemodule/mediawiki/images/icons/search.svg [new file with mode: 0644]
tests/phpunit/includes/resourceloader/ResourceLoaderOOUIImageModuleTest.php [new file with mode: 0644]

index 68b91bf..a8a8f4d 100644 (file)
@@ -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 (file)
index 0000000..4fe3d81
--- /dev/null
@@ -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 (file)
index 0000000..6952997
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
+    <g id="search">
+        <path id="magnifying-glass-apex" d="M18.87 18.375l-3.987-3.99-.286-.17a5.774 5.774 0 0 0 1.082-3.372C15.67 7.616 13.06 5 9.84 5A5.843 5.843 0 0 0 4 10.844a5.84 5.84 0 0 0 5.842 5.842c1.26 0 2.423-.403 3.377-1.08l.16.286 3.99 3.987c.32.31.91.24 1.33-.18.41-.42.49-1.01.17-1.33zM9.837 14.56a3.72 3.72 0 0 1-3.718-3.717c0-2.05 1.67-3.72 3.72-3.72s3.72 1.668 3.72 3.72a3.722 3.722 0 0 1-3.72 3.718z"/>
+    </g>
+</svg>
diff --git a/tests/phpunit/data/resourceloader/oouiimagemodule/mediawiki/icons.json b/tests/phpunit/data/resourceloader/oouiimagemodule/mediawiki/icons.json
new file mode 100644 (file)
index 0000000..4fe3d81
--- /dev/null
@@ -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 (file)
index 0000000..40438ea
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
+    <g id="search">
+        <path id="magnifying-glass-mediawiki" d="M10.5 4a6.5 6.5 0 1 0 2.844 12.344L16 19c1.4 1.4 2.5 1.5 4 0l-4.438-4.438A6.426 6.426 0 0 0 17 10.5 6.5 6.5 0 0 0 10.5 4zm0 2a4.5 4.5 0 1 1 0 9 4.5 4.5 0 0 1 0-9z"/>
+    </g>
+</svg>
diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderOOUIImageModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderOOUIImageModuleTest.php
new file mode 100644 (file)
index 0000000..4e482c8
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+
+/**
+ * @group ResourceLoader
+ */
+class ResourceLoaderOOUIImageModuleTest extends ResourceLoaderTestCase {
+
+       /**
+        * @covers ResourceLoaderOOUIImageModule::loadFromDefinition
+        */
+       public function testNonDefaultSkin() {
+               $module = new ResourceLoaderOOUIImageModule( [
+                       'class' => '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)'
+               );
+       }
+
+}