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