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