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).' );
27 $this->assertMetadata( $infile, $expected );
30 function assertMetadata( $infile, $expected ) {
32 $data = SVGMetadataExtractor
::getMetadata( $infile );
33 $this->assertEquals( $expected, $data, 'SVG metadata extraction test' );
34 } catch ( MWException
$e ) {
35 if ( $expected === false ) {
36 $this->assertTrue( true, 'SVG metadata extracted test (expected failure)' );
43 public static function provideSvgFiles() {
44 $base = __DIR__
. '/../../data/media';
48 "$base/Wikimedia-logo.svg",
52 'originalWidth' => '1024',
53 'originalHeight' => '1024',
61 'originalWidth' => '60',
62 'originalHeight' => '60',
66 "$base/Gtk-media-play-ltr.svg",
70 'originalWidth' => '60.0000000',
71 'originalHeight' => '60.0000000',
75 "$base/Toll_Texas_1.svg",
76 // This file triggered bug 31719, needs entity expansion in the xmlns checks
80 'originalWidth' => '385',
81 'originalHeight' => '385.0004883',
87 public static function provideSvgFilesWithXMLMetadata() {
88 $base = __DIR__
. '/../../data/media';
89 $metadata = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
90 <ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about="">
91 <ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format>
92 <ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
95 $metadata = str_replace( "\r", '', $metadata ); // Windows compat
98 "$base/US_states_by_total_state_tax_revenue.svg",
101 'metadata' => $metadata,
103 'originalWidth' => '958.69',
104 'originalHeight' => '592.78998',