3 class SVGMetadataExtractorTest
extends MediaWikiTestCase
{
5 protected function setUp() {
7 AutoLoader
::loadClass( 'SVGMetadataExtractorTest' );
11 * @dataProvider provideSvgFiles
13 function testGetMetadata( $infile, $expected ) {
14 $this->assertMetadata( $infile, $expected );
18 * @dataProvider provideSvgFilesWithXMLMetadata
20 function testGetXMLMetadata( $infile, $expected ) {
22 if( !method_exists( $r, 'readInnerXML' ) ) {
23 $this->markTestSkipped( 'XMLReader::readInnerXML() does not exist (libxml >2.6.20 needed).' );
26 $this->assertMetadata( $infile, $expected );
29 function assertMetadata( $infile, $expected ) {
31 $data = SVGMetadataExtractor
::getMetadata( $infile );
32 $this->assertEquals( $expected, $data, 'SVG metadata extraction test' );
33 } catch ( MWException
$e ) {
34 if ( $expected === false ) {
35 $this->assertTrue( true, 'SVG metadata extracted test (expected failure)' );
42 public static function provideSvgFiles() {
43 $base = __DIR__
. '/../../data/media';
46 "$base/Wikimedia-logo.svg",
50 'originalWidth' => '1024',
51 'originalHeight' => '1024',
59 'originalWidth' => '60',
60 'originalHeight' => '60',
64 "$base/Gtk-media-play-ltr.svg",
68 'originalWidth' => '60.0000000',
69 'originalHeight' => '60.0000000',
73 "$base/Toll_Texas_1.svg",
74 // This file triggered bug 31719, needs entity expansion in the xmlns checks
78 'originalWidth' => '385',
79 'originalHeight' => '385.0004883',
85 public static function provideSvgFilesWithXMLMetadata() {
86 $base = __DIR__
. '/../../data/media';
88 '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
89 <ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about="">
90 <ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format>
91 <ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
94 $metadata = str_replace( "\r", '', $metadata ); // Windows compat
97 "$base/US_states_by_total_state_tax_revenue.svg",
100 'metadata' => $metadata,
102 'originalWidth' => '958.69',
103 'originalHeight' => '592.78998',