Debian Codegraph @

tests/phpunit/includes/media/XCFHandlerTest.php

raw symbols SCIP
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(): void {
12 parent::setUp();
13 $this->handler = new XCFHandler();
14 }
15
16 /**
17 * @param string $filename
18 * @param array $expected
19 * @dataProvider provideGetSizeAndMetadata
20 * @covers \XCFHandler::getSizeAndMetadata
21 */
22 public function testGetSizeAndMetadata( $filename, $expected ) {
23 $file = $this->dataFile( $filename, 'image/x-xcf' );
24 $actual = $this->handler->getSizeAndMetadata( $file, $file->getLocalRefPath() );
25 $this->assertSame( $expected, $actual );
26 }
27
28 public static function provideGetSizeAndMetadata() {
29 return [
30 [
31 '80x60-2layers.xcf',
32 [
33 'width' => 80,
34 'height' => 60,
35 'bits' => 8,
36 'metadata' => [
37 'colorType' => 'truecolour-alpha',
38 ]
39 ],
40 ],
41 [
42 '80x60-RGB.xcf',
43 [
44 'width' => 80,
45 'height' => 60,
46 'bits' => 8,
47 'metadata' => [
48 'colorType' => 'truecolour-alpha',
49 ]
50 ],
51 ],
52 [
53 '80x60-Greyscale.xcf',
54 [
55 'width' => 80,
56 'height' => 60,
57 'bits' => 8,
58 'metadata' => [
59 'colorType' => 'greyscale-alpha',
60 ]
61 ]
62 ],
63 ];
64 }
65
66 /**
67 * @param string $metadata Serialized metadata
68 * @param int $expected One of the class constants of XCFHandler
69 * @dataProvider provideIsFileMetadataValid
70 * @covers \XCFHandler::isFileMetadataValid
71 */
72 public function testIsFileMetadataValid( $metadata, $expected ) {
73 $actual = $this->handler->isFileMetadataValid( $this->getMockFileWithMetadata( $metadata ) );
74 $this->assertEquals( $expected, $actual );
75 }
76
77 public static function provideIsFileMetadataValid() {
78 return [
79 [ '', XCFHandler::METADATA_BAD ],
80 [ serialize( [ 'error' => true ] ), XCFHandler::METADATA_GOOD ],
81 [ false, XCFHandler::METADATA_BAD ],
82 [ serialize( [ 'colorType' => 'greyscale-alpha' ] ), XCFHandler::METADATA_GOOD ],
83 ];
84 }
85 }