Merge "thumb.php: Set ENT_NOQUOTES for htmlspecialchars"
[lhc/web/wiklou.git] / tests / phpunit / includes / registration / VersionCheckerTest.php
1 <?php
2
3 /**
4 * @covers VersionChecker
5 */
6 class VersionCheckerTest extends PHPUnit_Framework_TestCase {
7
8 use MediaWikiCoversValidator;
9
10 /**
11 * @dataProvider provideCheck
12 */
13 public function testCheck( $coreVersion, $constraint, $expected ) {
14 $checker = new VersionChecker( $coreVersion );
15 $this->assertEquals( $expected, !(bool)$checker->checkArray( [
16 'FakeExtension' => [
17 'MediaWiki' => $constraint,
18 ],
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
47 /**
48 * @dataProvider provideType
49 */
50 public function testType( $given, $expected ) {
51 $checker = new VersionChecker( '1.0.0' );
52 $checker
53 ->setLoadedExtensionsAndSkins( [
54 'FakeDependency' => [
55 'version' => '1.0.0',
56 ],
57 ] );
58 $this->assertEquals( $expected, $checker->checkArray( [
59 'FakeExtension' => $given,
60 ] )
61 );
62 }
63
64 public static function provideType() {
65 return [
66 // valid type
67 [
68 [
69 'extensions' => [
70 'FakeDependency' => '1.0.0'
71 ]
72 ],
73 []
74 ],
75 [
76 [
77 'MediaWiki' => '1.0.0'
78 ],
79 []
80 ],
81 ];
82 }
83
84 /**
85 * Check, if a non-parsable version constraint does not throw an exception or
86 * returns any error message.
87 */
88 public function testInvalidConstraint() {
89 $checker = new VersionChecker( '1.0.0' );
90 $checker
91 ->setLoadedExtensionsAndSkins( [
92 'FakeDependency' => [
93 'version' => 'not really valid',
94 ],
95 ] );
96 $this->assertEquals( [ "FakeDependency does not have a valid version string." ],
97 $checker->checkArray( [
98 'FakeExtension' => [
99 'extensions' => [
100 'FakeDependency' => '1.24.3',
101 ],
102 ],
103 ] )
104 );
105
106 $checker = new VersionChecker( '1.0.0' );
107 $checker
108 ->setLoadedExtensionsAndSkins( [
109 'FakeDependency' => [
110 'version' => '1.24.3',
111 ],
112 ] );
113
114 $this->setExpectedException( 'UnexpectedValueException' );
115 $checker->checkArray( [
116 'FakeExtension' => [
117 'FakeDependency' => 'not really valid',
118 ]
119 ] );
120 }
121 }