MediaWiki  REL1_19
SVGMetadataExtractorTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class SVGMetadataExtractorTest extends MediaWikiTestCase {
00004 
00005         function setUp() {
00006                 AutoLoader::loadClass( 'SVGMetadataExtractorTest' );
00007         }
00008 
00012         function testGetMetadata( $infile, $expected ) {
00013                 $this->assertMetadata( $infile, $expected );
00014         }
00015         
00019         function testGetXMLMetadata( $infile, $expected ) {
00020                 $r = new XMLReader();
00021                 if( !method_exists( $r, 'readInnerXML' ) ) {
00022                         $this->markTestSkipped( 'XMLReader::readInnerXML() does not exist (libxml >2.6.20 needed).' );
00023                         return;
00024                 }
00025                 $this->assertMetadata( $infile, $expected );
00026         }
00027 
00028         function assertMetadata( $infile, $expected ) {
00029                 try {
00030                         $data = SVGMetadataExtractor::getMetadata( $infile );
00031                         $this->assertEquals( $expected, $data, 'SVG metadata extraction test' );
00032                 } catch ( MWException $e ) {
00033                         if ( $expected === false ) {
00034                                 $this->assertTrue( true, 'SVG metadata extracted test (expected failure)' );
00035                         } else {
00036                                 throw $e;
00037                         }
00038                 }
00039         }
00040 
00041         function providerSvgFiles() {
00042                 $base = dirname( __FILE__ ) . '/../../data/media';
00043                 return array(
00044                         array(
00045                                 "$base/Wikimedia-logo.svg",
00046                                 array(
00047                                         'width' => 1024,
00048                                         'height' => 1024
00049                                 )
00050                         ),
00051                         array(
00052                                 "$base/QA_icon.svg",
00053                                 array(
00054                                         'width' => 60,
00055                                         'height' => 60
00056                                 )
00057                         ),
00058                         array(
00059                                 "$base/Gtk-media-play-ltr.svg",
00060                                 array(
00061                                         'width' => 60,
00062                                         'height' => 60
00063                                 )
00064                         ),
00065                         array(
00066                                 "$base/Toll_Texas_1.svg",
00067                                 // This file triggered bug 31719, needs entity expansion in the xmlns checks
00068                                 array(
00069                                         'width' => 385,
00070                                         'height' => 385
00071                                 )
00072                         )
00073                 );
00074         }
00075 
00076         function providerSvgFilesWithXMLMetadata() {
00077                 $base = dirname( __FILE__ ) . '/../../data/media';
00078                 $metadata = 
00079     '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
00080       <ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about="">
00081         <ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format>
00082         <ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
00083       </ns4:Work>
00084     </rdf:RDF>';
00085                 $metadata = str_replace( "\r", '', $metadata ); // Windows compat
00086                 return array(
00087                         array(
00088                                 "$base/US_states_by_total_state_tax_revenue.svg",
00089                                 array(
00090                                         'height' => 593,
00091                                         'metadata' => $metadata,
00092                                         'width' => 959
00093                                 )
00094                         ),
00095                 );
00096         }
00097 }
00098