Cleanup tests/includes/media
[lhc/web/wiklou.git] / tests / phpunit / includes / media / FormatMetadataTest.php
1 <?php
2
3 /**
4 * @todo covers tags
5 */
6 class FormatMetadataTest extends MediaWikiTestCase {
7
8 /** @var FSFileBackend */
9 protected $backend;
10 /** @var FSRepo */
11 protected $repo;
12
13 protected function setUp() {
14 parent::setUp();
15
16 if ( !extension_loaded( 'exif' ) ) {
17 $this->markTestSkipped( "This test needs the exif extension." );
18 }
19 $filePath = __DIR__ . '/../../data/media';
20 $this->backend = new FSFileBackend( array(
21 'name' => 'localtesting',
22 'lockManager' => 'nullLockManager',
23 'containerPaths' => array( 'data' => $filePath )
24 ) );
25 $this->repo = new FSRepo( array(
26 'name' => 'temp',
27 'url' => 'http://localhost/thumbtest',
28 'backend' => $this->backend
29 ) );
30
31 $this->setMwGlobals( 'wgShowEXIF', true );
32 }
33
34 public function testInvalidDate() {
35 $file = $this->dataFile( 'broken_exif_date.jpg', 'image/jpeg' );
36
37 // Throws an error if bug hit
38 $meta = $file->formatMetadata();
39 $this->assertNotEquals( false, $meta, 'Valid metadata extracted' );
40
41 // Find date exif entry
42 $this->assertArrayHasKey( 'visible', $meta );
43 $dateIndex = null;
44 foreach ( $meta['visible'] as $i => $data ) {
45 if ( $data['id'] == 'exif-datetimeoriginal' ) {
46 $dateIndex = $i;
47 }
48 }
49 $this->assertNotNull( $dateIndex, 'Date entry exists in metadata' );
50 $this->assertEquals( '0000:01:00 00:02:27',
51 $meta['visible'][$dateIndex]['value'],
52 'File with invalid date metadata (bug 29471)' );
53 }
54
55 private function dataFile( $name, $type ) {
56 return new UnregisteredLocalFile( false, $this->repo,
57 "mwstore://localtesting/data/$name", $type );
58 }
59 }