wiki.techinc.nl/tests/phpunit/includes/media/FormatMetadataTest.php
Sébastien Santoro 241e741377 media: Ensure there ie enough data to extract software version
The Software EXIF / other metadata field was expected to contain
the software name followed by the version number.

There are occurences in Wikimedia production logs of errors showing
that's not always the case.

Bug: T178130
Change-Id: I4187a41b5fd8d7b5574ab50523668d8feb11bccc
2017-12-06 21:16:17 +00:00

144 lines
3.6 KiB
PHP

<?php
/**
* @group Media
*/
class FormatMetadataTest extends MediaWikiMediaTestCase {
protected function setUp() {
parent::setUp();
$this->checkPHPExtension( 'exif' );
$this->setMwGlobals( 'wgShowEXIF', 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->assertNotEquals( false, $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->assertEquals( '0000:01:00 00:02:27',
$meta['visible'][$dateIndex]['value'],
'File with invalid date metadata (T31471)' );
}
/**
* @param mixed $input
* @param mixed $output
* @dataProvider provideResolveMultivalueValue
* @covers FormatMetadata::resolveMultivalueValue
*/
public function testResolveMultivalueValue( $input, $output ) {
$formatMetadata = new FormatMetadata();
$class = new ReflectionClass( 'FormatMetadata' );
$method = $class->getMethod( 'resolveMultivalueValue' );
$method->setAccessible( true );
$actualInput = $method->invoke( $formatMetadata, $input );
$this->assertEquals( $output, $actualInput );
}
public 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'
],
],
];
}
/**
* @param mixed $input
* @param mixed $output
* @dataProvider provideGetFormattedData
* @covers FormatMetadata::getFormattedData
*/
public function testGetFormattedData( $input, $output ) {
$this->assertEquals( $output, FormatMetadata::getFormattedData( $input ) );
}
public 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>" ],
],
];
}
}