Handle old libxml when extracting SVG metadata
authorAntoine Musso <hashar@users.mediawiki.org>
Sat, 28 May 2011 09:58:43 +0000 (09:58 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Sat, 28 May 2011 09:58:43 +0000 (09:58 +0000)
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.

includes/media/SVGMetadataExtractor.php
tests/phpunit/includes/media/SVGMetadataExtractorTest.php

index db6b598..976948c 100644 (file)
@@ -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();
        }
 
index b1b5373..07ab4c1 100644 (file)
@@ -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(