gallery: Fix phan annotation for ImageGalleryBase::getImages
[mediawiki.git] / tests / phpunit / includes / media / FormatMetadataTest.php
blob516b87ab906bc0ed07b811dac2f86f230b36af42
1 <?php
3 use MediaWiki\MainConfigNames;
4 use Wikimedia\TestingAccessWrapper;
6 /**
7 * @group Media
8 * @requires extension exif
9 */
10 class FormatMetadataTest extends MediaWikiMediaTestCase {
12 protected function setUp(): void {
13 parent::setUp();
15 $this->overrideConfigValues( [
16 MainConfigNames::LanguageCode => 'en',
17 MainConfigNames::ShowEXIF => true,
18 ] );
21 /**
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 );
33 $dateIndex = null;
34 foreach ( $meta['visible'] as $i => $data ) {
35 if ( $data['id'] == 'exif-datetimeoriginal' ) {
36 $dateIndex = $i;
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)' );
45 /**
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() {
59 return [
60 'nonArray' => [
61 'foo',
62 'foo'
64 'multiValue' => [
65 [ 'first', 'second', 'third', '_type' => 'ol' ],
66 'first'
68 'noType' => [
69 [ 'first', 'second', 'third' ],
70 'first'
72 'typeFirst' => [
73 [ '_type' => 'ol', 'first', 'second', 'third' ],
74 'first'
76 'multilang' => [
78 'en' => 'first',
79 'de' => 'Erste',
80 '_type' => 'lang'
83 'en' => 'first',
84 'de' => 'Erste',
85 '_type' => 'lang'
88 'multilang-multivalue' => [
90 'en' => [ 'first', 'second' ],
91 'de' => [ 'Erste', 'Zweite' ],
92 '_type' => 'lang'
95 'en' => 'first',
96 'de' => 'Erste',
97 '_type' => 'lang'
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() {
112 return [
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>' .
134 "</li>\n" .
135 '</ul>'
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(
154 string $language,
155 array $expected
156 ): void {
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() {
166 return [
167 'LanguageMl' => [
168 'ml',
169 [ 'ml', 'en' ],
171 'LanguageEn' => [
172 'en',
173 [ 'en', 'en' ],
175 'LanguageQqx' => [
176 'qqx',
177 [ 'qqx', 'en' ],