5 * @covers SVGMetadataExtractor
7 class SVGMetadataExtractorTest
extends MediaWikiTestCase
{
9 protected function setUp() {
11 AutoLoader
::loadClass( 'SVGMetadataExtractorTest' );
15 * @dataProvider provideSvgFiles
17 public function testGetMetadata( $infile, $expected ) {
18 $this->assertMetadata( $infile, $expected );
22 * @dataProvider provideSvgFilesWithXMLMetadata
24 public function testGetXMLMetadata( $infile, $expected ) {
26 if ( !method_exists( $r, 'readInnerXML' ) ) {
27 $this->markTestSkipped( 'XMLReader::readInnerXML() does not exist (libxml >2.6.20 needed).' );
31 $this->assertMetadata( $infile, $expected );
34 function assertMetadata( $infile, $expected ) {
36 $data = SVGMetadataExtractor
::getMetadata( $infile );
37 $this->assertEquals( $expected, $data, 'SVG metadata extraction test' );
38 } catch ( MWException
$e ) {
39 if ( $expected === false ) {
40 $this->assertTrue( true, 'SVG metadata extracted test (expected failure)' );
47 public static function provideSvgFiles() {
48 $base = __DIR__
. '/../../data/media';
52 "$base/Wikimedia-logo.svg",
56 'originalWidth' => '1024',
57 'originalHeight' => '1024',
58 'translations' => array(),
66 'originalWidth' => '60',
67 'originalHeight' => '60',
68 'translations' => array(),
72 "$base/Gtk-media-play-ltr.svg",
76 'originalWidth' => '60.0000000',
77 'originalHeight' => '60.0000000',
78 'translations' => array(),
82 "$base/Toll_Texas_1.svg",
83 // This file triggered bug 31719, needs entity expansion in the xmlns checks
87 'originalWidth' => '385',
88 'originalHeight' => '385.0004883',
89 'translations' => array(),
97 'originalWidth' => '100%',
98 'originalHeight' => '100%',
100 'translations' => array(),
101 'description' => 'For more information see: http://commons.wikimedia.org/wiki/Image:Tux.svg',
105 "$base/Speech_bubbles.svg",
109 'originalWidth' => '17.7cm',
110 'originalHeight' => '13cm',
111 'translations' => array(
112 'de' => SVGReader
::LANG_FULL_MATCH
,
113 'fr' => SVGReader
::LANG_FULL_MATCH
,
114 'nl' => SVGReader
::LANG_FULL_MATCH
,
115 'tlh-ca' => SVGReader
::LANG_FULL_MATCH
,
116 'tlh' => SVGReader
::LANG_PREFIX_MATCH
121 "$base/Soccer_ball_animated.svg",
125 'originalWidth' => '150',
126 'originalHeight' => '150',
128 'translations' => array()
134 public static function provideSvgFilesWithXMLMetadata() {
135 $base = __DIR__
. '/../../data/media';
136 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
137 $metadata = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
138 <ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about="">
139 <ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format>
140 <ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
143 // @codingStandardsIgnoreEnd
145 $metadata = str_replace( "\r", '', $metadata ); // Windows compat
148 "$base/US_states_by_total_state_tax_revenue.svg",
151 'metadata' => $metadata,
153 'originalWidth' => '958.69',
154 'originalHeight' => '592.78998',
155 'translations' => array(),