Add an interface for getting "standard" file metadata.
[lhc/web/wiklou.git] / tests / phpunit / includes / media / SVGMetadataExtractorTest.php
1 <?php
2
3 class SVGMetadataExtractorTest extends MediaWikiTestCase {
4
5 protected function setUp() {
6 parent::setUp();
7 AutoLoader::loadClass( 'SVGMetadataExtractorTest' );
8 }
9
10 /**
11 * @dataProvider provideSvgFiles
12 */
13 function testGetMetadata( $infile, $expected ) {
14 $this->assertMetadata( $infile, $expected );
15 }
16
17 /**
18 * @dataProvider provideSvgFilesWithXMLMetadata
19 */
20 function testGetXMLMetadata( $infile, $expected ) {
21 $r = new XMLReader();
22 if ( !method_exists( $r, 'readInnerXML' ) ) {
23 $this->markTestSkipped( 'XMLReader::readInnerXML() does not exist (libxml >2.6.20 needed).' );
24
25 return;
26 }
27 $this->assertMetadata( $infile, $expected );
28 }
29
30 function assertMetadata( $infile, $expected ) {
31 try {
32 $data = SVGMetadataExtractor::getMetadata( $infile );
33 $this->assertEquals( $expected, $data, 'SVG metadata extraction test' );
34 } catch ( MWException $e ) {
35 if ( $expected === false ) {
36 $this->assertTrue( true, 'SVG metadata extracted test (expected failure)' );
37 } else {
38 throw $e;
39 }
40 }
41 }
42
43 public static function provideSvgFiles() {
44 $base = __DIR__ . '/../../data/media';
45
46 return array(
47 array(
48 "$base/Wikimedia-logo.svg",
49 array(
50 'width' => 1024,
51 'height' => 1024,
52 'originalWidth' => '1024',
53 'originalHeight' => '1024',
54 )
55 ),
56 array(
57 "$base/QA_icon.svg",
58 array(
59 'width' => 60,
60 'height' => 60,
61 'originalWidth' => '60',
62 'originalHeight' => '60',
63 )
64 ),
65 array(
66 "$base/Gtk-media-play-ltr.svg",
67 array(
68 'width' => 60,
69 'height' => 60,
70 'originalWidth' => '60.0000000',
71 'originalHeight' => '60.0000000',
72 )
73 ),
74 array(
75 "$base/Toll_Texas_1.svg",
76 // This file triggered bug 31719, needs entity expansion in the xmlns checks
77 array(
78 'width' => 385,
79 'height' => 385,
80 'originalWidth' => '385',
81 'originalHeight' => '385.0004883',
82 )
83 ),
84 array(
85 "$base/Tux.svg",
86 array(
87 'width' => 512,
88 'height' => 594,
89 'originalWidth' => '100%',
90 'originalHeight' => '100%',
91 'title' => 'Tux',
92 'description' => 'For more information see: http://commons.wikimedia.org/wiki/Image:Tux.svg',
93 )
94 )
95 );
96 }
97
98 public static function provideSvgFilesWithXMLMetadata() {
99 $base = __DIR__ . '/../../data/media';
100 $metadata = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
101 <ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about="">
102 <ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format>
103 <ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
104 </ns4:Work>
105 </rdf:RDF>';
106 $metadata = str_replace( "\r", '', $metadata ); // Windows compat
107 return array(
108 array(
109 "$base/US_states_by_total_state_tax_revenue.svg",
110 array(
111 'height' => 593,
112 'metadata' => $metadata,
113 'width' => 959,
114 'originalWidth' => '958.69',
115 'originalHeight' => '592.78998',
116 )
117 ),
118 );
119 }
120 }