registration: Allow specifying extension dependencies
[lhc/web/wiklou.git] / tests / phpunit / includes / registration / VersionCheckerTest.php
1 <?php
2
3 /**
4 * @covers CoreVersionChecker
5 */
6 class CoreVersionCheckerTest extends PHPUnit_Framework_TestCase {
7 /**
8 * @dataProvider provideCheck
9 */
10 public function testCheck( $coreVersion, $constraint, $expected ) {
11 $checker = new VersionChecker();
12 $checker->setCoreVersion( $coreVersion );
13 $this->assertEquals( $expected, !(bool)$checker->checkArray( [
14 'FakeExtension' => [
15 'MediaWiki' => $constraint,
16 ],
17 ] )
18 );
19 }
20
21 public static function provideCheck() {
22 return [
23 // [ $wgVersion, constraint, expected ]
24 [ '1.25alpha', '>= 1.26', false ],
25 [ '1.25.0', '>= 1.26', false ],
26 [ '1.26alpha', '>= 1.26', true ],
27 [ '1.26alpha', '>= 1.26.0', true ],
28 [ '1.26alpha', '>= 1.26.0-stable', false ],
29 [ '1.26.0', '>= 1.26.0-stable', true ],
30 [ '1.26.1', '>= 1.26.0-stable', true ],
31 [ '1.27.1', '>= 1.26.0-stable', true ],
32 [ '1.26alpha', '>= 1.26.1', false ],
33 [ '1.26alpha', '>= 1.26alpha', true ],
34 [ '1.26alpha', '>= 1.25', true ],
35 [ '1.26.0-alpha.14', '>= 1.26.0-alpha.15', false ],
36 [ '1.26.0-alpha.14', '>= 1.26.0-alpha.10', true ],
37 [ '1.26.1', '>= 1.26.2, <=1.26.0', false ],
38 [ '1.26.1', '^1.26.2', false ],
39 // Accept anything for un-parsable version strings
40 [ '1.26mwf14', '== 1.25alpha', true ],
41 [ 'totallyinvalid', '== 1.0', true ],
42 ];
43 }
44
45 /**
46 * @dataProvider provideType
47 */
48 public function testType( $given, $expected ) {
49 $checker = new VersionChecker();
50 $checker
51 ->setCoreVersion( '1.0.0' )
52 ->setLoadedExtensionsAndSkins( [
53 'FakeDependency' => [
54 'version' => '1.0.0',
55 ],
56 ] );
57 $this->assertEquals( $expected, $checker->checkArray( [
58 'FakeExtension' => $given,
59 ] )
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
83 /**
84 * Check, if a non-parsable version constraint does not throw an exception or
85 * returns any error message.
86 */
87 public function testInvalidConstraint() {
88 $checker = new VersionChecker();
89 $checker
90 ->setCoreVersion( '1.0.0' )
91 ->setLoadedExtensionsAndSkins( [
92 'FakeDependency' => [
93 'version' => 'not really valid',
94 ],
95 ] );
96 $this->assertEquals( [ "Dependency FakeDependency provides an invalid version string." ],
97 $checker->checkArray( [
98 'FakeExtension' => [
99 'extensions' => [
100 'FakeDependency' => '1.24.3',
101 ],
102 ],
103 ] )
104 );
105
106 $checker = new VersionChecker();
107 $checker
108 ->setCoreVersion( '1.0.0' )
109 ->setLoadedExtensionsAndSkins( [
110 'FakeDependency' => [
111 'version' => '1.24.3',
112 ],
113 ] );
114
115 $this->setExpectedException( 'UnexpectedValueException' );
116 $checker->checkArray( [
117 'FakeExtension' => [
118 'FakeDependency' => 'not really valid',
119 ]
120 ] );
121 }
122 }