MediaWiki REL1_31
VersionCheckerTest.php
Go to the documentation of this file.
1<?php
2
6class VersionCheckerTest extends PHPUnit\Framework\TestCase {
7
8 use MediaWikiCoversValidator;
9 use PHPUnit4And6Compat;
10
14 public function testCheck( $coreVersion, $constraint, $expected ) {
15 $checker = new VersionChecker( $coreVersion );
16 $this->assertEquals( $expected, !(bool)$checker->checkArray( [
17 'FakeExtension' => [
18 'MediaWiki' => $constraint,
19 ],
20 ] ) );
21 }
22
23 public static function provideCheck() {
24 return [
25 // [ $wgVersion, constraint, expected ]
26 [ '1.25alpha', '>= 1.26', false ],
27 [ '1.25.0', '>= 1.26', false ],
28 [ '1.26alpha', '>= 1.26', true ],
29 [ '1.26alpha', '>= 1.26.0', true ],
30 [ '1.26alpha', '>= 1.26.0-stable', false ],
31 [ '1.26.0', '>= 1.26.0-stable', true ],
32 [ '1.26.1', '>= 1.26.0-stable', true ],
33 [ '1.27.1', '>= 1.26.0-stable', true ],
34 [ '1.26alpha', '>= 1.26.1', false ],
35 [ '1.26alpha', '>= 1.26alpha', true ],
36 [ '1.26alpha', '>= 1.25', true ],
37 [ '1.26.0-alpha.14', '>= 1.26.0-alpha.15', false ],
38 [ '1.26.0-alpha.14', '>= 1.26.0-alpha.10', true ],
39 [ '1.26.1', '>= 1.26.2, <=1.26.0', false ],
40 [ '1.26.1', '^1.26.2', false ],
41 // Accept anything for un-parsable version strings
42 [ '1.26mwf14', '== 1.25alpha', true ],
43 [ 'totallyinvalid', '== 1.0', true ],
44 ];
45 }
46
50 public function testType( $given, $expected ) {
51 $checker = new VersionChecker( '1.0.0' );
52 $checker->setLoadedExtensionsAndSkins( [
53 'FakeDependency' => [
54 'version' => '1.0.0',
55 ],
56 'NoVersionGiven' => [],
57 ] );
58 $this->assertEquals( $expected, $checker->checkArray( [
59 'FakeExtension' => $given,
60 ] ) );
61 }
62
63 public static function provideType() {
64 return [
65 // valid type
66 [
67 [
68 'extensions' => [
69 'FakeDependency' => '1.0.0',
70 ],
71 ],
72 [],
73 ],
74 [
75 [
76 'MediaWiki' => '1.0.0',
77 ],
78 [],
79 ],
80 [
81 [
82 'extensions' => [
83 'NoVersionGiven' => '*',
84 ],
85 ],
86 [],
87 ],
88 [
89 [
90 'extensions' => [
91 'NoVersionGiven' => '1.0',
92 ],
93 ],
94 [
95 [
96 'incompatible' => 'FakeExtension',
97 'type' => 'incompatible-extensions',
98 'msg' => 'NoVersionGiven does not expose its version, but FakeExtension requires: 1.0.',
99 ],
100 ],
101 ],
102 [
103 [
104 'extensions' => [
105 'Missing' => '*',
106 ],
107 ],
108 [
109 [
110 'missing' => 'Missing',
111 'type' => 'missing-extensions',
112 'msg' => 'FakeExtension requires Missing to be installed.',
113 ],
114 ],
115 ],
116 [
117 [
118 'extensions' => [
119 'FakeDependency' => '2.0.0',
120 ],
121 ],
122 [
123 [
124 'incompatible' => 'FakeExtension',
125 'type' => 'incompatible-extensions',
126 // phpcs:ignore Generic.Files.LineLength.TooLong
127 'msg' => 'FakeExtension is not compatible with the current installed version of FakeDependency (1.0.0), it requires: 2.0.0.',
128 ],
129 ],
130 ],
131 [
132 [
133 'skins' => [
134 'FakeSkin' => '*',
135 ],
136 ],
137 [
138 [
139 'missing' => 'FakeSkin',
140 'type' => 'missing-skins',
141 'msg' => 'FakeExtension requires FakeSkin to be installed.',
142 ],
143 ],
144 ],
145 ];
146 }
147
152 public function testInvalidConstraint() {
153 $checker = new VersionChecker( '1.0.0' );
154 $checker->setLoadedExtensionsAndSkins( [
155 'FakeDependency' => [
156 'version' => 'not really valid',
157 ],
158 ] );
159 $this->assertEquals( [
160 [
161 'type' => 'invalid-version',
162 'msg' => "FakeDependency does not have a valid version string.",
163 ],
164 ], $checker->checkArray( [
165 'FakeExtension' => [
166 'extensions' => [
167 'FakeDependency' => '1.24.3',
168 ],
169 ],
170 ] ) );
171
172 $checker = new VersionChecker( '1.0.0' );
173 $checker->setLoadedExtensionsAndSkins( [
174 'FakeDependency' => [
175 'version' => '1.24.3',
176 ],
177 ] );
178
179 $this->setExpectedException( UnexpectedValueException::class );
180 $checker->checkArray( [
181 'FakeExtension' => [
182 'FakeDependency' => 'not really valid',
183 ],
184 ] );
185 }
186
190 public function testInvalidDependency() {
191 $checker = new VersionChecker( '1.0.0' );
192 $this->setExpectedException( UnexpectedValueException::class,
193 'Dependency type skin unknown in FakeExtension' );
194 $this->assertEquals( [
195 [
196 'type' => 'invalid-version',
197 'msg' => 'FakeDependency does not have a valid version string.',
198 ],
199 ], $checker->checkArray( [
200 'FakeExtension' => [
201 'skin' => [
202 'FakeSkin' => '*',
203 ],
204 ],
205 ] ) );
206 }
207}
testType( $given, $expected)
provideType
testCheck( $coreVersion, $constraint, $expected)
provideCheck
testInvalidConstraint()
Check, if a non-parsable version constraint does not throw an exception or returns any error message.
Provides functions to check a set of extensions with dependencies against a set of loaded extensions ...
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition hooks.txt:2006
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187