2015-05-14 05:51:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
2016-12-15 23:09:26 +00:00
|
|
|
* @covers VersionChecker
|
2015-05-14 05:51:55 +00:00
|
|
|
*/
|
2018-02-17 12:29:13 +00:00
|
|
|
class VersionCheckerTest extends PHPUnit\Framework\TestCase {
|
2017-12-29 23:22:37 +00:00
|
|
|
|
|
|
|
|
use MediaWikiCoversValidator;
|
2018-04-12 16:49:27 +00:00
|
|
|
use PHPUnit4And6Compat;
|
2017-12-29 23:22:37 +00:00
|
|
|
|
2015-05-14 05:51:55 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideCheck
|
|
|
|
|
*/
|
|
|
|
|
public function testCheck( $coreVersion, $constraint, $expected ) {
|
2016-12-15 23:09:26 +00:00
|
|
|
$checker = new VersionChecker( $coreVersion );
|
2016-12-03 18:06:46 +00:00
|
|
|
$this->assertEquals( $expected, !(bool)$checker->checkArray( [
|
|
|
|
|
'FakeExtension' => [
|
|
|
|
|
'MediaWiki' => $constraint,
|
|
|
|
|
],
|
|
|
|
|
] )
|
|
|
|
|
);
|
2015-05-14 05:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideCheck() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2016-07-10 15:23:29 +00:00
|
|
|
// [ $wgVersion, constraint, expected ]
|
2016-02-17 09:09:32 +00:00
|
|
|
[ '1.25alpha', '>= 1.26', false ],
|
|
|
|
|
[ '1.25.0', '>= 1.26', false ],
|
|
|
|
|
[ '1.26alpha', '>= 1.26', true ],
|
|
|
|
|
[ '1.26alpha', '>= 1.26.0', true ],
|
|
|
|
|
[ '1.26alpha', '>= 1.26.0-stable', false ],
|
|
|
|
|
[ '1.26.0', '>= 1.26.0-stable', true ],
|
|
|
|
|
[ '1.26.1', '>= 1.26.0-stable', true ],
|
|
|
|
|
[ '1.27.1', '>= 1.26.0-stable', true ],
|
|
|
|
|
[ '1.26alpha', '>= 1.26.1', false ],
|
|
|
|
|
[ '1.26alpha', '>= 1.26alpha', true ],
|
|
|
|
|
[ '1.26alpha', '>= 1.25', true ],
|
|
|
|
|
[ '1.26.0-alpha.14', '>= 1.26.0-alpha.15', false ],
|
|
|
|
|
[ '1.26.0-alpha.14', '>= 1.26.0-alpha.10', true ],
|
|
|
|
|
[ '1.26.1', '>= 1.26.2, <=1.26.0', false ],
|
|
|
|
|
[ '1.26.1', '^1.26.2', false ],
|
2015-05-14 05:51:55 +00:00
|
|
|
// Accept anything for un-parsable version strings
|
2016-02-17 09:09:32 +00:00
|
|
|
[ '1.26mwf14', '== 1.25alpha', true ],
|
|
|
|
|
[ 'totallyinvalid', '== 1.0', true ],
|
|
|
|
|
];
|
2015-05-14 05:51:55 +00:00
|
|
|
}
|
registration: Allow specifying extension dependencies
There are some extensoins that depend upon another extension or skin,
usually in different ways:
* A constant that is added in the dependency extension, and the
existence of is checked for. This is problematic because it requires a
specific load order.
* Checking whether a specific class exists. This is problematic because
it is extremely fragile, and breaks whenever the class is renamed.
* Checking ExtensionRegistry::isLoaded(). This is mostly there, but it
only checks at runtime, and doesn't provide any machine readable data.
Furthermore, developers implement each one differently, with very little
standardization.
With this, extensions may now specify what other extensions they depend
on. This is for explicit *hard* dependencies that must be installed.
For example:
"requires": {
"MediaWiki": ">= 1.25.0",
"extensions": {
"FakeExtension": "*"
},
"skins": {
"FakeSkin": "*"
}
}
This would add a minimum requirement on MediaWiki 1.25.0+ (already
implemented), as well as the requirement that the FakeExtension extension
needs to be installed, as well as the FakeSkin skin. A wildcard (*) is
used instead of an explicit version requirement as many extensions do
not actually version themselves, and there is no consistent versioning
scheme yet.
Bug: T117277
Change-Id: If1cccee1a16a867a71bb0285691c400443d8a30a
2016-12-03 18:19:25 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideType
|
|
|
|
|
*/
|
|
|
|
|
public function testType( $given, $expected ) {
|
2016-12-15 23:09:26 +00:00
|
|
|
$checker = new VersionChecker( '1.0.0' );
|
registration: Allow specifying extension dependencies
There are some extensoins that depend upon another extension or skin,
usually in different ways:
* A constant that is added in the dependency extension, and the
existence of is checked for. This is problematic because it requires a
specific load order.
* Checking whether a specific class exists. This is problematic because
it is extremely fragile, and breaks whenever the class is renamed.
* Checking ExtensionRegistry::isLoaded(). This is mostly there, but it
only checks at runtime, and doesn't provide any machine readable data.
Furthermore, developers implement each one differently, with very little
standardization.
With this, extensions may now specify what other extensions they depend
on. This is for explicit *hard* dependencies that must be installed.
For example:
"requires": {
"MediaWiki": ">= 1.25.0",
"extensions": {
"FakeExtension": "*"
},
"skins": {
"FakeSkin": "*"
}
}
This would add a minimum requirement on MediaWiki 1.25.0+ (already
implemented), as well as the requirement that the FakeExtension extension
needs to be installed, as well as the FakeSkin skin. A wildcard (*) is
used instead of an explicit version requirement as many extensions do
not actually version themselves, and there is no consistent versioning
scheme yet.
Bug: T117277
Change-Id: If1cccee1a16a867a71bb0285691c400443d8a30a
2016-12-03 18:19:25 +00:00
|
|
|
$checker
|
|
|
|
|
->setLoadedExtensionsAndSkins( [
|
|
|
|
|
'FakeDependency' => [
|
|
|
|
|
'version' => '1.0.0',
|
|
|
|
|
],
|
2018-02-10 07:14:07 +00:00
|
|
|
'NoVersionGiven' => [],
|
registration: Allow specifying extension dependencies
There are some extensoins that depend upon another extension or skin,
usually in different ways:
* A constant that is added in the dependency extension, and the
existence of is checked for. This is problematic because it requires a
specific load order.
* Checking whether a specific class exists. This is problematic because
it is extremely fragile, and breaks whenever the class is renamed.
* Checking ExtensionRegistry::isLoaded(). This is mostly there, but it
only checks at runtime, and doesn't provide any machine readable data.
Furthermore, developers implement each one differently, with very little
standardization.
With this, extensions may now specify what other extensions they depend
on. This is for explicit *hard* dependencies that must be installed.
For example:
"requires": {
"MediaWiki": ">= 1.25.0",
"extensions": {
"FakeExtension": "*"
},
"skins": {
"FakeSkin": "*"
}
}
This would add a minimum requirement on MediaWiki 1.25.0+ (already
implemented), as well as the requirement that the FakeExtension extension
needs to be installed, as well as the FakeSkin skin. A wildcard (*) is
used instead of an explicit version requirement as many extensions do
not actually version themselves, and there is no consistent versioning
scheme yet.
Bug: T117277
Change-Id: If1cccee1a16a867a71bb0285691c400443d8a30a
2016-12-03 18:19:25 +00:00
|
|
|
] );
|
|
|
|
|
$this->assertEquals( $expected, $checker->checkArray( [
|
|
|
|
|
'FakeExtension' => $given,
|
|
|
|
|
] )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideType() {
|
|
|
|
|
return [
|
|
|
|
|
// valid type
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'extensions' => [
|
|
|
|
|
'FakeDependency' => '1.0.0'
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'MediaWiki' => '1.0.0'
|
|
|
|
|
],
|
|
|
|
|
[]
|
|
|
|
|
],
|
2018-02-10 07:14:07 +00:00
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'extensions' => [
|
|
|
|
|
'NoVersionGiven' => '*'
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'extensions' => [
|
|
|
|
|
'NoVersionGiven' => '1.0',
|
|
|
|
|
]
|
|
|
|
|
],
|
2018-04-08 23:26:01 +00:00
|
|
|
[ [
|
|
|
|
|
'incompatible' => 'FakeExtension',
|
|
|
|
|
'type' => 'incompatible-extensions',
|
|
|
|
|
'msg' => 'NoVersionGiven does not expose its version, but FakeExtension requires: 1.0.'
|
|
|
|
|
] ],
|
2018-02-10 07:14:07 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'extensions' => [
|
|
|
|
|
'Missing' => '*',
|
|
|
|
|
]
|
|
|
|
|
],
|
2018-04-08 23:26:01 +00:00
|
|
|
[ [
|
|
|
|
|
'missing' => 'Missing',
|
|
|
|
|
'type' => 'missing-extensions',
|
|
|
|
|
'msg' => 'FakeExtension requires Missing to be installed.',
|
|
|
|
|
] ],
|
2018-02-10 07:14:07 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'extensions' => [
|
|
|
|
|
'FakeDependency' => '2.0.0',
|
|
|
|
|
]
|
|
|
|
|
],
|
2018-04-08 23:26:01 +00:00
|
|
|
[ [
|
|
|
|
|
'incompatible' => 'FakeExtension',
|
|
|
|
|
'type' => 'incompatible-extensions',
|
|
|
|
|
// phpcs:ignore Generic.Files.LineLength.TooLong
|
|
|
|
|
'msg' => 'FakeExtension is not compatible with the current installed version of FakeDependency (1.0.0), it requires: 2.0.0.'
|
|
|
|
|
] ],
|
2018-02-10 07:14:07 +00:00
|
|
|
]
|
registration: Allow specifying extension dependencies
There are some extensoins that depend upon another extension or skin,
usually in different ways:
* A constant that is added in the dependency extension, and the
existence of is checked for. This is problematic because it requires a
specific load order.
* Checking whether a specific class exists. This is problematic because
it is extremely fragile, and breaks whenever the class is renamed.
* Checking ExtensionRegistry::isLoaded(). This is mostly there, but it
only checks at runtime, and doesn't provide any machine readable data.
Furthermore, developers implement each one differently, with very little
standardization.
With this, extensions may now specify what other extensions they depend
on. This is for explicit *hard* dependencies that must be installed.
For example:
"requires": {
"MediaWiki": ">= 1.25.0",
"extensions": {
"FakeExtension": "*"
},
"skins": {
"FakeSkin": "*"
}
}
This would add a minimum requirement on MediaWiki 1.25.0+ (already
implemented), as well as the requirement that the FakeExtension extension
needs to be installed, as well as the FakeSkin skin. A wildcard (*) is
used instead of an explicit version requirement as many extensions do
not actually version themselves, and there is no consistent versioning
scheme yet.
Bug: T117277
Change-Id: If1cccee1a16a867a71bb0285691c400443d8a30a
2016-12-03 18:19:25 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check, if a non-parsable version constraint does not throw an exception or
|
|
|
|
|
* returns any error message.
|
|
|
|
|
*/
|
|
|
|
|
public function testInvalidConstraint() {
|
2016-12-15 23:09:26 +00:00
|
|
|
$checker = new VersionChecker( '1.0.0' );
|
registration: Allow specifying extension dependencies
There are some extensoins that depend upon another extension or skin,
usually in different ways:
* A constant that is added in the dependency extension, and the
existence of is checked for. This is problematic because it requires a
specific load order.
* Checking whether a specific class exists. This is problematic because
it is extremely fragile, and breaks whenever the class is renamed.
* Checking ExtensionRegistry::isLoaded(). This is mostly there, but it
only checks at runtime, and doesn't provide any machine readable data.
Furthermore, developers implement each one differently, with very little
standardization.
With this, extensions may now specify what other extensions they depend
on. This is for explicit *hard* dependencies that must be installed.
For example:
"requires": {
"MediaWiki": ">= 1.25.0",
"extensions": {
"FakeExtension": "*"
},
"skins": {
"FakeSkin": "*"
}
}
This would add a minimum requirement on MediaWiki 1.25.0+ (already
implemented), as well as the requirement that the FakeExtension extension
needs to be installed, as well as the FakeSkin skin. A wildcard (*) is
used instead of an explicit version requirement as many extensions do
not actually version themselves, and there is no consistent versioning
scheme yet.
Bug: T117277
Change-Id: If1cccee1a16a867a71bb0285691c400443d8a30a
2016-12-03 18:19:25 +00:00
|
|
|
$checker
|
|
|
|
|
->setLoadedExtensionsAndSkins( [
|
|
|
|
|
'FakeDependency' => [
|
|
|
|
|
'version' => 'not really valid',
|
|
|
|
|
],
|
|
|
|
|
] );
|
2018-04-08 23:26:01 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
[ [
|
|
|
|
|
'type' => 'invalid-version',
|
|
|
|
|
'msg' => "FakeDependency does not have a valid version string."
|
|
|
|
|
] ],
|
registration: Allow specifying extension dependencies
There are some extensoins that depend upon another extension or skin,
usually in different ways:
* A constant that is added in the dependency extension, and the
existence of is checked for. This is problematic because it requires a
specific load order.
* Checking whether a specific class exists. This is problematic because
it is extremely fragile, and breaks whenever the class is renamed.
* Checking ExtensionRegistry::isLoaded(). This is mostly there, but it
only checks at runtime, and doesn't provide any machine readable data.
Furthermore, developers implement each one differently, with very little
standardization.
With this, extensions may now specify what other extensions they depend
on. This is for explicit *hard* dependencies that must be installed.
For example:
"requires": {
"MediaWiki": ">= 1.25.0",
"extensions": {
"FakeExtension": "*"
},
"skins": {
"FakeSkin": "*"
}
}
This would add a minimum requirement on MediaWiki 1.25.0+ (already
implemented), as well as the requirement that the FakeExtension extension
needs to be installed, as well as the FakeSkin skin. A wildcard (*) is
used instead of an explicit version requirement as many extensions do
not actually version themselves, and there is no consistent versioning
scheme yet.
Bug: T117277
Change-Id: If1cccee1a16a867a71bb0285691c400443d8a30a
2016-12-03 18:19:25 +00:00
|
|
|
$checker->checkArray( [
|
|
|
|
|
'FakeExtension' => [
|
|
|
|
|
'extensions' => [
|
|
|
|
|
'FakeDependency' => '1.24.3',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
] )
|
|
|
|
|
);
|
|
|
|
|
|
2016-12-15 23:09:26 +00:00
|
|
|
$checker = new VersionChecker( '1.0.0' );
|
registration: Allow specifying extension dependencies
There are some extensoins that depend upon another extension or skin,
usually in different ways:
* A constant that is added in the dependency extension, and the
existence of is checked for. This is problematic because it requires a
specific load order.
* Checking whether a specific class exists. This is problematic because
it is extremely fragile, and breaks whenever the class is renamed.
* Checking ExtensionRegistry::isLoaded(). This is mostly there, but it
only checks at runtime, and doesn't provide any machine readable data.
Furthermore, developers implement each one differently, with very little
standardization.
With this, extensions may now specify what other extensions they depend
on. This is for explicit *hard* dependencies that must be installed.
For example:
"requires": {
"MediaWiki": ">= 1.25.0",
"extensions": {
"FakeExtension": "*"
},
"skins": {
"FakeSkin": "*"
}
}
This would add a minimum requirement on MediaWiki 1.25.0+ (already
implemented), as well as the requirement that the FakeExtension extension
needs to be installed, as well as the FakeSkin skin. A wildcard (*) is
used instead of an explicit version requirement as many extensions do
not actually version themselves, and there is no consistent versioning
scheme yet.
Bug: T117277
Change-Id: If1cccee1a16a867a71bb0285691c400443d8a30a
2016-12-03 18:19:25 +00:00
|
|
|
$checker
|
|
|
|
|
->setLoadedExtensionsAndSkins( [
|
|
|
|
|
'FakeDependency' => [
|
|
|
|
|
'version' => '1.24.3',
|
|
|
|
|
],
|
|
|
|
|
] );
|
|
|
|
|
|
2018-01-13 00:02:09 +00:00
|
|
|
$this->setExpectedException( UnexpectedValueException::class );
|
registration: Allow specifying extension dependencies
There are some extensoins that depend upon another extension or skin,
usually in different ways:
* A constant that is added in the dependency extension, and the
existence of is checked for. This is problematic because it requires a
specific load order.
* Checking whether a specific class exists. This is problematic because
it is extremely fragile, and breaks whenever the class is renamed.
* Checking ExtensionRegistry::isLoaded(). This is mostly there, but it
only checks at runtime, and doesn't provide any machine readable data.
Furthermore, developers implement each one differently, with very little
standardization.
With this, extensions may now specify what other extensions they depend
on. This is for explicit *hard* dependencies that must be installed.
For example:
"requires": {
"MediaWiki": ">= 1.25.0",
"extensions": {
"FakeExtension": "*"
},
"skins": {
"FakeSkin": "*"
}
}
This would add a minimum requirement on MediaWiki 1.25.0+ (already
implemented), as well as the requirement that the FakeExtension extension
needs to be installed, as well as the FakeSkin skin. A wildcard (*) is
used instead of an explicit version requirement as many extensions do
not actually version themselves, and there is no consistent versioning
scheme yet.
Bug: T117277
Change-Id: If1cccee1a16a867a71bb0285691c400443d8a30a
2016-12-03 18:19:25 +00:00
|
|
|
$checker->checkArray( [
|
|
|
|
|
'FakeExtension' => [
|
|
|
|
|
'FakeDependency' => 'not really valid',
|
|
|
|
|
]
|
|
|
|
|
] );
|
|
|
|
|
}
|
2015-05-14 05:51:55 +00:00
|
|
|
}
|