Merge "Added release notes for 'ContentHandler::runLegacyHooks' removal"
[mediawiki.git] / tests / phpunit / includes / media / SVGMetadataExtractorTest.php
blob3049e2f6ef16f56dc351a3d42378684f986ba19f
1 <?php
3 /**
4 * @group Media
5 * @covers SVGMetadataExtractor
6 */
7 class SVGMetadataExtractorTest extends MediaWikiTestCase {
9 /**
10 * @dataProvider provideSvgFiles
12 public function testGetMetadata( $infile, $expected ) {
13 $this->assertMetadata( $infile, $expected );
16 /**
17 * @dataProvider provideSvgFilesWithXMLMetadata
19 public function testGetXMLMetadata( $infile, $expected ) {
20 $r = new XMLReader();
21 if ( !method_exists( $r, 'readInnerXML' ) ) {
22 $this->markTestSkipped( 'XMLReader::readInnerXML() does not exist (libxml >2.6.20 needed).' );
24 return;
26 $this->assertMetadata( $infile, $expected );
29 function assertMetadata( $infile, $expected ) {
30 try {
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)' );
36 } else {
37 throw $e;
42 public static function provideSvgFiles() {
43 $base = __DIR__ . '/../../data/media';
45 return [
47 "$base/Wikimedia-logo.svg",
49 'width' => 1024,
50 'height' => 1024,
51 'originalWidth' => '1024',
52 'originalHeight' => '1024',
53 'translations' => [],
57 "$base/QA_icon.svg",
59 'width' => 60,
60 'height' => 60,
61 'originalWidth' => '60',
62 'originalHeight' => '60',
63 'translations' => [],
67 "$base/Gtk-media-play-ltr.svg",
69 'width' => 60,
70 'height' => 60,
71 'originalWidth' => '60.0000000',
72 'originalHeight' => '60.0000000',
73 'translations' => [],
77 "$base/Toll_Texas_1.svg",
78 // This file triggered bug 31719, needs entity expansion in the xmlns checks
80 'width' => 385,
81 'height' => 385,
82 'originalWidth' => '385',
83 'originalHeight' => '385.0004883',
84 'translations' => [],
88 "$base/Tux.svg",
90 'width' => 512,
91 'height' => 594,
92 'originalWidth' => '100%',
93 'originalHeight' => '100%',
94 'title' => 'Tux',
95 'translations' => [],
96 'description' => 'For more information see: http://commons.wikimedia.org/wiki/Image:Tux.svg',
100 "$base/Speech_bubbles.svg",
102 'width' => 627,
103 'height' => 461,
104 'originalWidth' => '17.7cm',
105 'originalHeight' => '13cm',
106 'translations' => [
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",
118 'width' => 150,
119 'height' => 150,
120 'originalWidth' => '150',
121 'originalHeight' => '150',
122 'animated' => true,
123 'translations' => []
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"/>
136 </ns4:Work>
137 </rdf:RDF>';
138 // @codingStandardsIgnoreEnd
140 $metadata = str_replace( "\r", '', $metadata ); // Windows compat
141 return [
143 "$base/US_states_by_total_state_tax_revenue.svg",
145 'height' => 593,
146 'metadata' => $metadata,
147 'width' => 959,
148 'originalWidth' => '958.69',
149 'originalHeight' => '592.78998',
150 'translations' => [],