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