4 * @group ResourceLoader
6 class ResourceLoaderImageTest
extends ResourceLoaderTestCase
{
10 protected function setUp() {
12 $this->imagesPath
= __DIR__
. '/../../data/resourceloader';
15 protected function getTestImage( $name ) {
16 $options = ResourceLoaderImageModuleTest
::$commonImageData[$name];
17 $fileDescriptor = is_string( $options ) ?
$options : $options['file'];
18 $allowedVariants = is_array( $options ) && isset( $options['variants'] ) ?
$options['variants'] : array();
19 $variants = array_fill_keys( $allowedVariants, array( 'color' => 'red' ) );
20 return new ResourceLoaderImageTestable( $name, 'test', $fileDescriptor, $this->imagesPath
, $variants );
23 public static function provideGetPath() {
25 array( 'add', 'en', 'add.gif' ),
26 array( 'add', 'he', 'add.gif' ),
27 array( 'remove', 'en', 'remove.svg' ),
28 array( 'remove', 'he', 'remove.svg' ),
29 array( 'next', 'en', 'next.svg' ),
30 array( 'next', 'he', 'prev.svg' ),
31 array( 'help', 'en', 'help-ltr.svg' ),
32 array( 'help', 'ar', 'help-rtl.svg' ),
33 array( 'help', 'he', 'help-ltr.svg' ),
34 array( 'bold', 'en', 'bold-b.svg' ),
35 array( 'bold', 'de', 'bold-f.svg' ),
36 array( 'bold', 'fr', 'bold-a.svg' ),
37 array( 'bold', 'he', 'bold-a.svg' ),
42 * @covers ResourceLoaderImage::getPath
43 * @dataProvider provideGetPath
45 public function testGetPath( $imageName, $languageCode, $path ) {
46 static $dirMap = array(
53 static $contexts = array();
55 $image = $this->getTestImage( $imageName );
56 $context = $this->getResourceLoaderContext( $languageCode, $dirMap[$languageCode] );
58 $this->assertEquals( $image->getPath( $context ), $this->imagesPath
. '/' . $path );
62 * @covers ResourceLoaderImage::getExtension
63 * @covers ResourceLoaderImage::getMimeType
65 public function testGetExtension() {
66 $image = $this->getTestImage( 'remove' );
67 $this->assertEquals( $image->getExtension(), 'svg' );
68 $this->assertEquals( $image->getExtension( 'original' ), 'svg' );
69 $this->assertEquals( $image->getExtension( 'rasterized' ), 'png' );
70 $image = $this->getTestImage( 'add' );
71 $this->assertEquals( $image->getExtension(), 'gif' );
72 $this->assertEquals( $image->getExtension( 'original' ), 'gif' );
73 $this->assertEquals( $image->getExtension( 'rasterized' ), 'gif' );
77 * @covers ResourceLoaderImage::getImageData
78 * @covers ResourceLoaderImage::variantize
79 * @covers ResourceLoaderImage::massageSvgPathdata
81 public function testGetImageData() {
82 $context = $this->getResourceLoaderContext( 'en', 'ltr' );
84 $image = $this->getTestImage( 'remove' );
85 $data = file_get_contents( $this->imagesPath
. '/remove.svg' );
86 $dataConstructive = file_get_contents( $this->imagesPath
. '/remove_variantize.svg' );
87 $this->assertEquals( $image->getImageData( $context, null, 'original' ), $data );
88 $this->assertEquals( $image->getImageData( $context, 'destructive', 'original' ), $dataConstructive );
89 // Stub, since we don't know if we even have a SVG handler, much less what exactly it'll output
90 $this->assertEquals( $image->getImageData( $context, null, 'rasterized' ), 'RASTERIZESTUB' );
92 $image = $this->getTestImage( 'add' );
93 $data = file_get_contents( $this->imagesPath
. '/add.gif' );
94 $this->assertEquals( $image->getImageData( $context, null, 'original' ), $data );
95 $this->assertEquals( $image->getImageData( $context, null, 'rasterized' ), $data );
99 * @covers ResourceLoaderImage::massageSvgPathdata
101 public function testMassageSvgPathdata() {
102 $image = $this->getTestImage( 'next' );
103 $data = file_get_contents( $this->imagesPath
. '/next.svg' );
104 $dataMassaged = file_get_contents( $this->imagesPath
. '/next_massage.svg' );
105 $this->assertEquals( $image->massageSvgPathdata( $data ), $dataMassaged );
109 class ResourceLoaderImageTestable
extends ResourceLoaderImage
{
110 // Make some protected methods public
111 public function getPath( ResourceLoaderContext
$context ) {
112 return parent
::getPath( $context );
114 public function massageSvgPathdata( $svg ) {
115 return parent
::massageSvgPathdata( $svg );
117 // Stub, since we don't know if we even have a SVG handler, much less what exactly it'll output
118 public function rasterize( $svg ) {
119 return 'RASTERIZESTUB';