MediaWiki
REL1_31
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
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'
=> [
107
'de'
=>
SVGReader::LANG_FULL_MATCH
,
108
'fr'
=>
SVGReader::LANG_FULL_MATCH
,
109
'nl'
=>
SVGReader::LANG_FULL_MATCH
,
110
'tlh-ca'
=>
SVGReader::LANG_FULL_MATCH
,
111
'tlh'
=>
SVGReader::LANG_PREFIX_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
// phpcs:disable Generic.Files.LineLength
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
// phpcs:enable
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
}
MWException
MediaWiki exception.
Definition
MWException.php:26
MediaWikiTestCase
Definition
MediaWikiTestCase.php:17
SVGMetadataExtractorTest
Media SVGMetadataExtractor.
Definition
SVGMetadataExtractorTest.php:7
SVGMetadataExtractorTest\testGetMetadata
testGetMetadata( $infile, $expected)
provideSvgFiles
Definition
SVGMetadataExtractorTest.php:12
SVGMetadataExtractorTest\testGetXMLMetadata
testGetXMLMetadata( $infile, $expected)
provideSvgFilesWithXMLMetadata
Definition
SVGMetadataExtractorTest.php:19
SVGMetadataExtractorTest\assertMetadata
assertMetadata( $infile, $expected)
Definition
SVGMetadataExtractorTest.php:29
SVGMetadataExtractorTest\provideSvgFilesWithXMLMetadata
static provideSvgFilesWithXMLMetadata()
Definition
SVGMetadataExtractorTest.php:129
SVGMetadataExtractorTest\provideSvgFiles
static provideSvgFiles()
Definition
SVGMetadataExtractorTest.php:42
SVGMetadataExtractor\getMetadata
static getMetadata( $filename)
Definition
SVGMetadataExtractor.php:32
SVGReader\LANG_PREFIX_MATCH
const LANG_PREFIX_MATCH
Definition
SVGMetadataExtractor.php:46
SVGReader\LANG_FULL_MATCH
const LANG_FULL_MATCH
Definition
SVGMetadataExtractor.php:47
$e
returning false will NOT prevent logging $e
Definition
hooks.txt:2176
$base
$base
Definition
generateLocalAutoload.php:11
tests
phpunit
includes
media
SVGMetadataExtractorTest.php
Generated on Mon Nov 25 2024 15:36:28 for MediaWiki by
1.10.0