Merge "Add 3D filetype for STL files"
[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 * @param string $filename
18 * @param int $expectedWidth Width
19 * @param int $expectedHeight Height
20 * @dataProvider provideGetImageSize
21 * @covers XCFHandler::getImageSize
22 */
23 public function testGetImageSize( $filename, $expectedWidth, $expectedHeight ) {
24 $file = $this->dataFile( $filename, 'image/x-xcf' );
25 $actual = $this->handler->getImageSize( $file, $file->getLocalRefPath() );
26 $this->assertEquals( $expectedWidth, $actual[0] );
27 $this->assertEquals( $expectedHeight, $actual[1] );
28 }
29
30 public static function provideGetImageSize() {
31 return [
32 [ '80x60-2layers.xcf', 80, 60 ],
33 [ '80x60-RGB.xcf', 80, 60 ],
34 [ '80x60-Greyscale.xcf', 80, 60 ],
35 ];
36 }
37
38 /**
39 * @param string $metadata Serialized metadata
40 * @param int $expected One of the class constants of XCFHandler
41 * @dataProvider provideIsMetadataValid
42 * @covers XCFHandler::isMetadataValid
43 */
44 public function testIsMetadataValid( $metadata, $expected ) {
45 $actual = $this->handler->isMetadataValid( null, $metadata );
46 $this->assertEquals( $expected, $actual );
47 }
48
49 public static function provideIsMetadataValid() {
50 return [
51 [ '', XCFHandler::METADATA_BAD ],
52 [ serialize( [ 'error' => true ] ), XCFHandler::METADATA_GOOD ],
53 [ false, XCFHandler::METADATA_BAD ],
54 [ serialize( [ 'colorType' => 'greyscale-alpha' ] ), XCFHandler::METADATA_GOOD ],
55 ];
56 }
57
58 /**
59 * @param string $filename
60 * @param string $expected Serialized array
61 * @dataProvider provideGetMetadata
62 * @covers XCFHandler::getMetadata
63 */
64 public function testGetMetadata( $filename, $expected ) {
65 $file = $this->dataFile( $filename, 'image/png' );
66 $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" );
67 $this->assertEquals( $expected, $actual );
68 }
69
70 public static function provideGetMetadata() {
71 return [
72 [ '80x60-2layers.xcf',
73 'a:1:{s:9:"colorType";s:16:"truecolour-alpha";}'
74 ],
75 [ '80x60-RGB.xcf',
76 'a:1:{s:9:"colorType";s:16:"truecolour-alpha";}'
77 ],
78 [ '80x60-Greyscale.xcf',
79 'a:1:{s:9:"colorType";s:15:"greyscale-alpha";}'
80 ],
81 ];
82 }
83 }