Move ResultWrapper subclasses to Rdbms
[mediawiki.git] / tests / phpunit / includes / resourceloader / ResourceLoaderImageTest.php
blob84b56d4f11e7a26cf67ab5b2a89b2512a6e42885
1 <?php
3 /**
4 * @group ResourceLoader
5 */
6 class ResourceLoaderImageTest extends ResourceLoaderTestCase {
8 protected $imagesPath;
10 protected function setUp() {
11 parent::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'] : [];
20 $variants = array_fill_keys( $allowedVariants, [ 'color' => 'red' ] );
21 return new ResourceLoaderImageTestable(
22 $name,
23 'test',
24 $fileDescriptor,
25 $this->imagesPath,
26 $variants
30 public static function provideGetPath() {
31 return [
32 [ 'add', 'en', 'add.gif' ],
33 [ 'add', 'he', 'add.gif' ],
34 [ 'remove', 'en', 'remove.svg' ],
35 [ 'remove', 'he', 'remove.svg' ],
36 [ 'next', 'en', 'next.svg' ],
37 [ 'next', 'he', 'prev.svg' ],
38 [ 'help', 'en', 'help-ltr.svg' ],
39 [ 'help', 'ar', 'help-rtl.svg' ],
40 [ 'help', 'he', 'help-ltr.svg' ],
41 [ 'bold', 'en', 'bold-b.svg' ],
42 [ 'bold', 'de', 'bold-f.svg' ],
43 [ 'bold', 'ar', 'bold-f.svg' ],
44 [ 'bold', 'fr', 'bold-a.svg' ],
45 [ 'bold', 'he', 'bold-a.svg' ],
49 /**
50 * @covers ResourceLoaderImage::getPath
51 * @dataProvider provideGetPath
53 public function testGetPath( $imageName, $languageCode, $path ) {
54 static $dirMap = [
55 'en' => 'ltr',
56 'de' => 'ltr',
57 'fr' => 'ltr',
58 'he' => 'rtl',
59 'ar' => 'rtl',
61 static $contexts = [];
63 $image = $this->getTestImage( $imageName );
64 $context = $this->getResourceLoaderContext( [
65 'lang' => $languageCode,
66 'dir' => $dirMap[$languageCode],
67 ] );
69 $this->assertEquals( $image->getPath( $context ), $this->imagesPath . '/' . $path );
72 /**
73 * @covers ResourceLoaderImage::getExtension
74 * @covers ResourceLoaderImage::getMimeType
76 public function testGetExtension() {
77 $image = $this->getTestImage( 'remove' );
78 $this->assertEquals( $image->getExtension(), 'svg' );
79 $this->assertEquals( $image->getExtension( 'original' ), 'svg' );
80 $this->assertEquals( $image->getExtension( 'rasterized' ), 'png' );
81 $image = $this->getTestImage( 'add' );
82 $this->assertEquals( $image->getExtension(), 'gif' );
83 $this->assertEquals( $image->getExtension( 'original' ), 'gif' );
84 $this->assertEquals( $image->getExtension( 'rasterized' ), 'gif' );
87 /**
88 * @covers ResourceLoaderImage::getImageData
89 * @covers ResourceLoaderImage::variantize
90 * @covers ResourceLoaderImage::massageSvgPathdata
92 public function testGetImageData() {
93 $context = $this->getResourceLoaderContext();
95 $image = $this->getTestImage( 'remove' );
96 $data = file_get_contents( $this->imagesPath . '/remove.svg' );
97 $dataConstructive = file_get_contents( $this->imagesPath . '/remove_variantize.svg' );
98 $this->assertEquals( $image->getImageData( $context, null, 'original' ), $data );
99 $this->assertEquals(
100 $image->getImageData( $context, 'destructive', 'original' ),
101 $dataConstructive
103 // Stub, since we don't know if we even have a SVG handler, much less what exactly it'll output
104 $this->assertEquals( $image->getImageData( $context, null, 'rasterized' ), 'RASTERIZESTUB' );
106 $image = $this->getTestImage( 'add' );
107 $data = file_get_contents( $this->imagesPath . '/add.gif' );
108 $this->assertEquals( $image->getImageData( $context, null, 'original' ), $data );
109 $this->assertEquals( $image->getImageData( $context, null, 'rasterized' ), $data );
113 * @covers ResourceLoaderImage::massageSvgPathdata
115 public function testMassageSvgPathdata() {
116 $image = $this->getTestImage( 'next' );
117 $data = file_get_contents( $this->imagesPath . '/next.svg' );
118 $dataMassaged = file_get_contents( $this->imagesPath . '/next_massage.svg' );
119 $this->assertEquals( $image->massageSvgPathdata( $data ), $dataMassaged );
123 class ResourceLoaderImageTestable extends ResourceLoaderImage {
124 // Make some protected methods public
125 public function massageSvgPathdata( $svg ) {
126 return parent::massageSvgPathdata( $svg );
128 // Stub, since we don't know if we even have a SVG handler, much less what exactly it'll output
129 public function rasterize( $svg ) {
130 return 'RASTERIZESTUB';