mw.Map: add ability to map over an existing object other than 'window'
[lhc/web/wiklou.git] / tests / phpunit / includes / media / FormatMetadataTest.php
1 <?php
2
3 class FormatMetadataTest extends MediaWikiTestCase {
4
5 /** @var FSFileBackend */
6 protected $backend;
7 /** @var FSRepo */
8 protected $repo;
9
10 protected function setUp() {
11 parent::setUp();
12
13 if ( !extension_loaded( 'exif' ) ) {
14 $this->markTestSkipped( "This test needs the exif extension." );
15 }
16 $filePath = __DIR__ . '/../../data/media';
17 $this->backend = new FSFileBackend( array(
18 'name' => 'localtesting',
19 'lockManager' => 'nullLockManager',
20 'containerPaths' => array( 'data' => $filePath )
21 ) );
22 $this->repo = new FSRepo( array(
23 'name' => 'temp',
24 'url' => 'http://localhost/thumbtest',
25 'backend' => $this->backend
26 ) );
27
28 $this->setMwGlobals( 'wgShowEXIF', true );
29 }
30
31 /**
32 * @covers File::formatMetadata
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 }