3 use MediaWiki\MainConfigNames
;
4 use Wikimedia\TestingAccessWrapper
;
8 * @requires extension exif
10 class FormatMetadataTest
extends MediaWikiMediaTestCase
{
12 protected function setUp(): void
{
15 $this->overrideConfigValues( [
16 MainConfigNames
::LanguageCode
=> 'en',
17 MainConfigNames
::ShowEXIF
=> true,
22 * @covers \File::formatMetadata
24 public function testInvalidDate() {
25 $file = $this->dataFile( 'broken_exif_date.jpg', 'image/jpeg' );
27 // Throws an error if bug hit
28 $meta = $file->formatMetadata();
29 $this->assertIsArray( $meta, 'Valid metadata extracted' );
31 // Find date exif entry
32 $this->assertArrayHasKey( 'visible', $meta );
34 foreach ( $meta['visible'] as $i => $data ) {
35 if ( $data['id'] == 'exif-datetimeoriginal' ) {
39 $this->assertNotNull( $dateIndex, 'Date entry exists in metadata' );
40 $this->assertSame( '0000:01:00 00:02:27',
41 $meta['visible'][$dateIndex]['value'],
42 'File with invalid date metadata (T31471)' );
46 * @dataProvider provideResolveMultivalueValue
47 * @covers \FormatMetadata::resolveMultivalueValue
49 public function testResolveMultivalueValue( $input, $output ) {
50 $formatMetadata = new FormatMetadata();
51 $class = new ReflectionClass( FormatMetadata
::class );
52 $method = $class->getMethod( 'resolveMultivalueValue' );
53 $method->setAccessible( true );
54 $actualInput = $method->invoke( $formatMetadata, $input );
55 $this->assertEquals( $output, $actualInput );
58 public static function provideResolveMultivalueValue() {
65 [ 'first', 'second', 'third', '_type' => 'ol' ],
69 [ 'first', 'second', 'third' ],
73 [ '_type' => 'ol', 'first', 'second', 'third' ],
88 'multilang-multivalue' => [
90 'en' => [ 'first', 'second' ],
91 'de' => [ 'Erste', 'Zweite' ],
104 * @dataProvider provideGetFormattedData
105 * @covers \FormatMetadata::getFormattedData
107 public function testGetFormattedData( $input, $output ) {
108 $this->assertEquals( $output, FormatMetadata
::getFormattedData( $input ) );
111 public static function provideGetFormattedData() {
114 [ 'Software' => 'Adobe Photoshop CS6 (Macintosh)' ],
115 [ 'Software' => 'Adobe Photoshop CS6 (Macintosh)' ],
118 [ 'Software' => [ 'FotoWare FotoStation' ] ],
119 [ 'Software' => 'FotoWare FotoStation' ],
122 [ 'Software' => [ [ 'Capture One PRO', '3.7.7' ] ] ],
123 [ 'Software' => 'Capture One PRO (Version 3.7.7)' ],
126 [ 'Software' => [ [ 'FotoWare ColorFactory', '' ] ] ],
127 [ 'Software' => 'FotoWare ColorFactory (Version )' ],
130 [ 'Software' => [ 'x-default' => 'paint.net 4.0.12', '_type' => 'lang' ] ],
131 [ 'Software' => '<ul class="metadata-langlist">' .
132 '<li class="mw-metadata-lang-default">' .
133 '<span class="mw-metadata-lang-value">paint.net 4.0.12</span>' .
139 // https://phabricator.wikimedia.org/T178130
140 // WebMHandler.php turns both 'muxingapp' & 'writingapp' to 'Software'
141 [ 'Software' => [ [ 'Lavf57.25.100' ], [ 'Lavf57.25.100' ] ] ],
142 [ 'Software' => "<ul><li>Lavf57.25.100</li>\n<li>Lavf57.25.100</li></ul>" ],
148 * @covers \FormatMetadata::getPriorityLanguages
149 * @dataProvider provideGetPriorityLanguagesData
150 * @param string $language
151 * @param string[] $expected
153 public function testGetPriorityLanguagesInternal_language_expect(
157 $formatMetadata = TestingAccessWrapper
::newFromObject( new FormatMetadata() );
158 $context = $formatMetadata->getContext();
159 $context->setLanguage( $this->getServiceContainer()->getLanguageFactory()->getLanguage( $language ) );
161 $x = $formatMetadata->getPriorityLanguages();
162 $this->assertSame( $expected, $x );
165 public static function provideGetPriorityLanguagesData() {