MediaWiki
REL1_20
|
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 = __DIR__ . '/../../data/media'; 00043 return array( 00044 array( 00045 "$base/Wikimedia-logo.svg", 00046 array( 00047 'width' => 1024, 00048 'height' => 1024, 00049 'originalWidth' => '1024', 00050 'originalHeight' => '1024', 00051 ) 00052 ), 00053 array( 00054 "$base/QA_icon.svg", 00055 array( 00056 'width' => 60, 00057 'height' => 60, 00058 'originalWidth' => '60', 00059 'originalHeight' => '60', 00060 ) 00061 ), 00062 array( 00063 "$base/Gtk-media-play-ltr.svg", 00064 array( 00065 'width' => 60, 00066 'height' => 60, 00067 'originalWidth' => '60.0000000', 00068 'originalHeight' => '60.0000000', 00069 ) 00070 ), 00071 array( 00072 "$base/Toll_Texas_1.svg", 00073 // This file triggered bug 31719, needs entity expansion in the xmlns checks 00074 array( 00075 'width' => 385, 00076 'height' => 385, 00077 'originalWidth' => '385', 00078 'originalHeight' => '385.0004883', 00079 ) 00080 ) 00081 ); 00082 } 00083 00084 function providerSvgFilesWithXMLMetadata() { 00085 $base = __DIR__ . '/../../data/media'; 00086 $metadata = 00087 '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> 00088 <ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about=""> 00089 <ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format> 00090 <ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/> 00091 </ns4:Work> 00092 </rdf:RDF>'; 00093 $metadata = str_replace( "\r", '', $metadata ); // Windows compat 00094 return array( 00095 array( 00096 "$base/US_states_by_total_state_tax_revenue.svg", 00097 array( 00098 'height' => 593, 00099 'metadata' => $metadata, 00100 'width' => 959, 00101 'originalWidth' => '958.69', 00102 'originalHeight' => '592.78998', 00103 ) 00104 ), 00105 ); 00106 } 00107 } 00108