MediaWiki  REL1_24
PNGTest.php
Go to the documentation of this file.
00001 <?php
00002 
00006 class PNGHandlerTest extends MediaWikiMediaTestCase {
00007 
00009     protected $handler;
00010 
00011     protected function setUp() {
00012         parent::setUp();
00013         $this->handler = new PNGHandler();
00014     }
00015 
00019     public function testInvalidFile() {
00020         $res = $this->handler->getMetadata( null, $this->filePath . '/README' );
00021         $this->assertEquals( PNGHandler::BROKEN_FILE, $res );
00022     }
00023 
00030     public function testIsAnimanted( $filename, $expected ) {
00031         $file = $this->dataFile( $filename, 'image/png' );
00032         $actual = $this->handler->isAnimatedImage( $file );
00033         $this->assertEquals( $expected, $actual );
00034     }
00035 
00036     public static function provideIsAnimated() {
00037         return array(
00038             array( 'Animated_PNG_example_bouncing_beach_ball.png', true ),
00039             array( '1bit-png.png', false ),
00040         );
00041     }
00042 
00049     public function testGetImageArea( $filename, $expected ) {
00050         $file = $this->dataFile( $filename, 'image/png' );
00051         $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() );
00052         $this->assertEquals( $expected, $actual );
00053     }
00054 
00055     public static function provideGetImageArea() {
00056         return array(
00057             array( '1bit-png.png', 2500 ),
00058             array( 'greyscale-png.png', 2500 ),
00059             array( 'Png-native-test.png', 126000 ),
00060             array( 'Animated_PNG_example_bouncing_beach_ball.png', 10000 ),
00061         );
00062     }
00063 
00070     public function testIsMetadataValid( $metadata, $expected ) {
00071         $actual = $this->handler->isMetadataValid( null, $metadata );
00072         $this->assertEquals( $expected, $actual );
00073     }
00074 
00075     public static function provideIsMetadataValid() {
00076         return array(
00077             array( PNGHandler::BROKEN_FILE, PNGHandler::METADATA_GOOD ),
00078             array( '', PNGHandler::METADATA_BAD ),
00079             array( null, PNGHandler::METADATA_BAD ),
00080             array( 'Something invalid!', PNGHandler::METADATA_BAD ),
00081             // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
00082             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 ),
00083             // @codingStandardsIgnoreEnd
00084         );
00085     }
00086 
00093     public function testGetMetadata( $filename, $expected ) {
00094         $file = $this->dataFile( $filename, 'image/png' );
00095         $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" );
00096 //      $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
00097         $this->assertEquals( ( $expected ), ( $actual ) );
00098     }
00099 
00100     public static function provideGetMetadata() {
00101         return array(
00102             // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
00103             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;}}' ),
00104             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;}}' ),
00105             // @codingStandardsIgnoreEnd
00106         );
00107     }
00108 
00115     public function testGetIndependentMetaArray( $filename, $expected ) {
00116         $file = $this->dataFile( $filename, 'image/png' );
00117         $actual = $this->handler->getCommonMetaArray( $file );
00118         $this->assertEquals( $expected, $actual );
00119     }
00120 
00121     public static function provideGetIndependentMetaArray() {
00122         return array(
00123             array( 'rgb-na-png.png', array() ),
00124             array( 'xmp.png',
00125                 array(
00126                     'SerialNumber' => '123456789',
00127                 )
00128             ),
00129         );
00130     }
00131 }