MediaWiki  1.23.2
SVGMetadataExtractorTest.php
Go to the documentation of this file.
1 <?php
2 
7 
8  protected function setUp() {
9  parent::setUp();
10  AutoLoader::loadClass( 'SVGMetadataExtractorTest' );
11  }
12 
16  public function testGetMetadata( $infile, $expected ) {
17  $this->assertMetadata( $infile, $expected );
18  }
19 
23  public function testGetXMLMetadata( $infile, $expected ) {
24  $r = new XMLReader();
25  if ( !method_exists( $r, 'readInnerXML' ) ) {
26  $this->markTestSkipped( 'XMLReader::readInnerXML() does not exist (libxml >2.6.20 needed).' );
27 
28  return;
29  }
30  $this->assertMetadata( $infile, $expected );
31  }
32 
33  function assertMetadata( $infile, $expected ) {
34  try {
35  $data = SVGMetadataExtractor::getMetadata( $infile );
36  $this->assertEquals( $expected, $data, 'SVG metadata extraction test' );
37  } catch ( MWException $e ) {
38  if ( $expected === false ) {
39  $this->assertTrue( true, 'SVG metadata extracted test (expected failure)' );
40  } else {
41  throw $e;
42  }
43  }
44  }
45 
46  public static function provideSvgFiles() {
47  $base = __DIR__ . '/../../data/media';
48 
49  return array(
50  array(
51  "$base/Wikimedia-logo.svg",
52  array(
53  'width' => 1024,
54  'height' => 1024,
55  'originalWidth' => '1024',
56  'originalHeight' => '1024',
57  'translations' => array(),
58  )
59  ),
60  array(
61  "$base/QA_icon.svg",
62  array(
63  'width' => 60,
64  'height' => 60,
65  'originalWidth' => '60',
66  'originalHeight' => '60',
67  'translations' => array(),
68  )
69  ),
70  array(
71  "$base/Gtk-media-play-ltr.svg",
72  array(
73  'width' => 60,
74  'height' => 60,
75  'originalWidth' => '60.0000000',
76  'originalHeight' => '60.0000000',
77  'translations' => array(),
78  )
79  ),
80  array(
81  "$base/Toll_Texas_1.svg",
82  // This file triggered bug 31719, needs entity expansion in the xmlns checks
83  array(
84  'width' => 385,
85  'height' => 385,
86  'originalWidth' => '385',
87  'originalHeight' => '385.0004883',
88  'translations' => array(),
89  )
90  ),
91  array(
92  "$base/Tux.svg",
93  array(
94  'width' => 512,
95  'height' => 594,
96  'originalWidth' => '100%',
97  'originalHeight' => '100%',
98  'title' => 'Tux',
99  'translations' => array(),
100  'description' => 'For more information see: http://commons.wikimedia.org/wiki/Image:Tux.svg',
101  )
102  ),
103  array(
104  "$base/Speech_bubbles.svg",
105  array(
106  'width' => 627,
107  'height' => 461,
108  'originalWidth' => '17.7cm',
109  'originalHeight' => '13cm',
110  'translations' => array(
114  'tlh-ca' => SVGReader::LANG_FULL_MATCH,
116  ),
117  )
118  ),
119  );
120  }
121 
122  public static function provideSvgFilesWithXMLMetadata() {
123  $base = __DIR__ . '/../../data/media';
124  $metadata = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
125  <ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about="">
126  <ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format>
127  <ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
128  </ns4:Work>
129  </rdf:RDF>';
130  $metadata = str_replace( "\r", '', $metadata ); // Windows compat
131  return array(
132  array(
133  "$base/US_states_by_total_state_tax_revenue.svg",
134  array(
135  'height' => 593,
136  'metadata' => $metadata,
137  'width' => 959,
138  'originalWidth' => '958.69',
139  'originalHeight' => '592.78998',
140  'translations' => array(),
141  )
142  ),
143  );
144  }
145 }
SVGReader\LANG_PREFIX_MATCH
const LANG_PREFIX_MATCH
Definition: SVGMetadataExtractor.php:46
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
SVGMetadataExtractor\getMetadata
static getMetadata( $filename)
Definition: SVGMetadataExtractor.php:32
SVGMetadataExtractorTest\provideSvgFiles
static provideSvgFiles()
Definition: SVGMetadataExtractorTest.php:46
SVGMetadataExtractorTest\testGetXMLMetadata
testGetXMLMetadata( $infile, $expected)
@dataProvider provideSvgFilesWithXMLMetadata
Definition: SVGMetadataExtractorTest.php:23
SVGMetadataExtractorTest\setUp
setUp()
Definition: SVGMetadataExtractorTest.php:8
MWException
MediaWiki exception.
Definition: MWException.php:26
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
SVGMetadataExtractorTest
@covers SVGMetadataExtractor
Definition: SVGMetadataExtractorTest.php:6
SVGReader\LANG_FULL_MATCH
const LANG_FULL_MATCH
Definition: SVGMetadataExtractor.php:47
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
SVGMetadataExtractorTest\provideSvgFilesWithXMLMetadata
static provideSvgFilesWithXMLMetadata()
Definition: SVGMetadataExtractorTest.php:122
SVGMetadataExtractorTest\assertMetadata
assertMetadata( $infile, $expected)
Definition: SVGMetadataExtractorTest.php:33
AutoLoader\loadClass
static loadClass( $class)
Force a class to be run through the autoloader, helpful for things like Sanitizer that have define()s...
Definition: AutoLoader.php:1264
SVGMetadataExtractorTest\testGetMetadata
testGetMetadata( $infile, $expected)
@dataProvider provideSvgFiles
Definition: SVGMetadataExtractorTest.php:16
$e
if( $useReadline) $e
Definition: eval.php:66