2011-06-19 21:38:58 +00:00
|
|
|
<?php
|
|
|
|
|
class FormatMetadataTest extends MediaWikiTestCase {
|
2012-10-08 10:56:20 +00:00
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
2013-10-09 16:46:57 +00:00
|
|
|
if ( !extension_loaded( 'exif' ) ) {
|
2011-09-18 01:53:09 +00:00
|
|
|
$this->markTestSkipped( "This test needs the exif extension." );
|
2011-06-29 20:24:53 +00:00
|
|
|
}
|
2013-02-15 10:17:52 +00:00
|
|
|
$filePath = __DIR__ . '/../../data/media';
|
2011-12-20 03:52:06 +00:00
|
|
|
$this->backend = new FSFileBackend( array(
|
2013-02-15 10:17:52 +00:00
|
|
|
'name' => 'localtesting',
|
|
|
|
|
'lockManager' => 'nullLockManager',
|
2011-12-20 03:52:06 +00:00
|
|
|
'containerPaths' => array( 'data' => $filePath )
|
|
|
|
|
) );
|
|
|
|
|
$this->repo = new FSRepo( array(
|
2013-02-15 10:17:52 +00:00
|
|
|
'name' => 'temp',
|
|
|
|
|
'url' => 'http://localhost/thumbtest',
|
2011-12-20 03:52:06 +00:00
|
|
|
'backend' => $this->backend
|
|
|
|
|
) );
|
2012-10-08 10:56:20 +00:00
|
|
|
|
|
|
|
|
$this->setMwGlobals( 'wgShowEXIF', true );
|
2011-09-18 01:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testInvalidDate() {
|
2011-12-20 03:52:06 +00:00
|
|
|
$file = $this->dataFile( 'broken_exif_date.jpg', 'image/jpeg' );
|
2013-02-15 10:17:52 +00:00
|
|
|
|
2011-06-19 21:38:58 +00:00
|
|
|
// Throws an error if bug hit
|
|
|
|
|
$meta = $file->formatMetadata();
|
2011-06-29 20:24:53 +00:00
|
|
|
$this->assertNotEquals( false, $meta, 'Valid metadata extracted' );
|
2013-02-15 10:17:52 +00:00
|
|
|
|
2011-06-19 21:38:58 +00:00
|
|
|
// Find date exif entry
|
|
|
|
|
$this->assertArrayHasKey( 'visible', $meta );
|
|
|
|
|
$dateIndex = null;
|
|
|
|
|
foreach ( $meta['visible'] as $i => $data ) {
|
|
|
|
|
if ( $data['id'] == 'exif-datetimeoriginal' ) {
|
|
|
|
|
$dateIndex = $i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->assertNotNull( $dateIndex, 'Date entry exists in metadata' );
|
2013-02-15 10:17:52 +00:00
|
|
|
$this->assertEquals( '0000:01:00 00:02:27',
|
2011-06-19 21:38:58 +00:00
|
|
|
$meta['visible'][$dateIndex]['value'],
|
|
|
|
|
'File with invalid date metadata (bug 29471)' );
|
|
|
|
|
}
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
private function dataFile( $name, $type ) {
|
|
|
|
|
return new UnregisteredLocalFile( false, $this->repo,
|
|
|
|
|
"mwstore://localtesting/data/$name", $type );
|
|
|
|
|
}
|
2011-07-20 15:35:48 +00:00
|
|
|
}
|