Merge "mediawiki.page.gallery.resize: Remove weird mw.hook call"
[lhc/web/wiklou.git] / tests / phpunit / includes / media / XCFTest.php
1 <?php
2 class XCFHandlerTest extends MediaWikiMediaTestCase {
3
4 /** @var XCFHandler */
5 protected $handler;
6
7 protected function setUp() {
8 parent::setUp();
9 $this->handler = new XCFHandler();
10 }
11
12
13 /**
14 * @param string $filename
15 * @param int $expectedWidth width
16 * @param int $expectedHeigh height
17 * @dataProvider provideGetImageSize
18 * @covers XCFHandler::getImageSize
19 */
20 public function testGetImageSize( $filename, $expectedWidth, $expectedHeight ) {
21 $file = $this->dataFile( $filename, 'image/x-xcf' );
22 $actual = $this->handler->getImageSize( $file, $file->getLocalRefPath() );
23 $this->assertEquals( $expectedWidth, $actual[0] );
24 $this->assertEquals( $expectedHeight, $actual[1] );
25 }
26
27 public static function provideGetImageSize() {
28 return array(
29 array( '80x60-2layers.xcf', 80, 60 ),
30 array( '80x60-RGB.xcf', 80, 60 ),
31 array( '80x60-Greyscale.xcf', 80, 60 ),
32 );
33 }
34
35 /**
36 * @param string $metadata Serialized metadata
37 * @param int $expected One of the class constants of XCFHandler
38 * @dataProvider provideIsMetadataValid
39 * @covers XCFHandler::isMetadataValid
40 */
41 public function testIsMetadataValid( $metadata, $expected ) {
42 $actual = $this->handler->isMetadataValid( null, $metadata );
43 $this->assertEquals( $expected, $actual );
44 }
45
46 public static function provideIsMetadataValid() {
47 return array(
48 array( '', XCFHandler::METADATA_BAD ),
49 array( serialize( array( 'error' => true ) ), XCFHandler::METADATA_GOOD ),
50 array( false, XCFHandler::METADATA_BAD ),
51 array( serialize( array( 'colorType' => 'greyscale-alpha' ) ), XCFHandler::METADATA_GOOD ),
52 );
53 }
54
55 /**
56 * @param string $filename
57 * @param string $expected Serialized array
58 * @dataProvider provideGetMetadata
59 * @covers XCFHandler::getMetadata
60 */
61 public function testGetMetadata( $filename, $expected ) {
62 $file = $this->dataFile( $filename, 'image/png' );
63 $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" );
64 $this->assertEquals( $expected, $actual );
65 }
66
67 public static function provideGetMetadata() {
68 return array(
69 array( '80x60-2layers.xcf', 'a:1:{s:9:"colorType";s:16:"truecolour-alpha";}' ),
70 array( '80x60-RGB.xcf', 'a:1:{s:9:"colorType";s:16:"truecolour-alpha";}' ),
71 array( '80x60-Greyscale.xcf', 'a:1:{s:9:"colorType";s:15:"greyscale-alpha";}' ),
72 );
73 }
74 }