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