4 * @covers SVGMetadataExtractor
6 class SVGMetadataExtractorTest
extends MediaWikiTestCase
{
8 protected function setUp() {
10 AutoLoader
::loadClass( 'SVGMetadataExtractorTest' );
14 * @dataProvider provideSvgFiles
16 public function testGetMetadata( $infile, $expected ) {
17 $this->assertMetadata( $infile, $expected );
21 * @dataProvider provideSvgFilesWithXMLMetadata
23 public function testGetXMLMetadata( $infile, $expected ) {
25 if ( !method_exists( $r, 'readInnerXML' ) ) {
26 $this->markTestSkipped( 'XMLReader::readInnerXML() does not exist (libxml >2.6.20 needed).' );
30 $this->assertMetadata( $infile, $expected );
33 function assertMetadata( $infile, $expected ) {
35 $data = SVGMetadataExtractor
::getMetadata( $infile );
36 $this->assertEquals( $expected, $data, 'SVG metadata extraction test' );
37 } catch ( MWException
$e ) {
38 if ( $expected === false ) {
39 $this->assertTrue( true, 'SVG metadata extracted test (expected failure)' );
46 public static function provideSvgFiles() {
47 $base = __DIR__
. '/../../data/media';
51 "$base/Wikimedia-logo.svg",
55 'originalWidth' => '1024',
56 'originalHeight' => '1024',
57 'translations' => array(),
65 'originalWidth' => '60',
66 'originalHeight' => '60',
67 'translations' => array(),
71 "$base/Gtk-media-play-ltr.svg",
75 'originalWidth' => '60.0000000',
76 'originalHeight' => '60.0000000',
77 'translations' => array(),
81 "$base/Toll_Texas_1.svg",
82 // This file triggered bug 31719, needs entity expansion in the xmlns checks
86 'originalWidth' => '385',
87 'originalHeight' => '385.0004883',
88 'translations' => array(),
96 'originalWidth' => '100%',
97 'originalHeight' => '100%',
99 'translations' => array(),
100 'description' => 'For more information see: http://commons.wikimedia.org/wiki/Image:Tux.svg',
104 "$base/Speech_bubbles.svg",
108 'originalWidth' => '17.7cm',
109 'originalHeight' => '13cm',
110 'translations' => array(
111 'de' => SVGReader
::LANG_FULL_MATCH
,
112 'fr' => SVGReader
::LANG_FULL_MATCH
,
113 'nl' => SVGReader
::LANG_FULL_MATCH
,
114 'tlh-ca' => SVGReader
::LANG_FULL_MATCH
,
115 'tlh' => SVGReader
::LANG_PREFIX_MATCH
122 public static function provideSvgFilesWithXMLMetadata() {
123 $base = __DIR__
. '/../../data/media';
124 $metadata = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
125 <ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about="">
126 <ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format>
127 <ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
130 $metadata = str_replace( "\r", '', $metadata ); // Windows compat
133 "$base/US_states_by_total_state_tax_revenue.svg",
136 'metadata' => $metadata,
138 'originalWidth' => '958.69',
139 'originalHeight' => '592.78998',
140 'translations' => array(),