MediaWiki
REL1_23
|
00001 <?php 00002 00006 class SVGMetadataExtractorTest extends MediaWikiTestCase { 00007 00008 protected function setUp() { 00009 parent::setUp(); 00010 AutoLoader::loadClass( 'SVGMetadataExtractorTest' ); 00011 } 00012 00016 public function testGetMetadata( $infile, $expected ) { 00017 $this->assertMetadata( $infile, $expected ); 00018 } 00019 00023 public function testGetXMLMetadata( $infile, $expected ) { 00024 $r = new XMLReader(); 00025 if ( !method_exists( $r, 'readInnerXML' ) ) { 00026 $this->markTestSkipped( 'XMLReader::readInnerXML() does not exist (libxml >2.6.20 needed).' ); 00027 00028 return; 00029 } 00030 $this->assertMetadata( $infile, $expected ); 00031 } 00032 00033 function assertMetadata( $infile, $expected ) { 00034 try { 00035 $data = SVGMetadataExtractor::getMetadata( $infile ); 00036 $this->assertEquals( $expected, $data, 'SVG metadata extraction test' ); 00037 } catch ( MWException $e ) { 00038 if ( $expected === false ) { 00039 $this->assertTrue( true, 'SVG metadata extracted test (expected failure)' ); 00040 } else { 00041 throw $e; 00042 } 00043 } 00044 } 00045 00046 public static function provideSvgFiles() { 00047 $base = __DIR__ . '/../../data/media'; 00048 00049 return array( 00050 array( 00051 "$base/Wikimedia-logo.svg", 00052 array( 00053 'width' => 1024, 00054 'height' => 1024, 00055 'originalWidth' => '1024', 00056 'originalHeight' => '1024', 00057 'translations' => array(), 00058 ) 00059 ), 00060 array( 00061 "$base/QA_icon.svg", 00062 array( 00063 'width' => 60, 00064 'height' => 60, 00065 'originalWidth' => '60', 00066 'originalHeight' => '60', 00067 'translations' => array(), 00068 ) 00069 ), 00070 array( 00071 "$base/Gtk-media-play-ltr.svg", 00072 array( 00073 'width' => 60, 00074 'height' => 60, 00075 'originalWidth' => '60.0000000', 00076 'originalHeight' => '60.0000000', 00077 'translations' => array(), 00078 ) 00079 ), 00080 array( 00081 "$base/Toll_Texas_1.svg", 00082 // This file triggered bug 31719, needs entity expansion in the xmlns checks 00083 array( 00084 'width' => 385, 00085 'height' => 385, 00086 'originalWidth' => '385', 00087 'originalHeight' => '385.0004883', 00088 'translations' => array(), 00089 ) 00090 ), 00091 array( 00092 "$base/Tux.svg", 00093 array( 00094 'width' => 512, 00095 'height' => 594, 00096 'originalWidth' => '100%', 00097 'originalHeight' => '100%', 00098 'title' => 'Tux', 00099 'translations' => array(), 00100 'description' => 'For more information see: http://commons.wikimedia.org/wiki/Image:Tux.svg', 00101 ) 00102 ), 00103 array( 00104 "$base/Speech_bubbles.svg", 00105 array( 00106 'width' => 627, 00107 'height' => 461, 00108 'originalWidth' => '17.7cm', 00109 'originalHeight' => '13cm', 00110 'translations' => array( 00111 'de' => SVGReader::LANG_FULL_MATCH, 00112 'fr' => SVGReader::LANG_FULL_MATCH, 00113 'nl' => SVGReader::LANG_FULL_MATCH, 00114 'tlh-ca' => SVGReader::LANG_FULL_MATCH, 00115 'tlh' => SVGReader::LANG_PREFIX_MATCH 00116 ), 00117 ) 00118 ), 00119 ); 00120 } 00121 00122 public static function provideSvgFilesWithXMLMetadata() { 00123 $base = __DIR__ . '/../../data/media'; 00124 $metadata = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> 00125 <ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about=""> 00126 <ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format> 00127 <ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/> 00128 </ns4:Work> 00129 </rdf:RDF>'; 00130 $metadata = str_replace( "\r", '', $metadata ); // Windows compat 00131 return array( 00132 array( 00133 "$base/US_states_by_total_state_tax_revenue.svg", 00134 array( 00135 'height' => 593, 00136 'metadata' => $metadata, 00137 'width' => 959, 00138 'originalWidth' => '958.69', 00139 'originalHeight' => '592.78998', 00140 'translations' => array(), 00141 ) 00142 ), 00143 ); 00144 } 00145 }