3 class FormatMetadataTest
extends MediaWikiTestCase
{
5 /** @var FSFileBackend */
10 protected function setUp() {
13 $this->checkPHPExtension( 'exif' );
14 $filePath = __DIR__
. '/../../data/media';
15 $this->backend
= new FSFileBackend( array(
16 'name' => 'localtesting',
17 'wikiId' => wfWikiId(),
18 'containerPaths' => array( 'data' => $filePath )
20 $this->repo
= new FSRepo( array(
22 'url' => 'http://localhost/thumbtest',
23 'backend' => $this->backend
26 $this->setMwGlobals( 'wgShowEXIF', true );
30 * @covers File::formatMetadata
32 public function testInvalidDate() {
33 $file = $this->dataFile( 'broken_exif_date.jpg', 'image/jpeg' );
35 // Throws an error if bug hit
36 $meta = $file->formatMetadata();
37 $this->assertNotEquals( false, $meta, 'Valid metadata extracted' );
39 // Find date exif entry
40 $this->assertArrayHasKey( 'visible', $meta );
42 foreach ( $meta['visible'] as $i => $data ) {
43 if ( $data['id'] == 'exif-datetimeoriginal' ) {
47 $this->assertNotNull( $dateIndex, 'Date entry exists in metadata' );
48 $this->assertEquals( '0000:01:00 00:02:27',
49 $meta['visible'][$dateIndex]['value'],
50 'File with invalid date metadata (bug 29471)' );
54 * @param string $filename
55 * @param int $expected Total image area
56 * @dataProvider provideFlattenArray
57 * @covers FormatMetadata::flattenArray
59 public function testFlattenArray( $vals, $type, $noHtml, $ctx, $expected ) {
60 $actual = FormatMetadata
::flattenArray( $vals, $type, $noHtml, $ctx );
61 $this->assertEquals( $expected, $actual );
64 public static function provideFlattenArray() {
67 array( 1, 2, 3 ), 'ul', false, false,
68 "<ul><li>1</li>\n<li>2</li>\n<li>3</li></ul>",
71 array( 1, 2, 3 ), 'ol', false, false,
72 "<ol><li>1</li>\n<li>2</li>\n<li>3</li></ol>",
75 array( 1, 2, 3 ), 'ul', true, false,
79 array( 1, 2, 3 ), 'ol', true, false,
82 // TODO: more test cases
86 private function dataFile( $name, $type ) {
87 return new UnregisteredLocalFile( false, $this->repo
,
88 "mwstore://localtesting/data/$name", $type );