From 5ed35b04c99abbd7a8d015402f359c7002c491eb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Fri, 27 Mar 2015 18:08:11 +0100 Subject: [PATCH] ResourceLoaderImageModule: Add basic tests Bug: T86334 Change-Id: Ie98bf5dec2d4d4c309ed5075b3191da3017f5ad4 --- .../ResourceLoaderImageModuleTest.php | 160 ++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php new file mode 100644 index 0000000000..f98f5fc847 --- /dev/null +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php @@ -0,0 +1,160 @@ + 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; + } +} -- 2.20.1