2 class PNGHandlerTest
extends MediaWikiTestCase
{
8 /** @var FSFileBackend */
13 protected function setUp() {
16 $this->filePath
= __DIR__
. '/../../data/media';
17 $this->backend
= new FSFileBackend( array(
18 'name' => 'localtesting',
19 'wikiId' => wfWikiId(),
20 'containerPaths' => array( 'data' => $this->filePath
)
22 $this->repo
= new FSRepo( array(
24 'url' => 'http://localhost/thumbtest',
25 'backend' => $this->backend
27 $this->handler
= new PNGHandler();
31 * @covers PNGHandler::getMetadata
33 public function testInvalidFile() {
34 $res = $this->handler
->getMetadata( null, $this->filePath
. '/README' );
35 $this->assertEquals( PNGHandler
::BROKEN_FILE
, $res );
39 * @param string $filename basename of the file to check
40 * @param bool $expected Expected result.
41 * @dataProvider provideIsAnimated
42 * @covers PNGHandler::isAnimatedImage
44 public function testIsAnimanted( $filename, $expected ) {
45 $file = $this->dataFile( $filename, 'image/png' );
46 $actual = $this->handler
->isAnimatedImage( $file );
47 $this->assertEquals( $expected, $actual );
50 public static function provideIsAnimated() {
52 array( 'Animated_PNG_example_bouncing_beach_ball.png', true ),
53 array( '1bit-png.png', false ),
58 * @param string $filename
59 * @param int $expected Total image area
60 * @dataProvider provideGetImageArea
61 * @covers PNGHandler::getImageArea
63 public function testGetImageArea( $filename, $expected ) {
64 $file = $this->dataFile( $filename, 'image/png' );
65 $actual = $this->handler
->getImageArea( $file, $file->getWidth(), $file->getHeight() );
66 $this->assertEquals( $expected, $actual );
69 public static function provideGetImageArea() {
71 array( '1bit-png.png', 2500 ),
72 array( 'greyscale-png.png', 2500 ),
73 array( 'Png-native-test.png', 126000 ),
74 array( 'Animated_PNG_example_bouncing_beach_ball.png', 10000 ),
79 * @param string $metadata Serialized metadata
80 * @param int $expected One of the class constants of PNGHandler
81 * @dataProvider provideIsMetadataValid
82 * @covers PNGHandler::isMetadataValid
84 public function testIsMetadataValid( $metadata, $expected ) {
85 $actual = $this->handler
->isMetadataValid( null, $metadata );
86 $this->assertEquals( $expected, $actual );
89 public static function provideIsMetadataValid() {
91 array( PNGHandler
::BROKEN_FILE
, PNGHandler
::METADATA_GOOD
),
92 array( '', PNGHandler
::METADATA_BAD
),
93 array( null, PNGHandler
::METADATA_BAD
),
94 array( 'Something invalid!', PNGHandler
::METADATA_BAD
),
95 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
96 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
),
97 // @codingStandardsIgnoreEnd
102 * @param string $filename
103 * @param string $expected Serialized array
104 * @dataProvider provideGetMetadata
105 * @covers PNGHandler::getMetadata
107 public function testGetMetadata( $filename, $expected ) {
108 $file = $this->dataFile( $filename, 'image/png' );
109 $actual = $this->handler
->getMetadata( $file, "$this->filePath/$filename" );
110 // $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
111 $this->assertEquals( ( $expected ), ( $actual ) );
114 public static function provideGetMetadata() {
116 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
117 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;}}' ),
118 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;}}' ),
119 // @codingStandardsIgnoreEnd
124 * @param string $filename
125 * @param array $expected Expected standard metadata
126 * @dataProvider provideGetIndependentMetaArray
127 * @covers PNGHandler::getCommonMetaArray
129 public function testGetIndependentMetaArray( $filename, $expected ) {
130 $file = $this->dataFile( $filename, 'image/png' );
131 $actual = $this->handler
->getCommonMetaArray( $file );
132 $this->assertEquals( $expected, $actual );
135 public function provideGetIndependentMetaArray() {
137 array( 'rgb-na-png.png', array() ),
140 'SerialNumber' => '123456789',
146 private function dataFile( $name, $type ) {
147 return new UnregisteredLocalFile( false, $this->repo
,
148 "mwstore://localtesting/data/$name", $type );