5 * @covers SVGMetadataExtractor
7 class SVGMetadataExtractorTest
extends MediaWikiTestCase
{
10 * @dataProvider provideSvgFiles
12 public function testGetMetadata( $infile, $expected ) {
13 $this->assertMetadata( $infile, $expected );
17 * @dataProvider provideSvgFilesWithXMLMetadata
19 public function testGetXMLMetadata( $infile, $expected ) {
21 if ( !method_exists( $r, 'readInnerXML' ) ) {
22 $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';
47 "$base/Wikimedia-logo.svg",
51 'originalWidth' => '1024',
52 'originalHeight' => '1024',
53 'translations' => array(),
61 'originalWidth' => '60',
62 'originalHeight' => '60',
63 'translations' => array(),
67 "$base/Gtk-media-play-ltr.svg",
71 'originalWidth' => '60.0000000',
72 'originalHeight' => '60.0000000',
73 'translations' => array(),
77 "$base/Toll_Texas_1.svg",
78 // This file triggered bug 31719, needs entity expansion in the xmlns checks
82 'originalWidth' => '385',
83 'originalHeight' => '385.0004883',
84 'translations' => array(),
92 'originalWidth' => '100%',
93 'originalHeight' => '100%',
95 'translations' => array(),
96 'description' => 'For more information see: http://commons.wikimedia.org/wiki/Image:Tux.svg',
100 "$base/Speech_bubbles.svg",
104 'originalWidth' => '17.7cm',
105 'originalHeight' => '13cm',
106 'translations' => array(
107 'de' => SVGReader
::LANG_FULL_MATCH
,
108 'fr' => SVGReader
::LANG_FULL_MATCH
,
109 'nl' => SVGReader
::LANG_FULL_MATCH
,
110 'tlh-ca' => SVGReader
::LANG_FULL_MATCH
,
111 'tlh' => SVGReader
::LANG_PREFIX_MATCH
116 "$base/Soccer_ball_animated.svg",
120 'originalWidth' => '150',
121 'originalHeight' => '150',
123 'translations' => array()
129 public static function provideSvgFilesWithXMLMetadata() {
130 $base = __DIR__
. '/../../data/media';
131 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
132 $metadata = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
133 <ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about="">
134 <ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format>
135 <ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
138 // @codingStandardsIgnoreEnd
140 $metadata = str_replace( "\r", '', $metadata ); // Windows compat
143 "$base/US_states_by_total_state_tax_revenue.svg",
146 'metadata' => $metadata,
148 'originalWidth' => '958.69',
149 'originalHeight' => '592.78998',
150 'translations' => array(),