Merge "Added release notes for 'ContentHandler::runLegacyHooks' removal"
[mediawiki.git] / tests / phpunit / includes / media / XCFTest.php
blob8441d8f06651c05a6d933d219dd068c94327bc72
1 <?php
3 /**
4 * @group Media
5 */
6 class XCFHandlerTest extends MediaWikiMediaTestCase {
8 /** @var XCFHandler */
9 protected $handler;
11 protected function setUp() {
12 parent::setUp();
13 $this->handler = new XCFHandler();
16 /**
17 * @param string $filename
18 * @param int $expectedWidth Width
19 * @param int $expectedHeight Height
20 * @dataProvider provideGetImageSize
21 * @covers XCFHandler::getImageSize
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] );
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 ],
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
44 public function testIsMetadataValid( $metadata, $expected ) {
45 $actual = $this->handler->isMetadataValid( null, $metadata );
46 $this->assertEquals( $expected, $actual );
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 ],
58 /**
59 * @param string $filename
60 * @param string $expected Serialized array
61 * @dataProvider provideGetMetadata
62 * @covers XCFHandler::getMetadata
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 );
70 public static function provideGetMetadata() {
71 return [
72 [ '80x60-2layers.xcf', 'a:1:{s:9:"colorType";s:16:"truecolour-alpha";}' ],
73 [ '80x60-RGB.xcf', 'a:1:{s:9:"colorType";s:16:"truecolour-alpha";}' ],
74 [ '80x60-Greyscale.xcf', 'a:1:{s:9:"colorType";s:15:"greyscale-alpha";}' ],