Revert "Revert "jQuery 1.8""
[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 = dirname( __FILE__ ) . '/../../data/media';
43 return array(
44 array(
45 "$base/Wikimedia-logo.svg",
46 array(
47 'width' => 1024,
48 'height' => 1024
49 )
50 ),
51 array(
52 "$base/QA_icon.svg",
53 array(
54 'width' => 60,
55 'height' => 60
56 )
57 ),
58 array(
59 "$base/Gtk-media-play-ltr.svg",
60 array(
61 'width' => 60,
62 'height' => 60
63 )
64 ),
65 array(
66 "$base/Toll_Texas_1.svg",
67 // This file triggered bug 31719, needs entity expansion in the xmlns checks
68 array(
69 'width' => 385,
70 'height' => 385
71 )
72 )
73 );
74 }
75
76 function providerSvgFilesWithXMLMetadata() {
77 $base = dirname( __FILE__ ) . '/../../data/media';
78 $metadata =
79 '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
80 <ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about="">
81 <ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format>
82 <ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
83 </ns4:Work>
84 </rdf:RDF>';
85 $metadata = str_replace( "\r", '', $metadata ); // Windows compat
86 return array(
87 array(
88 "$base/US_states_by_total_state_tax_revenue.svg",
89 array(
90 'height' => 593,
91 'metadata' => $metadata,
92 'width' => 959
93 )
94 ),
95 );
96 }
97 }
98