Added release notes for 'ContentHandler::runLegacyHooks' removal
[mediawiki.git] / tests / phpunit / includes / media / FormatMetadataTest.php
blob3d0724f98e786f92e427dd7633e66565f3538ad9
1 <?php
3 /**
4 * @group Media
5 */
6 class FormatMetadataTest extends MediaWikiMediaTestCase {
8 protected function setUp() {
9 parent::setUp();
11 $this->checkPHPExtension( 'exif' );
12 $this->setMwGlobals( 'wgShowEXIF', true );
15 /**
16 * @covers File::formatMetadata
18 public function testInvalidDate() {
19 $file = $this->dataFile( 'broken_exif_date.jpg', 'image/jpeg' );
21 // Throws an error if bug hit
22 $meta = $file->formatMetadata();
23 $this->assertNotEquals( false, $meta, 'Valid metadata extracted' );
25 // Find date exif entry
26 $this->assertArrayHasKey( 'visible', $meta );
27 $dateIndex = null;
28 foreach ( $meta['visible'] as $i => $data ) {
29 if ( $data['id'] == 'exif-datetimeoriginal' ) {
30 $dateIndex = $i;
33 $this->assertNotNull( $dateIndex, 'Date entry exists in metadata' );
34 $this->assertEquals( '0000:01:00 00:02:27',
35 $meta['visible'][$dateIndex]['value'],
36 'File with invalid date metadata (bug 29471)' );
39 /**
40 * @param mixed $input
41 * @param mixed $output
42 * @dataProvider provideResolveMultivalueValue
43 * @covers FormatMetadata::resolveMultivalueValue
45 public function testResolveMultivalueValue( $input, $output ) {
46 $formatMetadata = new FormatMetadata();
47 $class = new ReflectionClass( 'FormatMetadata' );
48 $method = $class->getMethod( 'resolveMultivalueValue' );
49 $method->setAccessible( true );
50 $actualInput = $method->invoke( $formatMetadata, $input );
51 $this->assertEquals( $output, $actualInput );
54 public function provideResolveMultivalueValue() {
55 return [
56 'nonArray' => [
57 'foo',
58 'foo'
60 'multiValue' => [
61 [ 'first', 'second', 'third', '_type' => 'ol' ],
62 'first'
64 'noType' => [
65 [ 'first', 'second', 'third' ],
66 'first'
68 'typeFirst' => [
69 [ '_type' => 'ol', 'first', 'second', 'third' ],
70 'first'
72 'multilang' => [
74 'en' => 'first',
75 'de' => 'Erste',
76 '_type' => 'lang'
79 'en' => 'first',
80 'de' => 'Erste',
81 '_type' => 'lang'
84 'multilang-multivalue' => [
86 'en' => [ 'first', 'second' ],
87 'de' => [ 'Erste', 'Zweite' ],
88 '_type' => 'lang'
91 'en' => 'first',
92 'de' => 'Erste',
93 '_type' => 'lang'