test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / includes / media / SVGMetadataExtractorTest.php
blob3bf9c59ff83ad9333c3e9f081b8d40fade079f89
1 <?php
3 class SVGMetadataExtractorTest extends MediaWikiTestCase {
5 protected function setUp() {
6 parent::setUp();
7 AutoLoader::loadClass( 'SVGMetadataExtractorTest' );
10 /**
11 * @dataProvider provideSvgFiles
13 function testGetMetadata( $infile, $expected ) {
14 $this->assertMetadata( $infile, $expected );
17 /**
18 * @dataProvider provideSvgFilesWithXMLMetadata
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).' );
25 return;
27 $this->assertMetadata( $infile, $expected );
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;
43 public static function provideSvgFiles() {
44 $base = __DIR__ . '/../../data/media';
46 return array(
47 array(
48 "$base/Wikimedia-logo.svg",
49 array(
50 'width' => 1024,
51 'height' => 1024,
52 'originalWidth' => '1024',
53 'originalHeight' => '1024',
56 array(
57 "$base/QA_icon.svg",
58 array(
59 'width' => 60,
60 'height' => 60,
61 'originalWidth' => '60',
62 'originalHeight' => '60',
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',
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',
87 public static function provideSvgFilesWithXMLMetadata() {
88 $base = __DIR__ . '/../../data/media';
89 $metadata = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
90 <ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about="">
91 <ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format>
92 <ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
93 </ns4:Work>
94 </rdf:RDF>';
95 $metadata = str_replace( "\r", '', $metadata ); // Windows compat
96 return array(
97 array(
98 "$base/US_states_by_total_state_tax_revenue.svg",
99 array(
100 'height' => 593,
101 'metadata' => $metadata,
102 'width' => 959,
103 'originalWidth' => '958.69',
104 'originalHeight' => '592.78998',