MediaWiki REL1_31
SVGTest.php
Go to the documentation of this file.
1<?php
2
7
11 private $handler;
12
13 protected function setUp() {
14 parent::setUp();
15
16 $this->filePath = __DIR__ . '/../../data/media/';
17
18 $this->setMwGlobals( 'wgShowEXIF', true );
19
20 $this->handler = new SvgHandler;
21 }
22
29 public function testGetIndependentMetaArray( $filename, $expected ) {
30 $file = $this->dataFile( $filename, 'image/svg+xml' );
31 $res = $this->handler->getCommonMetaArray( $file );
32
33 $this->assertEquals( $res, $expected );
34 }
35
36 public static function providerGetIndependentMetaArray() {
37 return [
38 [ 'Tux.svg', [
39 'ObjectName' => 'Tux',
40 'ImageDescription' =>
41 'For more information see: http://commons.wikimedia.org/wiki/Image:Tux.svg',
42 ] ],
43 [ 'Wikimedia-logo.svg', [] ]
44 ];
45 }
46
54 public function testGetMatchedLanguage( $userPreferredLanguage, $svgLanguages, $expectedMatch ) {
55 $match = $this->handler->getMatchedLanguage( $userPreferredLanguage, $svgLanguages );
56 $this->assertEquals( $expectedMatch, $match );
57 }
58
59 public function providerGetMatchedLanguage() {
60 return [
61 'no match' => [
62 'userPreferredLanguage' => 'en',
63 'svgLanguages' => [ 'de-DE', 'zh', 'ga', 'fr', 'sr-Latn-ME' ],
64 'expectedMatch' => null,
65 ],
66 'no subtags' => [
67 'userPreferredLanguage' => 'en',
68 'svgLanguages' => [ 'de', 'zh', 'en', 'fr' ],
69 'expectedMatch' => 'en',
70 ],
71 'user no subtags, svg 1 subtag' => [
72 'userPreferredLanguage' => 'en',
73 'svgLanguages' => [ 'de-DE', 'en-GB', 'en-US', 'fr' ],
74 'expectedMatch' => 'en-GB',
75 ],
76 'user no subtags, svg >1 subtag' => [
77 'userPreferredLanguage' => 'sr',
78 'svgLanguages' => [ 'de-DE', 'sr-Cyrl-BA', 'sr-Latn-ME', 'en-US', 'fr' ],
79 'expectedMatch' => 'sr-Cyrl-BA',
80 ],
81 'user 1 subtag, svg no subtags' => [
82 'userPreferredLanguage' => 'en-US',
83 'svgLanguages' => [ 'de', 'en', 'en', 'fr' ],
84 'expectedMatch' => null,
85 ],
86 'user 1 subtag, svg 1 subtag' => [
87 'userPreferredLanguage' => 'en-US',
88 'svgLanguages' => [ 'de-DE', 'en-GB', 'en-US', 'fr' ],
89 'expectedMatch' => 'en-US',
90 ],
91 'user 1 subtag, svg >1 subtag' => [
92 'userPreferredLanguage' => 'sr-Latn',
93 'svgLanguages' => [ 'de-DE', 'sr-Cyrl-BA', 'sr-Latn-ME', 'fr' ],
94 'expectedMatch' => 'sr-Latn-ME',
95 ],
96 'user >1 subtag, svg >1 subtag' => [
97 'userPreferredLanguage' => 'sr-Latn-ME',
98 'svgLanguages' => [ 'de-DE', 'sr-Cyrl-BA', 'sr-Latn-ME', 'en-US', 'fr' ],
99 'expectedMatch' => 'sr-Latn-ME',
100 ],
101 'user >1 subtag, svg <=1 subtag' => [
102 'userPreferredLanguage' => 'sr-Latn-ME',
103 'svgLanguages' => [ 'de-DE', 'sr-Cyrl', 'sr-Latn', 'en-US', 'fr' ],
104 'expectedMatch' => null,
105 ],
106 'ensure case-insensitive' => [
107 'userPreferredLanguage' => 'sr-latn',
108 'svgLanguages' => [ 'de-DE', 'sr-Cyrl', 'sr-Latn-ME', 'en-US', 'fr' ],
109 'expectedMatch' => 'sr-Latn-ME',
110 ],
111 ];
112 }
113}
Specificly for testing Media handlers.
dataFile( $name, $type=null)
Utility function: Get a new file object for a file on disk but not actually in db.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Media.
Definition SVGTest.php:6
testGetIndependentMetaArray( $filename, $expected)
Definition SVGTest.php:29
SvgHandler $handler
Definition SVGTest.php:11
testGetMatchedLanguage( $userPreferredLanguage, $svgLanguages, $expectedMatch)
Definition SVGTest.php:54
setUp()
Definition SVGTest.php:13
providerGetMatchedLanguage()
Definition SVGTest.php:59
static providerGetIndependentMetaArray()
Definition SVGTest.php:36
Handler for SVG images.
Definition SVG.php:30
$res
Definition database.txt:21
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves set to a MediaTransformOutput the error message to be returned in an array you should do so by altering $wgNamespaceProtection and $wgNamespaceContentModels outside the handler
Definition hooks.txt:930