jenkins-bot has submitted this change and it was merged.

Change subject: ResourceLoaderImageModule: Add basic tests
......................................................................


ResourceLoaderImageModule: Add basic tests

Bug: T86334
Change-Id: Ie98bf5dec2d4d4c309ed5075b3191da3017f5ad4
---
A tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php
1 file changed, 160 insertions(+), 0 deletions(-)

Approvals:
  Jforrester: Looks good to me, approved
  jenkins-bot: Verified



diff --git 
a/tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php 
b/tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php
new file mode 100644
index 0000000..f98f5fc
--- /dev/null
+++ b/tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php
@@ -0,0 +1,160 @@
+<?php
+
+/**
+ * @group ResourceLoader
+ */
+class ResourceLoaderImageModuleTest extends ResourceLoaderTestCase {
+
+       public static function providerGetModules() {
+               $commonVariants = array(
+                       'invert' => array(
+                               'color' => '#FFFFFF',
+                               'global' => true,
+                       ),
+                       'primary' => array(
+                               'color' => '#598AD1',
+                       ),
+                       'constructive' => array(
+                               'color' => '#00C697',
+                       ),
+                       'destructive' => array(
+                               'color' => '#E81915',
+                       ),
+               );
+
+               $commonImageData = array(
+                       'advanced' => 'advanced.svg',
+                       'remove' => array(
+                               'image' => 'remove.svg',
+                               'variants' => array( 'destructive' ),
+                       ),
+                       'next' => array(
+                               'image' => array(
+                                       'ltr' => 'next.svg',
+                                       'rtl' => 'prev.svg'
+                               ),
+                       ),
+                       'help' => array(
+                               'image' => array(
+                                       'ltr' => 'help-ltr.svg',
+                                       'rtl' => 'help-rtl.svg',
+                                       'lang' => array(
+                                               'he' => 'help-ltr.svg',
+                                       )
+                               ),
+                       ),
+                       'bold' => array(
+                               'image' => array(
+                                       'default' => 'bold-a.svg',
+                                       'lang' => array(
+                                               'en' => 'bold-b.svg',
+                                               'de' => 'bold-f.svg',
+                                       )
+                               ),
+                       )
+               );
+
+               return array(
+                       array(
+                               array(
+                                       'class' => 'ResourceLoaderImageModule',
+                                       'prefix' => 'oo-ui',
+                                       'variants' => array(
+                                               'icon' => $commonVariants,
+                                       ),
+                                       'images' => array(
+                                               'icon' => $commonImageData,
+                                       ),
+                               ),
+                               '.oo-ui-icon-advanced {
+       ...
+}
+.oo-ui-icon-advanced-invert {
+       ...
+}
+.oo-ui-icon-remove {
+       ...
+}
+.oo-ui-icon-remove-invert {
+       ...
+}
+.oo-ui-icon-remove-destructive {
+       ...
+}
+.oo-ui-icon-next {
+       ...
+}
+.oo-ui-icon-next-invert {
+       ...
+}
+.oo-ui-icon-help {
+       ...
+}
+.oo-ui-icon-help-invert {
+       ...
+}
+.oo-ui-icon-bold {
+       ...
+}
+.oo-ui-icon-bold-invert {
+       ...
+}',
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider providerGetModules
+        * @covers ResourceLoaderImageModule::getStyles
+        */
+       public function testGetStyles( $module, $expected ) {
+               $module = new ResourceLoaderImageModuleTestable( $module );
+               $styles = $module->getStyles( $this->getResourceLoaderContext() 
);
+               $this->assertEquals( $expected, $styles['all'] );
+       }
+}
+
+class ResourceLoaderImageModuleTestable extends ResourceLoaderImageModule {
+       /**
+        * Replace with a stub to make test cases easier to write.
+        */
+       protected function getCssDeclarations( $primary, $fallback ) {
+               return array( '...' );
+       }
+
+       /**
+        * Return mock ResourceLoaderImages that don't call file_get_contents 
and such.
+        */
+       public function getImages() {
+               $images = parent::getImages();
+               foreach ( $images as $name => &$image ) {
+                       $image = new ResourceLoaderImageWrapper( $image );
+               }
+               return $images;
+       }
+}
+
+/**
+ * Wraps a ResourceLoaderImage not to call file_get_contents and such.
+ */
+class ResourceLoaderImageWrapper extends ResourceLoaderImage {
+       public function __construct( ResourceLoaderImage $image ) {
+               $this->image = $image;
+       }
+
+       public function getUrl( ResourceLoaderContext $context, $script, 
$variant, $format ) {
+               return null;
+       }
+
+       public function getDataUri( ResourceLoaderContext $context, $variant, 
$format ) {
+               return null;
+       }
+
+       public function __call( $method, $arguments ) {
+               return call_user_func_array( array( $this->image, $method ), 
$arguments );
+       }
+
+       public function __get( $name ) {
+               return $this->image->$name;
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/199128
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie98bf5dec2d4d4c309ed5075b3191da3017f5ad4
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com>
Gerrit-Reviewer: Bartosz Dziewoński <matma....@gmail.com>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Umherirrender <umherirrender_de...@web.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to