From: Antoine Musso Date: Sat, 28 May 2011 09:58:43 +0000 (+0000) Subject: Handle old libxml when extracting SVG metadata X-Git-Tag: 1.31.0-rc.0~29900 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=827254b99f33ecd61763181ddea77bdc76c72fe1;p=lhc%2Fweb%2Fwiklou.git Handle old libxml when extracting SVG metadata Mac OS X 10.5.8 comes with libxml 2.6.16, thus some methods of XMLReader are not availabe (ex: readInnerXML()). This patch, throw an error if the above method does not exist (only one use in our code). Since metadata can comes as string or an XML fragment, I have split the tests to take care of the two usages and of the exception. --- diff --git a/includes/media/SVGMetadataExtractor.php b/includes/media/SVGMetadataExtractor.php index db6b59866e..976948c30b 100644 --- a/includes/media/SVGMetadataExtractor.php +++ b/includes/media/SVGMetadataExtractor.php @@ -177,7 +177,11 @@ class SVGReader { return; } // TODO: find and store type of xml snippet. metadata['metadataType'] = "rdf" - $this->metadata[$metafield] = trim( $this->reader->readInnerXML() ); + if( method_exists( $this->reader, 'readInnerXML()' ) ) { + $this->metadata[$metafield] = trim( $this->reader->readInnerXML() ); + } else { + 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)." ); + } $this->reader->next(); } diff --git a/tests/phpunit/includes/media/SVGMetadataExtractorTest.php b/tests/phpunit/includes/media/SVGMetadataExtractorTest.php index b1b5373361..07ab4c1581 100644 --- a/tests/phpunit/includes/media/SVGMetadataExtractorTest.php +++ b/tests/phpunit/includes/media/SVGMetadataExtractorTest.php @@ -10,6 +10,22 @@ class SVGMetadataExtractorTest extends MediaWikiTestCase { * @dataProvider providerSvgFiles */ function testGetMetadata( $infile, $expected ) { + $this->assertMetadata( $infile, $expected ); + } + + /** + * @dataProvider providerSvgFilesWithXMLMetadata + */ + function testGetXMLMetadata( $infile, $expected ) { + $r = new XMLReader(); + if( !method_exists( $r, 'readInnerXML()' ) ) { + $this->markTestSkipped( 'XMLReader::readInnerXML() does not exist (libxml >2.6.20 needed).' ); + return; + } + $this->assertMetadata( $infile, $expected ); + } + + function assertMetadata( $infile, $expected ) { try { $data = SVGMetadataExtractor::getMetadata( $infile ); $this->assertEquals( $expected, $data, 'SVG metadata extraction test' ); @@ -46,6 +62,12 @@ class SVGMetadataExtractorTest extends MediaWikiTestCase { 'height' => 60 ) ), + ); + } + + function providerSvgFilesWithXMLMetadata() { + $base = dirname( __FILE__ ); + return array( array( "$base/US_states_by_total_state_tax_revenue.svg", array(