wiki.techinc.nl/tests/phpunit/includes/media/FormatMetadataTest.php
James D. Forrester 1e9c361960 tests: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

Change-Id: I46261416f7603558dceb76ebe695a5cac274e417
2017-02-21 02:14:34 +00:00

98 lines
2.2 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'
],
],
];
}
}