Support offsets in prefix searching
[mediawiki.git] / tests / phpunit / includes / media / PNGTest.php
blob36872a75d23c25072b9b200e137be29d9a6d7092
1 <?php
3 /**
4 * @group Media
5 */
6 class PNGHandlerTest extends MediaWikiMediaTestCase {
8 /** @var PNGHandler */
9 protected $handler;
11 protected function setUp() {
12 parent::setUp();
13 $this->handler = new PNGHandler();
16 /**
17 * @covers PNGHandler::getMetadata
19 public function testInvalidFile() {
20 $res = $this->handler->getMetadata( null, $this->filePath . '/README' );
21 $this->assertEquals( PNGHandler::BROKEN_FILE, $res );
24 /**
25 * @param string $filename Basename of the file to check
26 * @param bool $expected Expected result.
27 * @dataProvider provideIsAnimated
28 * @covers PNGHandler::isAnimatedImage
30 public function testIsAnimanted( $filename, $expected ) {
31 $file = $this->dataFile( $filename, 'image/png' );
32 $actual = $this->handler->isAnimatedImage( $file );
33 $this->assertEquals( $expected, $actual );
36 public static function provideIsAnimated() {
37 return array(
38 array( 'Animated_PNG_example_bouncing_beach_ball.png', true ),
39 array( '1bit-png.png', false ),
43 /**
44 * @param string $filename
45 * @param int $expected Total image area
46 * @dataProvider provideGetImageArea
47 * @covers PNGHandler::getImageArea
49 public function testGetImageArea( $filename, $expected ) {
50 $file = $this->dataFile( $filename, 'image/png' );
51 $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() );
52 $this->assertEquals( $expected, $actual );
55 public static function provideGetImageArea() {
56 return array(
57 array( '1bit-png.png', 2500 ),
58 array( 'greyscale-png.png', 2500 ),
59 array( 'Png-native-test.png', 126000 ),
60 array( 'Animated_PNG_example_bouncing_beach_ball.png', 10000 ),
64 /**
65 * @param string $metadata Serialized metadata
66 * @param int $expected One of the class constants of PNGHandler
67 * @dataProvider provideIsMetadataValid
68 * @covers PNGHandler::isMetadataValid
70 public function testIsMetadataValid( $metadata, $expected ) {
71 $actual = $this->handler->isMetadataValid( null, $metadata );
72 $this->assertEquals( $expected, $actual );
75 public static function provideIsMetadataValid() {
76 return array(
77 array( PNGHandler::BROKEN_FILE, PNGHandler::METADATA_GOOD ),
78 array( '', PNGHandler::METADATA_BAD ),
79 array( null, PNGHandler::METADATA_BAD ),
80 array( 'Something invalid!', PNGHandler::METADATA_BAD ),
81 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
82 array( 'a:6:{s:10:"frameCount";i:0;s:9:"loopCount";i:1;s:8:"duration";d:0;s:8:"bitDepth";i:8;s:9:"colorType";s:10:"truecolour";s:8:"metadata";a:1:{s:15:"_MW_PNG_VERSION";i:1;}}', PNGHandler::METADATA_GOOD ),
83 // @codingStandardsIgnoreEnd
87 /**
88 * @param string $filename
89 * @param string $expected Serialized array
90 * @dataProvider provideGetMetadata
91 * @covers PNGHandler::getMetadata
93 public function testGetMetadata( $filename, $expected ) {
94 $file = $this->dataFile( $filename, 'image/png' );
95 $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" );
96 // $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
97 $this->assertEquals( ( $expected ), ( $actual ) );
100 public static function provideGetMetadata() {
101 return array(
102 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
103 array( 'rgb-na-png.png', 'a:6:{s:10:"frameCount";i:0;s:9:"loopCount";i:1;s:8:"duration";d:0;s:8:"bitDepth";i:8;s:9:"colorType";s:10:"truecolour";s:8:"metadata";a:1:{s:15:"_MW_PNG_VERSION";i:1;}}' ),
104 array( 'xmp.png', 'a:6:{s:10:"frameCount";i:0;s:9:"loopCount";i:1;s:8:"duration";d:0;s:8:"bitDepth";i:1;s:9:"colorType";s:14:"index-coloured";s:8:"metadata";a:2:{s:12:"SerialNumber";s:9:"123456789";s:15:"_MW_PNG_VERSION";i:1;}}' ),
105 // @codingStandardsIgnoreEnd
110 * @param string $filename
111 * @param array $expected Expected standard metadata
112 * @dataProvider provideGetIndependentMetaArray
113 * @covers PNGHandler::getCommonMetaArray
115 public function testGetIndependentMetaArray( $filename, $expected ) {
116 $file = $this->dataFile( $filename, 'image/png' );
117 $actual = $this->handler->getCommonMetaArray( $file );
118 $this->assertEquals( $expected, $actual );
121 public static function provideGetIndependentMetaArray() {
122 return array(
123 array( 'rgb-na-png.png', array() ),
124 array( 'xmp.png',
125 array(
126 'SerialNumber' => '123456789',