| Index: trunk/phase3/tests/phpunit/includes/media/SVGMetadataExtractorTest.php |
| — | — | @@ -10,6 +10,22 @@ |
| 11 | 11 | * @dataProvider providerSvgFiles |
| 12 | 12 | */ |
| 13 | 13 | function testGetMetadata( $infile, $expected ) { |
| | 14 | + $this->assertMetadata( $infile, $expected ); |
| | 15 | + } |
| | 16 | + |
| | 17 | + /** |
| | 18 | + * @dataProvider providerSvgFilesWithXMLMetadata |
| | 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 ) { |
| 14 | 30 | try { |
| 15 | 31 | $data = SVGMetadataExtractor::getMetadata( $infile ); |
| 16 | 32 | $this->assertEquals( $expected, $data, 'SVG metadata extraction test' ); |
| — | — | @@ -46,6 +62,12 @@ |
| 47 | 63 | 'height' => 60 |
| 48 | 64 | ) |
| 49 | 65 | ), |
| | 66 | + ); |
| | 67 | + } |
| | 68 | + |
| | 69 | + function providerSvgFilesWithXMLMetadata() { |
| | 70 | + $base = dirname( __FILE__ ); |
| | 71 | + return array( |
| 50 | 72 | array( |
| 51 | 73 | "$base/US_states_by_total_state_tax_revenue.svg", |
| 52 | 74 | array( |
| Index: trunk/phase3/includes/media/SVGMetadataExtractor.php |
| — | — | @@ -177,7 +177,11 @@ |
| 178 | 178 | return; |
| 179 | 179 | } |
| 180 | 180 | // TODO: find and store type of xml snippet. metadata['metadataType'] = "rdf" |
| 181 | | - $this->metadata[$metafield] = trim( $this->reader->readInnerXML() ); |
| | 181 | + if( method_exists( $this->reader, 'readInnerXML()' ) ) { |
| | 182 | + $this->metadata[$metafield] = trim( $this->reader->readInnerXML() ); |
| | 183 | + } else { |
| | 184 | + throw new MWException( "The PHP XMLReader extension does not comes with readInnerXML() method. Your libxml is probably out of date (need 2.6.20 or later)." ); |
| | 185 | + } |
| 182 | 186 | $this->reader->next(); |
| 183 | 187 | } |
| 184 | 188 | |