MediaWiki  REL1_22
FormatMetadataTest.php
Go to the documentation of this file.
00001 <?php
00002 
00006 class FormatMetadataTest extends MediaWikiTestCase {
00007 
00009     protected $backend;
00011     protected $repo;
00012 
00013     protected function setUp() {
00014         parent::setUp();
00015 
00016         if ( !extension_loaded( 'exif' ) ) {
00017             $this->markTestSkipped( "This test needs the exif extension." );
00018         }
00019         $filePath = __DIR__ . '/../../data/media';
00020         $this->backend = new FSFileBackend( array(
00021             'name' => 'localtesting',
00022             'lockManager' => 'nullLockManager',
00023             'containerPaths' => array( 'data' => $filePath )
00024         ) );
00025         $this->repo = new FSRepo( array(
00026             'name' => 'temp',
00027             'url' => 'http://localhost/thumbtest',
00028             'backend' => $this->backend
00029         ) );
00030 
00031         $this->setMwGlobals( 'wgShowEXIF', true );
00032     }
00033 
00034     public function testInvalidDate() {
00035         $file = $this->dataFile( 'broken_exif_date.jpg', 'image/jpeg' );
00036 
00037         // Throws an error if bug hit
00038         $meta = $file->formatMetadata();
00039         $this->assertNotEquals( false, $meta, 'Valid metadata extracted' );
00040 
00041         // Find date exif entry
00042         $this->assertArrayHasKey( 'visible', $meta );
00043         $dateIndex = null;
00044         foreach ( $meta['visible'] as $i => $data ) {
00045             if ( $data['id'] == 'exif-datetimeoriginal' ) {
00046                 $dateIndex = $i;
00047             }
00048         }
00049         $this->assertNotNull( $dateIndex, 'Date entry exists in metadata' );
00050         $this->assertEquals( '0000:01:00 00:02:27',
00051             $meta['visible'][$dateIndex]['value'],
00052             'File with invalid date metadata (bug 29471)' );
00053     }
00054 
00055     private function dataFile( $name, $type ) {
00056         return new UnregisteredLocalFile( false, $this->repo,
00057             "mwstore://localtesting/data/$name", $type );
00058     }
00059 }