5 * @covers SVGMetadataExtractor
7 class SVGMetadataExtractorTest
extends \MediaWikiIntegrationTestCase
{
10 * @dataProvider provideSvgFiles
12 public function testGetMetadata( $infile, $expected ) {
13 $this->assertMetadata( $infile, $expected );
17 * @dataProvider provideSvgFilesWithXMLMetadata
19 public function testGetXMLMetadata( $infile, $expected ) {
21 $this->assertMetadata( $infile, $expected );
25 * @dataProvider provideSvgUnits
27 public function testScaleSVGUnit( $inUnit, $expected ) {
30 SVGReader
::scaleSVGUnit( $inUnit ),
31 'SVG unit conversion and scaling failure'
35 function assertMetadata( $infile, $expected ) {
37 $data = SVGMetadataExtractor
::getMetadata( $infile );
38 $this->assertEquals( $expected, $data, 'SVG metadata extraction test' );
39 } catch ( MWException
$e ) {
40 if ( $expected === false ) {
41 $this->assertTrue( true, 'SVG metadata extracted test (expected failure)' );
48 public static function provideSvgFiles() {
49 $base = __DIR__
. '/../../data/media';
53 "$base/Wikimedia-logo.svg",
57 'originalWidth' => '1024',
58 'originalHeight' => '1024',
67 'originalWidth' => '60',
68 'originalHeight' => '60',
73 "$base/Gtk-media-play-ltr.svg",
77 'originalWidth' => '60.0000000',
78 'originalHeight' => '60.0000000',
83 "$base/Toll_Texas_1.svg",
84 // This file triggered T33719, needs entity expansion in the xmlns checks
88 'originalWidth' => '385',
89 'originalHeight' => '385.0004883',
98 'originalWidth' => '100%',
99 'originalHeight' => '100%',
101 'translations' => [],
102 'description' => 'For more information see: http://commons.wikimedia.org/wiki/Image:Tux.svg',
106 "$base/Speech_bubbles.svg",
110 'originalWidth' => '17.7cm',
111 'originalHeight' => '13cm',
113 'de' => SVGReader
::LANG_FULL_MATCH
,
114 'fr' => SVGReader
::LANG_FULL_MATCH
,
115 'nl' => SVGReader
::LANG_FULL_MATCH
,
116 'tlh-ca' => SVGReader
::LANG_FULL_MATCH
,
117 'tlh' => SVGReader
::LANG_PREFIX_MATCH
122 "$base/Soccer_ball_animated.svg",
126 'originalWidth' => '150',
127 'originalHeight' => '150',
133 "$base/comma_separated_viewbox.svg",
137 'originalWidth' => '100%',
138 'originalHeight' => '100%',
145 public static function provideSvgFilesWithXMLMetadata() {
146 $base = __DIR__
. '/../../data/media';
147 // phpcs:disable Generic.Files.LineLength
148 $metadata = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
149 <ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about="">
150 <ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format>
151 <ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
156 $metadata = str_replace( "\r", '', $metadata ); // Windows compat
159 "$base/US_states_by_total_state_tax_revenue.svg",
162 'metadata' => $metadata,
164 'originalWidth' => '958.69',
165 'originalHeight' => '592.78998',
166 'translations' => [],
172 public static function provideSvgUnits() {
186 [ '10pt' , 10 * 1.25 ],
187 [ '10pc' , 10 * 15 ],
188 [ '10mm' , 10 * 3.543307 ],
189 [ '10cm' , 10 * 35.43307 ],
190 [ '10in' , 10 * 90 ],
191 [ '10em' , 10 * 16 ],
192 [ '10ex' , 10 * 12 ],