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 ) &&
19 isset( $options['variants'] ) ?
$options['variants'] : array();
20 $variants = array_fill_keys( $allowedVariants, array( 'color' => 'red' ) );
21 return new ResourceLoaderImageTestable(
30 public static function provideGetPath() {
32 array( 'add', 'en', 'add.gif' ),
33 array( 'add', 'he', 'add.gif' ),
34 array( 'remove', 'en', 'remove.svg' ),
35 array( 'remove', 'he', 'remove.svg' ),
36 array( 'next', 'en', 'next.svg' ),
37 array( 'next', 'he', 'prev.svg' ),
38 array( 'help', 'en', 'help-ltr.svg' ),
39 array( 'help', 'ar', 'help-rtl.svg' ),
40 array( 'help', 'he', 'help-ltr.svg' ),
41 array( 'bold', 'en', 'bold-b.svg' ),
42 array( 'bold', 'de', 'bold-f.svg' ),
43 array( 'bold', 'ar', 'bold-f.svg' ),
44 array( 'bold', 'fr', 'bold-a.svg' ),
45 array( 'bold', 'he', 'bold-a.svg' ),
50 * @covers ResourceLoaderImage::getPath
51 * @dataProvider provideGetPath
53 public function testGetPath( $imageName, $languageCode, $path ) {
54 static $dirMap = array(
61 static $contexts = array();
63 $image = $this->getTestImage( $imageName );
64 $context = $this->getResourceLoaderContext( $languageCode, $dirMap[$languageCode] );
66 $this->assertEquals( $image->getPath( $context ), $this->imagesPath
. '/' . $path );
70 * @covers ResourceLoaderImage::getExtension
71 * @covers ResourceLoaderImage::getMimeType
73 public function testGetExtension() {
74 $image = $this->getTestImage( 'remove' );
75 $this->assertEquals( $image->getExtension(), 'svg' );
76 $this->assertEquals( $image->getExtension( 'original' ), 'svg' );
77 $this->assertEquals( $image->getExtension( 'rasterized' ), 'png' );
78 $image = $this->getTestImage( 'add' );
79 $this->assertEquals( $image->getExtension(), 'gif' );
80 $this->assertEquals( $image->getExtension( 'original' ), 'gif' );
81 $this->assertEquals( $image->getExtension( 'rasterized' ), 'gif' );
85 * @covers ResourceLoaderImage::getImageData
86 * @covers ResourceLoaderImage::variantize
87 * @covers ResourceLoaderImage::massageSvgPathdata
89 public function testGetImageData() {
90 $context = $this->getResourceLoaderContext( 'en', 'ltr' );
92 $image = $this->getTestImage( 'remove' );
93 $data = file_get_contents( $this->imagesPath
. '/remove.svg' );
94 $dataConstructive = file_get_contents( $this->imagesPath
. '/remove_variantize.svg' );
95 $this->assertEquals( $image->getImageData( $context, null, 'original' ), $data );
97 $image->getImageData( $context, 'destructive', 'original' ),
100 // Stub, since we don't know if we even have a SVG handler, much less what exactly it'll output
101 $this->assertEquals( $image->getImageData( $context, null, 'rasterized' ), 'RASTERIZESTUB' );
103 $image = $this->getTestImage( 'add' );
104 $data = file_get_contents( $this->imagesPath
. '/add.gif' );
105 $this->assertEquals( $image->getImageData( $context, null, 'original' ), $data );
106 $this->assertEquals( $image->getImageData( $context, null, 'rasterized' ), $data );
110 * @covers ResourceLoaderImage::massageSvgPathdata
112 public function testMassageSvgPathdata() {
113 $image = $this->getTestImage( 'next' );
114 $data = file_get_contents( $this->imagesPath
. '/next.svg' );
115 $dataMassaged = file_get_contents( $this->imagesPath
. '/next_massage.svg' );
116 $this->assertEquals( $image->massageSvgPathdata( $data ), $dataMassaged );
120 class ResourceLoaderImageTestable
extends ResourceLoaderImage
{
121 // Make some protected methods public
122 public function massageSvgPathdata( $svg ) {
123 return parent
::massageSvgPathdata( $svg );
125 // Stub, since we don't know if we even have a SVG handler, much less what exactly it'll output
126 public function rasterize( $svg ) {
127 return 'RASTERIZESTUB';