MediaWiki  REL1_21
SVGMetadataExtractorTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class SVGMetadataExtractorTest extends MediaWikiTestCase {
00004 
00005         protected function setUp() {
00006                 parent::setUp();
00007                 AutoLoader::loadClass( 'SVGMetadataExtractorTest' );
00008         }
00009 
00013         function testGetMetadata( $infile, $expected ) {
00014                 $this->assertMetadata( $infile, $expected );
00015         }
00016 
00020         function testGetXMLMetadata( $infile, $expected ) {
00021                 $r = new XMLReader();
00022                 if ( !method_exists( $r, 'readInnerXML' ) ) {
00023                         $this->markTestSkipped( 'XMLReader::readInnerXML() does not exist (libxml >2.6.20 needed).' );
00024                         return;
00025                 }
00026                 $this->assertMetadata( $infile, $expected );
00027         }
00028 
00029         function assertMetadata( $infile, $expected ) {
00030                 try {
00031                         $data = SVGMetadataExtractor::getMetadata( $infile );
00032                         $this->assertEquals( $expected, $data, 'SVG metadata extraction test' );
00033                 } catch ( MWException $e ) {
00034                         if ( $expected === false ) {
00035                                 $this->assertTrue( true, 'SVG metadata extracted test (expected failure)' );
00036                         } else {
00037                                 throw $e;
00038                         }
00039                 }
00040         }
00041 
00042         public static function provideSvgFiles() {
00043                 $base = __DIR__ . '/../../data/media';
00044                 return array(
00045                         array(
00046                                 "$base/Wikimedia-logo.svg",
00047                                 array(
00048                                         'width' => 1024,
00049                                         'height' => 1024,
00050                                         'originalWidth' => '1024',
00051                                         'originalHeight' => '1024',
00052                                 )
00053                         ),
00054                         array(
00055                                 "$base/QA_icon.svg",
00056                                 array(
00057                                         'width' => 60,
00058                                         'height' => 60,
00059                                         'originalWidth' => '60',
00060                                         'originalHeight' => '60',
00061                                 )
00062                         ),
00063                         array(
00064                                 "$base/Gtk-media-play-ltr.svg",
00065                                 array(
00066                                         'width' => 60,
00067                                         'height' => 60,
00068                                         'originalWidth' => '60.0000000',
00069                                         'originalHeight' => '60.0000000',
00070                                 )
00071                         ),
00072                         array(
00073                                 "$base/Toll_Texas_1.svg",
00074                                 // This file triggered bug 31719, needs entity expansion in the xmlns checks
00075                                 array(
00076                                         'width' => 385,
00077                                         'height' => 385,
00078                                         'originalWidth' => '385',
00079                                         'originalHeight' => '385.0004883',
00080                                 )
00081                         )
00082                 );
00083         }
00084 
00085         public static function provideSvgFilesWithXMLMetadata() {
00086                 $base = __DIR__ . '/../../data/media';
00087                 $metadata = '<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 }