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 );
30 * @dataProvider provideSvgUnits
32 public function testScaleSVGUnit( $inUnit, $expected ) {
35 SVGReader
::scaleSVGUnit( $inUnit ),
36 'SVG unit conversion and scaling failure'
40 function assertMetadata( $infile, $expected ) {
42 $data = SVGMetadataExtractor
::getMetadata( $infile );
43 $this->assertEquals( $expected, $data, 'SVG metadata extraction test' );
44 } catch ( MWException
$e ) {
45 if ( $expected === false ) {
46 $this->assertTrue( true, 'SVG metadata extracted test (expected failure)' );
53 public static function provideSvgFiles() {
54 $base = __DIR__
. '/../../data/media';
58 "$base/Wikimedia-logo.svg",
62 'originalWidth' => '1024',
63 'originalHeight' => '1024',
72 'originalWidth' => '60',
73 'originalHeight' => '60',
78 "$base/Gtk-media-play-ltr.svg",
82 'originalWidth' => '60.0000000',
83 'originalHeight' => '60.0000000',
88 "$base/Toll_Texas_1.svg",
89 // This file triggered T33719, needs entity expansion in the xmlns checks
93 'originalWidth' => '385',
94 'originalHeight' => '385.0004883',
103 'originalWidth' => '100%',
104 'originalHeight' => '100%',
106 'translations' => [],
107 'description' => 'For more information see: http://commons.wikimedia.org/wiki/Image:Tux.svg',
111 "$base/Speech_bubbles.svg",
115 'originalWidth' => '17.7cm',
116 'originalHeight' => '13cm',
118 'de' => SVGReader
::LANG_FULL_MATCH
,
119 'fr' => SVGReader
::LANG_FULL_MATCH
,
120 'nl' => SVGReader
::LANG_FULL_MATCH
,
121 'tlh-ca' => SVGReader
::LANG_FULL_MATCH
,
122 'tlh' => SVGReader
::LANG_PREFIX_MATCH
127 "$base/Soccer_ball_animated.svg",
131 'originalWidth' => '150',
132 'originalHeight' => '150',
138 "$base/comma_separated_viewbox.svg",
142 'originalWidth' => '100%',
143 'originalHeight' => '100%',
150 public static function provideSvgFilesWithXMLMetadata() {
151 $base = __DIR__
. '/../../data/media';
152 // phpcs:disable Generic.Files.LineLength
153 $metadata = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
154 <ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about="">
155 <ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format>
156 <ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
161 $metadata = str_replace( "\r", '', $metadata ); // Windows compat
164 "$base/US_states_by_total_state_tax_revenue.svg",
167 'metadata' => $metadata,
169 'originalWidth' => '958.69',
170 'originalHeight' => '592.78998',
171 'translations' => [],
177 public static function provideSvgUnits() {
191 [ '10pt' , 10 * 1.25 ],
192 [ '10pc' , 10 * 15 ],
193 [ '10mm' , 10 * 3.543307 ],
194 [ '10cm' , 10 * 35.43307 ],
195 [ '10in' , 10 * 90 ],
196 [ '10em' , 10 * 16 ],
197 [ '10ex' , 10 * 12 ],