1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
<?php
use MediaWiki\MainConfigNames;
use Wikimedia\TestingAccessWrapper;
/**
* @group Media
* @requires extension exif
*/
class FormatMetadataTest extends MediaWikiMediaTestCase {
protected function setUp(): void {
parent::setUp();
$this->overrideConfigValues( [
MainConfigNames::LanguageCode => 'en',
MainConfigNames::ShowEXIF => true,
] );
}
/**
* @covers \File::formatMetadata
*/
public function testInvalidDate() {
$file = $this->dataFile( 'broken_exif_date.jpg', 'image/jpeg' );
// Throws an error if bug hit
$meta = $file->formatMetadata();
$this->assertIsArray( $meta, 'Valid metadata extracted' );
// Find date exif entry
$this->assertArrayHasKey( 'visible', $meta );
$dateIndex = null;
foreach ( $meta['visible'] as $i => $data ) {
if ( $data['id'] == 'exif-datetimeoriginal' ) {
$dateIndex = $i;
}
}
$this->assertNotNull( $dateIndex, 'Date entry exists in metadata' );
$this->assertSame( '0000:01:00 00:02:27',
$meta['visible'][$dateIndex]['value'],
'File with invalid date metadata (T31471)' );
}
/**
* @dataProvider provideResolveMultivalueValue
* @covers \FormatMetadata::resolveMultivalueValue
*/
public function testResolveMultivalueValue( $input, $output ) {
$formatMetadata = new FormatMetadata();
$class = new ReflectionClass( FormatMetadata::class );
$method = $class->getMethod( 'resolveMultivalueValue' );
$method->setAccessible( true );
$actualInput = $method->invoke( $formatMetadata, $input );
$this->assertEquals( $output, $actualInput );
}
public static function provideResolveMultivalueValue() {
return [
'nonArray' => [
'foo',
'foo'
],
'multiValue' => [
[ 'first', 'second', 'third', '_type' => 'ol' ],
'first'
],
'noType' => [
[ 'first', 'second', 'third' ],
'first'
],
'typeFirst' => [
[ '_type' => 'ol', 'first', 'second', 'third' ],
'first'
],
'multilang' => [
[
'en' => 'first',
'de' => 'Erste',
'_type' => 'lang'
],
[
'en' => 'first',
'de' => 'Erste',
'_type' => 'lang'
],
],
'multilang-multivalue' => [
[
'en' => [ 'first', 'second' ],
'de' => [ 'Erste', 'Zweite' ],
'_type' => 'lang'
],
[
'en' => 'first',
'de' => 'Erste',
'_type' => 'lang'
],
],
];
}
/**
* @dataProvider provideGetFormattedData
* @covers \FormatMetadata::getFormattedData
*/
public function testGetFormattedData( $input, $output ) {
$this->assertEquals( $output, FormatMetadata::getFormattedData( $input ) );
}
public static function provideGetFormattedData() {
return [
[
[ 'Software' => 'Adobe Photoshop CS6 (Macintosh)' ],
[ 'Software' => 'Adobe Photoshop CS6 (Macintosh)' ],
],
[
[ 'Software' => [ 'FotoWare FotoStation' ] ],
[ 'Software' => 'FotoWare FotoStation' ],
],
[
[ 'Software' => [ [ 'Capture One PRO', '3.7.7' ] ] ],
[ 'Software' => 'Capture One PRO (Version 3.7.7)' ],
],
[
[ 'Software' => [ [ 'FotoWare ColorFactory', '' ] ] ],
[ 'Software' => 'FotoWare ColorFactory (Version )' ],
],
[
[ 'Software' => [ 'x-default' => 'paint.net 4.0.12', '_type' => 'lang' ] ],
[ 'Software' => '<ul class="metadata-langlist">' .
'<li class="mw-metadata-lang-default">' .
'<span class="mw-metadata-lang-value">paint.net 4.0.12</span>' .
"</li>\n" .
'</ul>'
],
],
[
// https://phabricator.wikimedia.org/T178130
// WebMHandler.php turns both 'muxingapp' & 'writingapp' to 'Software'
[ 'Software' => [ [ 'Lavf57.25.100' ], [ 'Lavf57.25.100' ] ] ],
[ 'Software' => "<ul><li>Lavf57.25.100</li>\n<li>Lavf57.25.100</li></ul>" ],
],
];
}
/**
* @covers \FormatMetadata::getPriorityLanguages
* @dataProvider provideGetPriorityLanguagesData
* @param string $language
* @param string[] $expected
*/
public function testGetPriorityLanguagesInternal_language_expect(
string $language,
array $expected
): void {
$formatMetadata = TestingAccessWrapper::newFromObject( new FormatMetadata() );
$context = $formatMetadata->getContext();
$context->setLanguage( $this->getServiceContainer()->getLanguageFactory()->getLanguage( $language ) );
$x = $formatMetadata->getPriorityLanguages();
$this->assertSame( $expected, $x );
}
public static function provideGetPriorityLanguagesData() {
return [
'LanguageMl' => [
'ml',
[ 'ml', 'en' ],
],
'LanguageEn' => [
'en',
[ 'en', 'en' ],
],
'LanguageQqx' => [
'qqx',
[ 'qqx', 'en' ],
],
];
}
}
|