Move ResultWrapper subclasses to Rdbms
[mediawiki.git] / tests / phpunit / includes / registration / VersionCheckerTest.php
blob9ee58816dfa8968ff183c8cf4ddfd35342063086
1 <?php
3 /**
4 * @covers VersionChecker
5 */
6 class VersionCheckerTest extends PHPUnit_Framework_TestCase {
7 /**
8 * @dataProvider provideCheck
9 */
10 public function testCheck( $coreVersion, $constraint, $expected ) {
11 $checker = new VersionChecker( $coreVersion );
12 $this->assertEquals( $expected, !(bool)$checker->checkArray( [
13 'FakeExtension' => [
14 'MediaWiki' => $constraint,
16 ] )
20 public static function provideCheck() {
21 return [
22 // [ $wgVersion, constraint, expected ]
23 [ '1.25alpha', '>= 1.26', false ],
24 [ '1.25.0', '>= 1.26', false ],
25 [ '1.26alpha', '>= 1.26', true ],
26 [ '1.26alpha', '>= 1.26.0', true ],
27 [ '1.26alpha', '>= 1.26.0-stable', false ],
28 [ '1.26.0', '>= 1.26.0-stable', true ],
29 [ '1.26.1', '>= 1.26.0-stable', true ],
30 [ '1.27.1', '>= 1.26.0-stable', true ],
31 [ '1.26alpha', '>= 1.26.1', false ],
32 [ '1.26alpha', '>= 1.26alpha', true ],
33 [ '1.26alpha', '>= 1.25', true ],
34 [ '1.26.0-alpha.14', '>= 1.26.0-alpha.15', false ],
35 [ '1.26.0-alpha.14', '>= 1.26.0-alpha.10', true ],
36 [ '1.26.1', '>= 1.26.2, <=1.26.0', false ],
37 [ '1.26.1', '^1.26.2', false ],
38 // Accept anything for un-parsable version strings
39 [ '1.26mwf14', '== 1.25alpha', true ],
40 [ 'totallyinvalid', '== 1.0', true ],
44 /**
45 * @dataProvider provideType
47 public function testType( $given, $expected ) {
48 $checker = new VersionChecker( '1.0.0' );
49 $checker
50 ->setLoadedExtensionsAndSkins( [
51 'FakeDependency' => [
52 'version' => '1.0.0',
54 ] );
55 $this->assertEquals( $expected, $checker->checkArray( [
56 'FakeExtension' => $given,
57 ] )
61 public static function provideType() {
62 return [
63 // valid type
66 'extensions' => [
67 'FakeDependency' => '1.0.0'
74 'MediaWiki' => '1.0.0'
81 /**
82 * Check, if a non-parsable version constraint does not throw an exception or
83 * returns any error message.
85 public function testInvalidConstraint() {
86 $checker = new VersionChecker( '1.0.0' );
87 $checker
88 ->setLoadedExtensionsAndSkins( [
89 'FakeDependency' => [
90 'version' => 'not really valid',
92 ] );
93 $this->assertEquals( [ "FakeDependency does not have a valid version string." ],
94 $checker->checkArray( [
95 'FakeExtension' => [
96 'extensions' => [
97 'FakeDependency' => '1.24.3',
103 $checker = new VersionChecker( '1.0.0' );
104 $checker
105 ->setLoadedExtensionsAndSkins( [
106 'FakeDependency' => [
107 'version' => '1.24.3',
109 ] );
111 $this->setExpectedException( 'UnexpectedValueException' );
112 $checker->checkArray( [
113 'FakeExtension' => [
114 'FakeDependency' => 'not really valid',
116 ] );