MediaWiki  REL1_22
PNGTest.php
Go to the documentation of this file.
00001 <?php
00002 class PNGHandlerTest extends MediaWikiTestCase {
00003 
00005     protected $handler;
00007     protected $repo;
00009     protected $backend;
00011     protected $filePath;
00012 
00013     protected function setUp() {
00014         parent::setUp();
00015 
00016         $this->filePath = __DIR__ . '/../../data/media';
00017         $this->backend = new FSFileBackend( array(
00018             'name' => 'localtesting',
00019             'lockManager' => 'nullLockManager',
00020             'containerPaths' => array( 'data' => $this->filePath )
00021         ) );
00022         $this->repo = new FSRepo( array(
00023             'name' => 'temp',
00024             'url' => 'http://localhost/thumbtest',
00025             'backend' => $this->backend
00026         ) );
00027         $this->handler = new PNGHandler();
00028     }
00029 
00033     public function testInvalidFile() {
00034         $res = $this->handler->getMetadata( null, $this->filePath . '/README' );
00035         $this->assertEquals( PNGHandler::BROKEN_FILE, $res );
00036     }
00037 
00044     public function testIsAnimanted( $filename, $expected ) {
00045         $file = $this->dataFile( $filename, 'image/png' );
00046         $actual = $this->handler->isAnimatedImage( $file );
00047         $this->assertEquals( $expected, $actual );
00048     }
00049 
00050     public static function provideIsAnimated() {
00051         return array(
00052             array( 'Animated_PNG_example_bouncing_beach_ball.png', true ),
00053             array( '1bit-png.png', false ),
00054         );
00055     }
00056 
00063     public function testGetImageArea( $filename, $expected ) {
00064         $file = $this->dataFile( $filename, 'image/png' );
00065         $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() );
00066         $this->assertEquals( $expected, $actual );
00067     }
00068 
00069     public static function provideGetImageArea() {
00070         return array(
00071             array( '1bit-png.png', 2500 ),
00072             array( 'greyscale-png.png', 2500 ),
00073             array( 'Png-native-test.png', 126000 ),
00074             array( 'Animated_PNG_example_bouncing_beach_ball.png', 10000 ),
00075         );
00076     }
00077 
00084     public function testIsMetadataValid( $metadata, $expected ) {
00085         $actual = $this->handler->isMetadataValid( null, $metadata );
00086         $this->assertEquals( $expected, $actual );
00087     }
00088 
00089     public static function provideIsMetadataValid() {
00090         return array(
00091             array( PNGHandler::BROKEN_FILE, PNGHandler::METADATA_GOOD ),
00092             array( '', PNGHandler::METADATA_BAD ),
00093             array( null, PNGHandler::METADATA_BAD ),
00094             array( 'Something invalid!', PNGHandler::METADATA_BAD ),
00095             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 ),
00096         );
00097     }
00098 
00105     public function testGetMetadata( $filename, $expected ) {
00106         $file = $this->dataFile( $filename, 'image/png' );
00107         $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" );
00108 //      $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
00109         $this->assertEquals( ( $expected ), ( $actual ) );
00110     }
00111 
00112     public static function provideGetMetadata() {
00113         return array(
00114             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;}}' ),
00115             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;}}' ),
00116         );
00117     }
00118 
00119     private function dataFile( $name, $type ) {
00120         return new UnregisteredLocalFile( false, $this->repo,
00121             "mwstore://localtesting/data/$name", $type );
00122     }
00123 }