3 class FormatMetadataTest
extends MediaWikiTestCase
{
5 /** @var FSFileBackend */
10 protected function setUp() {
13 if ( !extension_loaded( 'exif' ) ) {
14 $this->markTestSkipped( "This test needs the exif extension." );
16 $filePath = __DIR__
. '/../../data/media';
17 $this->backend
= new FSFileBackend( array(
18 'name' => 'localtesting',
19 'lockManager' => 'nullLockManager',
20 'containerPaths' => array( 'data' => $filePath )
22 $this->repo
= new FSRepo( array(
24 'url' => 'http://localhost/thumbtest',
25 'backend' => $this->backend
28 $this->setMwGlobals( 'wgShowEXIF', true );
32 * @covers File::formatMetadata
34 public function testInvalidDate() {
35 $file = $this->dataFile( 'broken_exif_date.jpg', 'image/jpeg' );
37 // Throws an error if bug hit
38 $meta = $file->formatMetadata();
39 $this->assertNotEquals( false, $meta, 'Valid metadata extracted' );
41 // Find date exif entry
42 $this->assertArrayHasKey( 'visible', $meta );
44 foreach ( $meta['visible'] as $i => $data ) {
45 if ( $data['id'] == 'exif-datetimeoriginal' ) {
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)' );
56 * @param $filename String
57 * @param $expected Integer Total image area
58 * @dataProvider provideFlattenArray
59 * @covers FormatMetadata::flattenArray
61 public function testFlattenArray( $vals, $type, $noHtml, $ctx, $expected ) {
62 $actual = FormatMetadata
::flattenArray( $vals, $type, $noHtml, $ctx );
63 $this->assertEquals( $expected, $actual );
66 public static function provideFlattenArray() {
69 array( 1, 2, 3 ), 'ul', false, false,
70 "<ul><li>1</li>\n<li>2</li>\n<li>3</li></ul>",
73 array( 1, 2, 3 ), 'ol', false, false,
74 "<ol><li>1</li>\n<li>2</li>\n<li>3</li></ol>",
77 array( 1, 2, 3 ), 'ul', true, false,
81 array( 1, 2, 3 ), 'ol', true, false,
84 // TODO: more test cases
88 private function dataFile( $name, $type ) {
89 return new UnregisteredLocalFile( false, $this->repo
,
90 "mwstore://localtesting/data/$name", $type );