MediaWiki  1.30.2
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  if ( !method_exists( $r, 'readInnerXML' ) ) {
22  $this->markTestSkipped( 'XMLReader::readInnerXML() does not exist (libxml >2.6.20 needed).' );
23 
24  return;
25  }
26  $this->assertMetadata( $infile, $expected );
27  }
28 
29  function assertMetadata( $infile, $expected ) {
30  try {
31  $data = SVGMetadataExtractor::getMetadata( $infile );
32  $this->assertEquals( $expected, $data, 'SVG metadata extraction test' );
33  } catch ( MWException $e ) {
34  if ( $expected === false ) {
35  $this->assertTrue( true, 'SVG metadata extracted test (expected failure)' );
36  } else {
37  throw $e;
38  }
39  }
40  }
41 
42  public static function provideSvgFiles() {
43  $base = __DIR__ . '/../../data/media';
44 
45  return [
46  [
47  "$base/Wikimedia-logo.svg",
48  [
49  'width' => 1024,
50  'height' => 1024,
51  'originalWidth' => '1024',
52  'originalHeight' => '1024',
53  'translations' => [],
54  ]
55  ],
56  [
57  "$base/QA_icon.svg",
58  [
59  'width' => 60,
60  'height' => 60,
61  'originalWidth' => '60',
62  'originalHeight' => '60',
63  'translations' => [],
64  ]
65  ],
66  [
67  "$base/Gtk-media-play-ltr.svg",
68  [
69  'width' => 60,
70  'height' => 60,
71  'originalWidth' => '60.0000000',
72  'originalHeight' => '60.0000000',
73  'translations' => [],
74  ]
75  ],
76  [
77  "$base/Toll_Texas_1.svg",
78  // This file triggered T33719, needs entity expansion in the xmlns checks
79  [
80  'width' => 385,
81  'height' => 385,
82  'originalWidth' => '385',
83  'originalHeight' => '385.0004883',
84  'translations' => [],
85  ]
86  ],
87  [
88  "$base/Tux.svg",
89  [
90  'width' => 512,
91  'height' => 594,
92  'originalWidth' => '100%',
93  'originalHeight' => '100%',
94  'title' => 'Tux',
95  'translations' => [],
96  'description' => 'For more information see: http://commons.wikimedia.org/wiki/Image:Tux.svg',
97  ]
98  ],
99  [
100  "$base/Speech_bubbles.svg",
101  [
102  'width' => 627,
103  'height' => 461,
104  'originalWidth' => '17.7cm',
105  'originalHeight' => '13cm',
106  'translations' => [
110  'tlh-ca' => SVGReader::LANG_FULL_MATCH,
112  ],
113  ]
114  ],
115  [
116  "$base/Soccer_ball_animated.svg",
117  [
118  'width' => 150,
119  'height' => 150,
120  'originalWidth' => '150',
121  'originalHeight' => '150',
122  'animated' => true,
123  'translations' => []
124  ],
125  ],
126  ];
127  }
128 
129  public static function provideSvgFilesWithXMLMetadata() {
130  $base = __DIR__ . '/../../data/media';
131  // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
132  $metadata = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
133  <ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about="">
134  <ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format>
135  <ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
136  </ns4:Work>
137  </rdf:RDF>';
138  // @codingStandardsIgnoreEnd
139 
140  $metadata = str_replace( "\r", '', $metadata ); // Windows compat
141  return [
142  [
143  "$base/US_states_by_total_state_tax_revenue.svg",
144  [
145  'height' => 593,
146  'metadata' => $metadata,
147  'width' => 959,
148  'originalWidth' => '958.69',
149  'originalHeight' => '592.78998',
150  'translations' => [],
151  ]
152  ],
153  ];
154  }
155 }
SVGReader\LANG_PREFIX_MATCH
const LANG_PREFIX_MATCH
Definition: SVGMetadataExtractor.php:46
SVGMetadataExtractor\getMetadata
static getMetadata( $filename)
Definition: SVGMetadataExtractor.php:32
SVGMetadataExtractorTest\provideSvgFiles
static provideSvgFiles()
Definition: SVGMetadataExtractorTest.php:42
SVGMetadataExtractorTest\testGetXMLMetadata
testGetXMLMetadata( $infile, $expected)
provideSvgFilesWithXMLMetadata
Definition: SVGMetadataExtractorTest.php:19
$base
$base
Definition: generateLocalAutoload.php:10
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
MWException
MediaWiki exception.
Definition: MWException.php:26
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
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:129
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2141
SVGMetadataExtractorTest\assertMetadata
assertMetadata( $infile, $expected)
Definition: SVGMetadataExtractorTest.php:29
SVGMetadataExtractorTest\testGetMetadata
testGetMetadata( $infile, $expected)
provideSvgFiles
Definition: SVGMetadataExtractorTest.php:12