MediaWiki  master
PNGTest.php
Go to the documentation of this file.
00001 <?php
00002 class PNGHandlerTest extends MediaWikiTestCase {
00003 
00004         protected function setUp() {
00005                 parent::setUp();
00006 
00007                 $this->filePath = __DIR__ .  '/../../data/media';
00008                 $this->backend = new FSFileBackend( array(
00009                         'name'           => 'localtesting',
00010                         'lockManager'    => 'nullLockManager',
00011                         'containerPaths' => array( 'data' => $this->filePath )
00012                 ) );
00013                 $this->repo = new FSRepo( array(
00014                         'name'    => 'temp',
00015                         'url'     => 'http://localhost/thumbtest',
00016                         'backend' => $this->backend
00017                 ) );
00018                 $this->handler = new PNGHandler();
00019         }
00020 
00021         public function testInvalidFile() {
00022                 $res = $this->handler->getMetadata( null, $this->filePath . '/README' );
00023                 $this->assertEquals( PNGHandler::BROKEN_FILE, $res );
00024         }
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         public static function provideIsAnimated() {
00036                 return array(
00037                         array( 'Animated_PNG_example_bouncing_beach_ball.png', true ),
00038                         array( '1bit-png.png', false ),
00039                 );
00040         }
00041 
00047         public function testGetImageArea( $filename, $expected ) {
00048                 $file = $this->dataFile($filename, 'image/png' );
00049                 $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() );
00050                 $this->assertEquals( $expected, $actual );
00051         }
00052         public static function provideGetImageArea() {
00053                 return array(
00054                         array( '1bit-png.png', 2500 ),
00055                         array( 'greyscale-png.png', 2500 ),
00056                         array( 'Png-native-test.png', 126000 ),
00057                         array( 'Animated_PNG_example_bouncing_beach_ball.png', 10000 ),
00058                 );
00059         }
00060 
00066         public function testIsMetadataValid( $metadata, $expected ) {
00067                 $actual = $this->handler->isMetadataValid( null, $metadata );
00068                 $this->assertEquals( $expected, $actual );
00069         }
00070         public static function provideIsMetadataValid() {
00071                 return array(
00072                         array( PNGHandler::BROKEN_FILE, PNGHandler::METADATA_GOOD ),
00073                         array( '', PNGHandler::METADATA_BAD ),
00074                         array( null, PNGHandler::METADATA_BAD ),
00075                         array( 'Something invalid!', PNGHandler::METADATA_BAD ),
00076                         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 ),
00077                 );
00078         }
00079 
00085         public function testGetMetadata( $filename, $expected ) {
00086                 $file = $this->dataFile( $filename, 'image/png' );
00087                 $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" );
00088 //              $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
00089                 $this->assertEquals( ( $expected ), ( $actual ) );
00090         }
00091         public static function provideGetMetadata() {
00092                 return array(
00093                         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;}}' ),
00094                         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;}}' ), 
00095                 );
00096         }
00097 
00098         private function dataFile( $name, $type ) {
00099                 return new UnregisteredLocalFile( false, $this->repo,
00100                         "mwstore://localtesting/data/$name", $type );
00101         }
00102 }