Merge "New paragraphs wrapping tests in the presence of comments & WS lines."
[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 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 return array(
45 array(
46 "$base/Wikimedia-logo.svg",
47 array(
48 'width' => 1024,
49 'height' => 1024,
50 'originalWidth' => '1024',
51 'originalHeight' => '1024',
52 )
53 ),
54 array(
55 "$base/QA_icon.svg",
56 array(
57 'width' => 60,
58 'height' => 60,
59 'originalWidth' => '60',
60 'originalHeight' => '60',
61 )
62 ),
63 array(
64 "$base/Gtk-media-play-ltr.svg",
65 array(
66 'width' => 60,
67 'height' => 60,
68 'originalWidth' => '60.0000000',
69 'originalHeight' => '60.0000000',
70 )
71 ),
72 array(
73 "$base/Toll_Texas_1.svg",
74 // This file triggered bug 31719, needs entity expansion in the xmlns checks
75 array(
76 'width' => 385,
77 'height' => 385,
78 'originalWidth' => '385',
79 'originalHeight' => '385.0004883',
80 )
81 )
82 );
83 }
84
85 public static function provideSvgFilesWithXMLMetadata() {
86 $base = __DIR__ . '/../../data/media';
87 $metadata = '<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 }