MediaWiki  1.33.0
SVGMetadataExtractorTest.php
Go to the documentation of this file.
1 <?php
2 
8 
12  public function testGetMetadata( $infile, $expected ) {
13  $this->assertMetadata( $infile, $expected );
14  }
15 
19  public function testGetXMLMetadata( $infile, $expected ) {
20  $r = new XMLReader();
21  $this->assertMetadata( $infile, $expected );
22  }
23 
27  public function testScaleSVGUnit( $inUnit, $expected ) {
28  $this->assertEquals(
29  $expected,
30  SVGReader::scaleSVGUnit( $inUnit ),
31  'SVG unit conversion and scaling failure'
32  );
33  }
34 
35  function assertMetadata( $infile, $expected ) {
36  try {
38  $this->assertEquals( $expected, $data, 'SVG metadata extraction test' );
39  } catch ( MWException $e ) {
40  if ( $expected === false ) {
41  $this->assertTrue( true, 'SVG metadata extracted test (expected failure)' );
42  } else {
43  throw $e;
44  }
45  }
46  }
47 
48  public static function provideSvgFiles() {
49  $base = __DIR__ . '/../../data/media';
50 
51  return [
52  [
53  "$base/Wikimedia-logo.svg",
54  [
55  'width' => 1024,
56  'height' => 1024,
57  'originalWidth' => '1024',
58  'originalHeight' => '1024',
59  'translations' => [],
60  ]
61  ],
62  [
63  "$base/QA_icon.svg",
64  [
65  'width' => 60,
66  'height' => 60,
67  'originalWidth' => '60',
68  'originalHeight' => '60',
69  'translations' => [],
70  ]
71  ],
72  [
73  "$base/Gtk-media-play-ltr.svg",
74  [
75  'width' => 60,
76  'height' => 60,
77  'originalWidth' => '60.0000000',
78  'originalHeight' => '60.0000000',
79  'translations' => [],
80  ]
81  ],
82  [
83  "$base/Toll_Texas_1.svg",
84  // This file triggered T33719, needs entity expansion in the xmlns checks
85  [
86  'width' => 385,
87  'height' => 385,
88  'originalWidth' => '385',
89  'originalHeight' => '385.0004883',
90  'translations' => [],
91  ]
92  ],
93  [
94  "$base/Tux.svg",
95  [
96  'width' => 512,
97  'height' => 594,
98  'originalWidth' => '100%',
99  'originalHeight' => '100%',
100  'title' => 'Tux',
101  'translations' => [],
102  'description' => 'For more information see: http://commons.wikimedia.org/wiki/Image:Tux.svg',
103  ]
104  ],
105  [
106  "$base/Speech_bubbles.svg",
107  [
108  'width' => 627,
109  'height' => 461,
110  'originalWidth' => '17.7cm',
111  'originalHeight' => '13cm',
112  'translations' => [
116  'tlh-ca' => SVGReader::LANG_FULL_MATCH,
118  ],
119  ]
120  ],
121  [
122  "$base/Soccer_ball_animated.svg",
123  [
124  'width' => 150,
125  'height' => 150,
126  'originalWidth' => '150',
127  'originalHeight' => '150',
128  'animated' => true,
129  'translations' => []
130  ],
131  ],
132  [
133  "$base/comma_separated_viewbox.svg",
134  [
135  'width' => 512,
136  'height' => 594,
137  'originalWidth' => '100%',
138  'originalHeight' => '100%',
139  'translations' => []
140  ],
141  ],
142  ];
143  }
144 
145  public static function provideSvgFilesWithXMLMetadata() {
146  $base = __DIR__ . '/../../data/media';
147  // phpcs:disable Generic.Files.LineLength
148  $metadata = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
149  <ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about="">
150  <ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format>
151  <ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
152  </ns4:Work>
153  </rdf:RDF>';
154  // phpcs:enable
155 
156  $metadata = str_replace( "\r", '', $metadata ); // Windows compat
157  return [
158  [
159  "$base/US_states_by_total_state_tax_revenue.svg",
160  [
161  'height' => 593,
162  'metadata' => $metadata,
163  'width' => 959,
164  'originalWidth' => '958.69',
165  'originalHeight' => '592.78998',
166  'translations' => [],
167  ]
168  ],
169  ];
170  }
171 
172  public static function provideSvgUnits() {
173  return [
174  [ '1' , 1 ],
175  [ '1.1' , 1.1 ],
176  [ '0.1' , 0.1 ],
177  [ '.1' , 0.1 ],
178  [ '1e2' , 100 ],
179  [ '1E2' , 100 ],
180  [ '+1' , 1 ],
181  [ '-1' , -1 ],
182  [ '-1.1' , -1.1 ],
183  [ '1e+2' , 100 ],
184  [ '1e-2' , 0.01 ],
185  [ '10px' , 10 ],
186  [ '10pt' , 10 * 1.25 ],
187  [ '10pc' , 10 * 15 ],
188  [ '10mm' , 10 * 3.543307 ],
189  [ '10cm' , 10 * 35.43307 ],
190  [ '10in' , 10 * 90 ],
191  [ '10em' , 10 * 16 ],
192  [ '10ex' , 10 * 12 ],
193  [ '10%' , 51.2 ],
194  [ '10 px' , 10 ],
195  // Invalid values
196  [ '1e1.1', 10 ],
197  [ '10bp', 10 ],
198  [ 'p10', null ],
199  ];
200  }
201 }
SVGReader\LANG_PREFIX_MATCH
const LANG_PREFIX_MATCH
Definition: SVGMetadataExtractor.php:46
SVGMetadataExtractorTest\provideSvgUnits
static provideSvgUnits()
Definition: SVGMetadataExtractorTest.php:172
SVGMetadataExtractor\getMetadata
static getMetadata( $filename)
Definition: SVGMetadataExtractor.php:32
SVGMetadataExtractorTest\provideSvgFiles
static provideSvgFiles()
Definition: SVGMetadataExtractorTest.php:48
SVGReader\scaleSVGUnit
static scaleSVGUnit( $length, $viewportSize=512)
Return a rounded pixel equivalent for a labeled CSS/SVG length.
Definition: SVGMetadataExtractor.php:365
SVGMetadataExtractorTest\testGetXMLMetadata
testGetXMLMetadata( $infile, $expected)
provideSvgFilesWithXMLMetadata
Definition: SVGMetadataExtractorTest.php:19
$base
$base
Definition: generateLocalAutoload.php:11
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$data
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
Definition: generatePhpCharToUpperMappings.php:13
MWException
MediaWiki exception.
Definition: MWException.php:26
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
SVGMetadataExtractorTest
Media SVGMetadataExtractor.
Definition: SVGMetadataExtractorTest.php:7
SVGReader\LANG_FULL_MATCH
const LANG_FULL_MATCH
Definition: SVGMetadataExtractor.php:47
SVGMetadataExtractorTest\provideSvgFilesWithXMLMetadata
static provideSvgFilesWithXMLMetadata()
Definition: SVGMetadataExtractorTest.php:145
null
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2162
SVGMetadataExtractorTest\assertMetadata
assertMetadata( $infile, $expected)
Definition: SVGMetadataExtractorTest.php:35
SVGMetadataExtractorTest\testGetMetadata
testGetMetadata( $infile, $expected)
provideSvgFiles
Definition: SVGMetadataExtractorTest.php:12
SVGMetadataExtractorTest\testScaleSVGUnit
testScaleSVGUnit( $inUnit, $expected)
provideSvgUnits
Definition: SVGMetadataExtractorTest.php:27