a4f71db547dafc4edc21825b9f44ec2c2bd075e4
[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 /**
56 * @param $filename String
57 * @param $expected Integer Total image area
58 * @dataProvider provideFlattenArray
59 * @covers FormatMetadata::flattenArray
60 */
61 public function testFlattenArray( $vals, $type, $noHtml, $ctx, $expected ) {
62 $actual = FormatMetadata::flattenArray( $vals, $type, $noHtml, $ctx );
63 $this->assertEquals( $expected, $actual );
64 }
65
66 public static function provideFlattenArray() {
67 return array(
68 array(
69 array( 1, 2, 3 ), 'ul', false, false,
70 "<ul><li>1</li>\n<li>2</li>\n<li>3</li></ul>",
71 ),
72 array(
73 array( 1, 2, 3 ), 'ol', false, false,
74 "<ol><li>1</li>\n<li>2</li>\n<li>3</li></ol>",
75 ),
76 array(
77 array( 1, 2, 3 ), 'ul', true, false,
78 "\n*1\n*2\n*3",
79 ),
80 array(
81 array( 1, 2, 3 ), 'ol', true, false,
82 "\n#1\n#2\n#3",
83 ),
84 // TODO: more test cases
85 );
86 }
87
88 private function dataFile( $name, $type ) {
89 return new UnregisteredLocalFile( false, $this->repo,
90 "mwstore://localtesting/data/$name", $type );
91 }
92 }