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