0241aec4b51963ba646c078e448758c90df98f46
[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 /**
10 * @dataProvider provideSvgFiles
11 */
12 public function testGetMetadata( $infile, $expected ) {
13 $this->assertMetadata( $infile, $expected );
14 }
15
16 /**
17 * @dataProvider provideSvgFilesWithXMLMetadata
18 */
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).' );
23
24 return;
25 }
26 $this->assertMetadata( $infile, $expected );
27 }
28
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;
38 }
39 }
40 }
41
42 public static function provideSvgFiles() {
43 $base = __DIR__ . '/../../data/media';
44
45 return array(
46 array(
47 "$base/Wikimedia-logo.svg",
48 array(
49 'width' => 1024,
50 'height' => 1024,
51 'originalWidth' => '1024',
52 'originalHeight' => '1024',
53 'translations' => array(),
54 )
55 ),
56 array(
57 "$base/QA_icon.svg",
58 array(
59 'width' => 60,
60 'height' => 60,
61 'originalWidth' => '60',
62 'originalHeight' => '60',
63 'translations' => array(),
64 )
65 ),
66 array(
67 "$base/Gtk-media-play-ltr.svg",
68 array(
69 'width' => 60,
70 'height' => 60,
71 'originalWidth' => '60.0000000',
72 'originalHeight' => '60.0000000',
73 'translations' => array(),
74 )
75 ),
76 array(
77 "$base/Toll_Texas_1.svg",
78 // This file triggered bug 31719, needs entity expansion in the xmlns checks
79 array(
80 'width' => 385,
81 'height' => 385,
82 'originalWidth' => '385',
83 'originalHeight' => '385.0004883',
84 'translations' => array(),
85 )
86 ),
87 array(
88 "$base/Tux.svg",
89 array(
90 'width' => 512,
91 'height' => 594,
92 'originalWidth' => '100%',
93 'originalHeight' => '100%',
94 'title' => 'Tux',
95 'translations' => array(),
96 'description' => 'For more information see: http://commons.wikimedia.org/wiki/Image:Tux.svg',
97 )
98 ),
99 array(
100 "$base/Speech_bubbles.svg",
101 array(
102 'width' => 627,
103 'height' => 461,
104 'originalWidth' => '17.7cm',
105 'originalHeight' => '13cm',
106 'translations' => array(
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
112 ),
113 )
114 ),
115 array(
116 "$base/Soccer_ball_animated.svg",
117 array(
118 'width' => 150,
119 'height' => 150,
120 'originalWidth' => '150',
121 'originalHeight' => '150',
122 'animated' => true,
123 'translations' => array()
124 ),
125 ),
126 );
127 }
128
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
139
140 $metadata = str_replace( "\r", '', $metadata ); // Windows compat
141 return array(
142 array(
143 "$base/US_states_by_total_state_tax_revenue.svg",
144 array(
145 'height' => 593,
146 'metadata' => $metadata,
147 'width' => 959,
148 'originalWidth' => '958.69',
149 'originalHeight' => '592.78998',
150 'translations' => array(),
151 )
152 ),
153 );
154 }
155 }