MediaWiki
REL1_32
SVGMetadataExtractorTest.php
Go to the documentation of this file.
1
<?php
2
7
class
SVGMetadataExtractorTest
extends
MediaWikiTestCase
{
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
32
public
function
testScaleSVGUnit
( $inUnit, $expected ) {
33
$this->assertEquals(
34
$expected,
35
SVGReader::scaleSVGUnit
( $inUnit ),
36
'SVG unit conversion and scaling failure'
37
);
38
}
39
40
function
assertMetadata
( $infile, $expected ) {
41
try
{
42
$data =
SVGMetadataExtractor::getMetadata
( $infile );
43
$this->assertEquals( $expected, $data,
'SVG metadata extraction test'
);
44
}
catch
(
MWException
$e
) {
45
if
( $expected ===
false
) {
46
$this->assertTrue(
true
,
'SVG metadata extracted test (expected failure)'
);
47
}
else
{
48
throw
$e
;
49
}
50
}
51
}
52
53
public
static
function
provideSvgFiles
() {
54
$base
= __DIR__ .
'/../../data/media'
;
55
56
return
[
57
[
58
"$base/Wikimedia-logo.svg"
,
59
[
60
'width'
=> 1024,
61
'height'
=> 1024,
62
'originalWidth'
=>
'1024'
,
63
'originalHeight'
=>
'1024'
,
64
'translations'
=> [],
65
]
66
],
67
[
68
"$base/QA_icon.svg"
,
69
[
70
'width'
=> 60,
71
'height'
=> 60,
72
'originalWidth'
=>
'60'
,
73
'originalHeight'
=>
'60'
,
74
'translations'
=> [],
75
]
76
],
77
[
78
"$base/Gtk-media-play-ltr.svg"
,
79
[
80
'width'
=> 60,
81
'height'
=> 60,
82
'originalWidth'
=>
'60.0000000'
,
83
'originalHeight'
=>
'60.0000000'
,
84
'translations'
=> [],
85
]
86
],
87
[
88
"$base/Toll_Texas_1.svg"
,
89
// This file triggered T33719, needs entity expansion in the xmlns checks
90
[
91
'width'
=> 385,
92
'height'
=> 385,
93
'originalWidth'
=>
'385'
,
94
'originalHeight'
=>
'385.0004883'
,
95
'translations'
=> [],
96
]
97
],
98
[
99
"$base/Tux.svg"
,
100
[
101
'width'
=> 512,
102
'height'
=> 594,
103
'originalWidth'
=>
'100%'
,
104
'originalHeight'
=>
'100%'
,
105
'title'
=>
'Tux'
,
106
'translations'
=> [],
107
'description'
=>
'For more information see: http://commons.wikimedia.org/wiki/Image:Tux.svg'
,
108
]
109
],
110
[
111
"$base/Speech_bubbles.svg"
,
112
[
113
'width'
=> 627,
114
'height'
=> 461,
115
'originalWidth'
=>
'17.7cm'
,
116
'originalHeight'
=>
'13cm'
,
117
'translations'
=> [
118
'de'
=>
SVGReader::LANG_FULL_MATCH
,
119
'fr'
=>
SVGReader::LANG_FULL_MATCH
,
120
'nl'
=>
SVGReader::LANG_FULL_MATCH
,
121
'tlh-ca'
=>
SVGReader::LANG_FULL_MATCH
,
122
'tlh'
=>
SVGReader::LANG_PREFIX_MATCH
123
],
124
]
125
],
126
[
127
"$base/Soccer_ball_animated.svg"
,
128
[
129
'width'
=> 150,
130
'height'
=> 150,
131
'originalWidth'
=>
'150'
,
132
'originalHeight'
=>
'150'
,
133
'animated'
=>
true
,
134
'translations'
=> []
135
],
136
],
137
[
138
"$base/comma_separated_viewbox.svg"
,
139
[
140
'width'
=> 512,
141
'height'
=> 594,
142
'originalWidth'
=>
'100%'
,
143
'originalHeight'
=>
'100%'
,
144
'translations'
=> []
145
],
146
],
147
];
148
}
149
150
public
static
function
provideSvgFilesWithXMLMetadata
() {
151
$base
= __DIR__ .
'/../../data/media'
;
152
// phpcs:disable Generic.Files.LineLength
153
$metadata =
'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
154
<ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about="">
155
<ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format>
156
<ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
157
</ns4:Work>
158
</rdf:RDF>'
;
159
// phpcs:enable
160
161
$metadata = str_replace(
"\r"
,
''
, $metadata );
// Windows compat
162
return
[
163
[
164
"$base/US_states_by_total_state_tax_revenue.svg"
,
165
[
166
'height'
=> 593,
167
'metadata'
=> $metadata,
168
'width'
=> 959,
169
'originalWidth'
=>
'958.69'
,
170
'originalHeight'
=>
'592.78998'
,
171
'translations'
=> [],
172
]
173
],
174
];
175
}
176
177
public
static
function
provideSvgUnits
() {
178
return
[
179
[
'1'
, 1 ],
180
[
'1.1'
, 1.1 ],
181
[
'0.1'
, 0.1 ],
182
[
'.1'
, 0.1 ],
183
[
'1e2'
, 100 ],
184
[
'1E2'
, 100 ],
185
[
'+1'
, 1 ],
186
[
'-1'
, -1 ],
187
[
'-1.1'
, -1.1 ],
188
[
'1e+2'
, 100 ],
189
[
'1e-2'
, 0.01 ],
190
[
'10px'
, 10 ],
191
[
'10pt'
, 10 * 1.25 ],
192
[
'10pc'
, 10 * 15 ],
193
[
'10mm'
, 10 * 3.543307 ],
194
[
'10cm'
, 10 * 35.43307 ],
195
[
'10in'
, 10 * 90 ],
196
[
'10em'
, 10 * 16 ],
197
[
'10ex'
, 10 * 12 ],
198
[
'10%'
, 51.2 ],
199
[
'10 px'
, 10 ],
200
// Invalid values
201
[
'1e1.1'
, 10 ],
202
[
'10bp'
, 10 ],
203
[
'p10'
, null ],
204
];
205
}
206
}
MWException
MediaWiki exception.
Definition
MWException.php:26
MediaWikiTestCase
Definition
MediaWikiTestCase.php:16
SVGMetadataExtractorTest
Media SVGMetadataExtractor.
Definition
SVGMetadataExtractorTest.php:7
SVGMetadataExtractorTest\testGetMetadata
testGetMetadata( $infile, $expected)
provideSvgFiles
Definition
SVGMetadataExtractorTest.php:12
SVGMetadataExtractorTest\provideSvgUnits
static provideSvgUnits()
Definition
SVGMetadataExtractorTest.php:177
SVGMetadataExtractorTest\testScaleSVGUnit
testScaleSVGUnit( $inUnit, $expected)
provideSvgUnits
Definition
SVGMetadataExtractorTest.php:32
SVGMetadataExtractorTest\testGetXMLMetadata
testGetXMLMetadata( $infile, $expected)
provideSvgFilesWithXMLMetadata
Definition
SVGMetadataExtractorTest.php:19
SVGMetadataExtractorTest\assertMetadata
assertMetadata( $infile, $expected)
Definition
SVGMetadataExtractorTest.php:40
SVGMetadataExtractorTest\provideSvgFilesWithXMLMetadata
static provideSvgFilesWithXMLMetadata()
Definition
SVGMetadataExtractorTest.php:150
SVGMetadataExtractorTest\provideSvgFiles
static provideSvgFiles()
Definition
SVGMetadataExtractorTest.php:53
SVGMetadataExtractor\getMetadata
static getMetadata( $filename)
Definition
SVGMetadataExtractor.php:32
SVGReader\LANG_PREFIX_MATCH
const LANG_PREFIX_MATCH
Definition
SVGMetadataExtractor.php:46
SVGReader\scaleSVGUnit
static scaleSVGUnit( $length, $viewportSize=512)
Return a rounded pixel equivalent for a labeled CSS/SVG length.
Definition
SVGMetadataExtractor.php:370
SVGReader\LANG_FULL_MATCH
const LANG_FULL_MATCH
Definition
SVGMetadataExtractor.php:47
$e
returning false will NOT prevent logging $e
Definition
hooks.txt:2226
$base
$base
Definition
generateLocalAutoload.php:11
tests
phpunit
includes
media
SVGMetadataExtractorTest.php
Generated on Mon Nov 25 2024 15:58:46 for MediaWiki by
1.10.0