Merge "Follow-up I0b781c11 (2a55449): use User::getAutomaticGroups()."
[lhc/web/wiklou.git] / tests / phpunit / includes / media / SVGMetadataExtractorTest.php
1 <?php
2
3 class SVGMetadataExtractorTest extends MediaWikiTestCase {
4
5 function setUp() {
6 AutoLoader::loadClass( 'SVGMetadataExtractorTest' );
7 }
8
9 /**
10 * @dataProvider providerSvgFiles
11 */
12 function testGetMetadata( $infile, $expected ) {
13 $this->assertMetadata( $infile, $expected );
14 }
15
16 /**
17 * @dataProvider providerSvgFilesWithXMLMetadata
18 */
19 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 return;
24 }
25 $this->assertMetadata( $infile, $expected );
26 }
27
28 function assertMetadata( $infile, $expected ) {
29 try {
30 $data = SVGMetadataExtractor::getMetadata( $infile );
31 $this->assertEquals( $expected, $data, 'SVG metadata extraction test' );
32 } catch ( MWException $e ) {
33 if ( $expected === false ) {
34 $this->assertTrue( true, 'SVG metadata extracted test (expected failure)' );
35 } else {
36 throw $e;
37 }
38 }
39 }
40
41 function providerSvgFiles() {
42 $base = __DIR__ . '/../../data/media';
43 return array(
44 array(
45 "$base/Wikimedia-logo.svg",
46 array(
47 'width' => 1024,
48 'height' => 1024,
49 'originalWidth' => '1024',
50 'originalHeight' => '1024',
51 )
52 ),
53 array(
54 "$base/QA_icon.svg",
55 array(
56 'width' => 60,
57 'height' => 60,
58 'originalWidth' => '60',
59 'originalHeight' => '60',
60 )
61 ),
62 array(
63 "$base/Gtk-media-play-ltr.svg",
64 array(
65 'width' => 60,
66 'height' => 60,
67 'originalWidth' => '60.0000000',
68 'originalHeight' => '60.0000000',
69 )
70 ),
71 array(
72 "$base/Toll_Texas_1.svg",
73 // This file triggered bug 31719, needs entity expansion in the xmlns checks
74 array(
75 'width' => 385,
76 'height' => 385,
77 'originalWidth' => '385',
78 'originalHeight' => '385.0004883',
79 )
80 )
81 );
82 }
83
84 function providerSvgFilesWithXMLMetadata() {
85 $base = __DIR__ . '/../../data/media';
86 $metadata =
87 '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
88 <ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about="">
89 <ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format>
90 <ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
91 </ns4:Work>
92 </rdf:RDF>';
93 $metadata = str_replace( "\r", '', $metadata ); // Windows compat
94 return array(
95 array(
96 "$base/US_states_by_total_state_tax_revenue.svg",
97 array(
98 'height' => 593,
99 'metadata' => $metadata,
100 'width' => 959,
101 'originalWidth' => '958.69',
102 'originalHeight' => '592.78998',
103 )
104 ),
105 );
106 }
107 }
108