Merge "mediawiki.jqueryMsg: Prevent default action for functions as external link"
[lhc/web/wiklou.git] / tests / phpunit / includes / media / SVGMetadataExtractorTest.php
1 <?php
2
3 /**
4 * @group Media
5 * @covers SVGMetadataExtractor
6 */
7 class SVGMetadataExtractorTest extends MediaWikiTestCase {
8
9 protected function setUp() {
10 parent::setUp();
11 AutoLoader::loadClass( 'SVGMetadataExtractorTest' );
12 }
13
14 /**
15 * @dataProvider provideSvgFiles
16 */
17 public function testGetMetadata( $infile, $expected ) {
18 $this->assertMetadata( $infile, $expected );
19 }
20
21 /**
22 * @dataProvider provideSvgFilesWithXMLMetadata
23 */
24 public function testGetXMLMetadata( $infile, $expected ) {
25 $r = new XMLReader();
26 if ( !method_exists( $r, 'readInnerXML' ) ) {
27 $this->markTestSkipped( 'XMLReader::readInnerXML() does not exist (libxml >2.6.20 needed).' );
28
29 return;
30 }
31 $this->assertMetadata( $infile, $expected );
32 }
33
34 function assertMetadata( $infile, $expected ) {
35 try {
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)' );
41 } else {
42 throw $e;
43 }
44 }
45 }
46
47 public static function provideSvgFiles() {
48 $base = __DIR__ . '/../../data/media';
49
50 return array(
51 array(
52 "$base/Wikimedia-logo.svg",
53 array(
54 'width' => 1024,
55 'height' => 1024,
56 'originalWidth' => '1024',
57 'originalHeight' => '1024',
58 'translations' => array(),
59 )
60 ),
61 array(
62 "$base/QA_icon.svg",
63 array(
64 'width' => 60,
65 'height' => 60,
66 'originalWidth' => '60',
67 'originalHeight' => '60',
68 'translations' => array(),
69 )
70 ),
71 array(
72 "$base/Gtk-media-play-ltr.svg",
73 array(
74 'width' => 60,
75 'height' => 60,
76 'originalWidth' => '60.0000000',
77 'originalHeight' => '60.0000000',
78 'translations' => array(),
79 )
80 ),
81 array(
82 "$base/Toll_Texas_1.svg",
83 // This file triggered bug 31719, needs entity expansion in the xmlns checks
84 array(
85 'width' => 385,
86 'height' => 385,
87 'originalWidth' => '385',
88 'originalHeight' => '385.0004883',
89 'translations' => array(),
90 )
91 ),
92 array(
93 "$base/Tux.svg",
94 array(
95 'width' => 512,
96 'height' => 594,
97 'originalWidth' => '100%',
98 'originalHeight' => '100%',
99 'title' => 'Tux',
100 'translations' => array(),
101 'description' => 'For more information see: http://commons.wikimedia.org/wiki/Image:Tux.svg',
102 )
103 ),
104 array(
105 "$base/Speech_bubbles.svg",
106 array(
107 'width' => 627,
108 'height' => 461,
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
117 ),
118 )
119 ),
120 array(
121 "$base/Soccer_ball_animated.svg",
122 array(
123 'width' => 150,
124 'height' => 150,
125 'originalWidth' => '150',
126 'originalHeight' => '150',
127 'animated' => true,
128 'translations' => array()
129 ),
130 ),
131 );
132 }
133
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"/>
141 </ns4:Work>
142 </rdf:RDF>';
143 // @codingStandardsIgnoreEnd
144
145 $metadata = str_replace( "\r", '', $metadata ); // Windows compat
146 return array(
147 array(
148 "$base/US_states_by_total_state_tax_revenue.svg",
149 array(
150 'height' => 593,
151 'metadata' => $metadata,
152 'width' => 959,
153 'originalWidth' => '958.69',
154 'originalHeight' => '592.78998',
155 'translations' => array(),
156 )
157 ),
158 );
159 }
160 }