Merge "Don't localize parentheses in version number in parserTests.php"
[lhc/web/wiklou.git] / tests / phpunit / includes / resourceloader / ResourceLoaderImageTest.php
1 <?php
2
3 /**
4 * @group ResourceLoader
5 */
6 class ResourceLoaderImageTest extends ResourceLoaderTestCase {
7
8 protected $imagesPath;
9
10 protected function setUp() {
11 parent::setUp();
12 $this->imagesPath = __DIR__ . '/../../data/resourceloader';
13 }
14
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 );
21 }
22
23 public static function provideGetPath() {
24 return array(
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', 'ar', 'bold-f.svg' ),
37 array( 'bold', 'fr', 'bold-a.svg' ),
38 array( 'bold', 'he', 'bold-a.svg' ),
39 );
40 }
41
42 /**
43 * @covers ResourceLoaderImage::getPath
44 * @dataProvider provideGetPath
45 */
46 public function testGetPath( $imageName, $languageCode, $path ) {
47 static $dirMap = array(
48 'en' => 'ltr',
49 'de' => 'ltr',
50 'fr' => 'ltr',
51 'he' => 'rtl',
52 'ar' => 'rtl',
53 );
54 static $contexts = array();
55
56 $image = $this->getTestImage( $imageName );
57 $context = $this->getResourceLoaderContext( $languageCode, $dirMap[$languageCode] );
58
59 $this->assertEquals( $image->getPath( $context ), $this->imagesPath . '/' . $path );
60 }
61
62 /**
63 * @covers ResourceLoaderImage::getExtension
64 * @covers ResourceLoaderImage::getMimeType
65 */
66 public function testGetExtension() {
67 $image = $this->getTestImage( 'remove' );
68 $this->assertEquals( $image->getExtension(), 'svg' );
69 $this->assertEquals( $image->getExtension( 'original' ), 'svg' );
70 $this->assertEquals( $image->getExtension( 'rasterized' ), 'png' );
71 $image = $this->getTestImage( 'add' );
72 $this->assertEquals( $image->getExtension(), 'gif' );
73 $this->assertEquals( $image->getExtension( 'original' ), 'gif' );
74 $this->assertEquals( $image->getExtension( 'rasterized' ), 'gif' );
75 }
76
77 /**
78 * @covers ResourceLoaderImage::getImageData
79 * @covers ResourceLoaderImage::variantize
80 * @covers ResourceLoaderImage::massageSvgPathdata
81 */
82 public function testGetImageData() {
83 $context = $this->getResourceLoaderContext( 'en', 'ltr' );
84
85 $image = $this->getTestImage( 'remove' );
86 $data = file_get_contents( $this->imagesPath . '/remove.svg' );
87 $dataConstructive = file_get_contents( $this->imagesPath . '/remove_variantize.svg' );
88 $this->assertEquals( $image->getImageData( $context, null, 'original' ), $data );
89 $this->assertEquals( $image->getImageData( $context, 'destructive', 'original' ), $dataConstructive );
90 // Stub, since we don't know if we even have a SVG handler, much less what exactly it'll output
91 $this->assertEquals( $image->getImageData( $context, null, 'rasterized' ), 'RASTERIZESTUB' );
92
93 $image = $this->getTestImage( 'add' );
94 $data = file_get_contents( $this->imagesPath . '/add.gif' );
95 $this->assertEquals( $image->getImageData( $context, null, 'original' ), $data );
96 $this->assertEquals( $image->getImageData( $context, null, 'rasterized' ), $data );
97 }
98
99 /**
100 * @covers ResourceLoaderImage::massageSvgPathdata
101 */
102 public function testMassageSvgPathdata() {
103 $image = $this->getTestImage( 'next' );
104 $data = file_get_contents( $this->imagesPath . '/next.svg' );
105 $dataMassaged = file_get_contents( $this->imagesPath . '/next_massage.svg' );
106 $this->assertEquals( $image->massageSvgPathdata( $data ), $dataMassaged );
107 }
108 }
109
110 class ResourceLoaderImageTestable extends ResourceLoaderImage {
111 // Make some protected methods public
112 public function massageSvgPathdata( $svg ) {
113 return parent::massageSvgPathdata( $svg );
114 }
115 // Stub, since we don't know if we even have a SVG handler, much less what exactly it'll output
116 public function rasterize( $svg ) {
117 return 'RASTERIZESTUB';
118 }
119 }