As there will likely be extensions bundled with the 1.31 release that depend upon other extensions, we should have the installer prevent users from enabling extensions that depend on other, not-enabled extensions. We can build a dependency map from extension.json's "requires" component. On the client-side, we'll first disable all checkboxes that require other extensions, and evaluate each checkbox click, updating the disabled checkboxes as possible. This required some refactoring of how ExtensionRegistry reports issues with dependency resolution so we could get a list of what was missing. While we're at it, sort the extensions under headings by type. This does not support skins that have dependencies yet (T186092). Bug: T31134 Bug: T55985 Change-Id: I5f0e3b1b540b5ef6f9b8e3fc2bbaad1c65b4b680
171 lines
3.8 KiB
PHP
171 lines
3.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @covers VersionChecker
|
|
*/
|
|
class VersionCheckerTest extends PHPUnit\Framework\TestCase {
|
|
|
|
use MediaWikiCoversValidator;
|
|
|
|
/**
|
|
* @dataProvider provideCheck
|
|
*/
|
|
public function testCheck( $coreVersion, $constraint, $expected ) {
|
|
$checker = new VersionChecker( $coreVersion );
|
|
$this->assertEquals( $expected, !(bool)$checker->checkArray( [
|
|
'FakeExtension' => [
|
|
'MediaWiki' => $constraint,
|
|
],
|
|
] )
|
|
);
|
|
}
|
|
|
|
public static function provideCheck() {
|
|
return [
|
|
// [ $wgVersion, constraint, expected ]
|
|
[ '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 ],
|
|
// Accept anything for un-parsable version strings
|
|
[ '1.26mwf14', '== 1.25alpha', true ],
|
|
[ 'totallyinvalid', '== 1.0', true ],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideType
|
|
*/
|
|
public function testType( $given, $expected ) {
|
|
$checker = new VersionChecker( '1.0.0' );
|
|
$checker
|
|
->setLoadedExtensionsAndSkins( [
|
|
'FakeDependency' => [
|
|
'version' => '1.0.0',
|
|
],
|
|
'NoVersionGiven' => [],
|
|
] );
|
|
$this->assertEquals( $expected, $checker->checkArray( [
|
|
'FakeExtension' => $given,
|
|
] )
|
|
);
|
|
}
|
|
|
|
public static function provideType() {
|
|
return [
|
|
// valid type
|
|
[
|
|
[
|
|
'extensions' => [
|
|
'FakeDependency' => '1.0.0'
|
|
]
|
|
],
|
|
[]
|
|
],
|
|
[
|
|
[
|
|
'MediaWiki' => '1.0.0'
|
|
],
|
|
[]
|
|
],
|
|
[
|
|
[
|
|
'extensions' => [
|
|
'NoVersionGiven' => '*'
|
|
]
|
|
],
|
|
[],
|
|
],
|
|
[
|
|
[
|
|
'extensions' => [
|
|
'NoVersionGiven' => '1.0',
|
|
]
|
|
],
|
|
[ [
|
|
'incompatible' => 'FakeExtension',
|
|
'type' => 'incompatible-extensions',
|
|
'msg' => 'NoVersionGiven does not expose its version, but FakeExtension requires: 1.0.'
|
|
] ],
|
|
],
|
|
[
|
|
[
|
|
'extensions' => [
|
|
'Missing' => '*',
|
|
]
|
|
],
|
|
[ [
|
|
'missing' => 'Missing',
|
|
'type' => 'missing-extensions',
|
|
'msg' => 'FakeExtension requires Missing to be installed.',
|
|
] ],
|
|
],
|
|
[
|
|
[
|
|
'extensions' => [
|
|
'FakeDependency' => '2.0.0',
|
|
]
|
|
],
|
|
[ [
|
|
'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.'
|
|
] ],
|
|
]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Check, if a non-parsable version constraint does not throw an exception or
|
|
* returns any error message.
|
|
*/
|
|
public function testInvalidConstraint() {
|
|
$checker = new VersionChecker( '1.0.0' );
|
|
$checker
|
|
->setLoadedExtensionsAndSkins( [
|
|
'FakeDependency' => [
|
|
'version' => 'not really valid',
|
|
],
|
|
] );
|
|
$this->assertEquals(
|
|
[ [
|
|
'type' => 'invalid-version',
|
|
'msg' => "FakeDependency does not have a valid version string."
|
|
] ],
|
|
$checker->checkArray( [
|
|
'FakeExtension' => [
|
|
'extensions' => [
|
|
'FakeDependency' => '1.24.3',
|
|
],
|
|
],
|
|
] )
|
|
);
|
|
|
|
$checker = new VersionChecker( '1.0.0' );
|
|
$checker
|
|
->setLoadedExtensionsAndSkins( [
|
|
'FakeDependency' => [
|
|
'version' => '1.24.3',
|
|
],
|
|
] );
|
|
|
|
$this->setExpectedException( UnexpectedValueException::class );
|
|
$checker->checkArray( [
|
|
'FakeExtension' => [
|
|
'FakeDependency' => 'not really valid',
|
|
]
|
|
] );
|
|
}
|
|
}
|