Follow-up r92635 Make sure the Exif related tests handle not having the Exif extensio...
[lhc/web/wiklou.git] / tests / phpunit / includes / media / FormatMetadataTest.php
1 <?php
2 class FormatMetadataTest extends MediaWikiTestCase {
3 public function setUp() {
4 if ( !wfDl( 'exif' ) ) {
5 $this->markTestSkipped( "This test needs the exif extension." );
6 }
7 global $wgShowEXIF;
8 $this->show = $wgShowEXIF;
9 $wgShowEXIF = true;
10 }
11 public function tearDown() {
12 global $wgShowEXIF;
13 $wgShowEXIF = $this->show;
14 }
15
16 public function testInvalidDate() {
17 $file = UnregisteredLocalFile::newFromPath( dirname( __FILE__ ) .
18 '/../../data/media/broken_exif_date.jpg', 'image/jpeg' );
19
20 // Throws an error if bug hit
21 $meta = $file->formatMetadata();
22 $this->assertNotEquals( false, $meta, 'Valid metadata extracted' );
23
24 // Find date exif entry
25 $this->assertArrayHasKey( 'visible', $meta );
26 $dateIndex = null;
27 foreach ( $meta['visible'] as $i => $data ) {
28 if ( $data['id'] == 'exif-datetimeoriginal' ) {
29 $dateIndex = $i;
30 }
31 }
32 $this->assertNotNull( $dateIndex, 'Date entry exists in metadata' );
33 $this->assertEquals( '0000:01:00 00:02:27',
34 $meta['visible'][$dateIndex]['value'],
35 'File with invalid date metadata (bug 29471)' );
36 }
37 }