wiki.techinc.nl/tests/phpunit/includes/media/MediaHandlerIntegrationTest.php
C. Scott Ananian 916a1777ef Provide mechanism for MediaHandlers to override metadata formatting
This avoids the incorrect use of the default formatting, which (for
extension tags not handled in core) will usually assume the tag value
is numeric.

Bug: T266677
Change-Id: I184a7976f2e63f2e70a87257d7749af688659c9d
2020-10-30 11:50:08 -04:00

82 lines
2.1 KiB
PHP

<?php
/**
* @group Media
*/
class MediaHandlerIntegrationTest extends MediaWikiMediaTestCase {
/**
* @covers MediaHandler::formatTag
* @covers MediaHandler::formatMetadataHelper
*/
public function testFormatMetadataHelper() {
$testHandler = new class extends MediaHandler {
public function formatMetadata( $image, $context = false ) {
return $this->formatMetadataHelper( [
'UnitTestOverride' => 'abc',
'UnitTestDelete' => 'def',
'UnitTestOther' => '1234.5678',
], $context );
}
protected function formatTag( $key, $vals, $context = false ) {
if ( $key === 'UnitTestOverride' ) {
return 'Override';
} elseif ( $key === 'UnitTestDelete' ) {
return null;
} else {
return false;
}
}
public function getParamMap() {
throw new Exception( 'should never get here' );
}
public function validateParam( $name, $value ) {
throw new Exception( 'should never get here' );
}
public function makeParamString( $params ) {
throw new Exception( 'should never get here' );
}
public function parseParamString( $str ) {
throw new Exception( 'should never get here' );
}
public function normaliseParams( $image, &$params ) {
throw new Exception( 'should never get here' );
}
public function getImageSize( $image, $path ) {
throw new Exception( 'should never get here' );
}
public function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
throw new Exception( 'should never get here' );
}
};
$file = $this->dataFile( 'Tux.svg', 'image/svg+xml' );
$result = $testHandler->formatMetadata( $file );
$this->assertEqualsCanonicalizing( [
'visible' => [
],
'collapsed' => [
[
'id' => 'exif-unittestoverride',
'name' => 'unittestoverride',
// Note that formatTag overrode the formatted result here
'value' => 'Override'
],
[
'id' => 'exif-unittestother',
'name' => 'unittestother',
// Note that this value went through Language::formatNum()
'value' => '1,234.5678'
],
// Note that unittestdelete is missing as expected
],
], $result );
}
}