wiki.techinc.nl/tests/phpunit/includes/registration/CoreVersionCheckerTest.php
Kunal Mehta cef1f31167 registration: Allow extensions to specify which MW core versions they require
This adds a "requires" property to extension.json, which extensions and
skins can use to indicate which versions of MediaWiki core they support.
The hacky wfUseMW() is now deprecated in favor of this.

Rather than writing our own version constraint and parser library, we
can re-use composer's, which was recently split out into a separate
library named "composer/semver" for this patch.

Any syntax accepted by composer[1] is available for usage here. Test
cases have been provided to demonstrate how versions are parsed. For now
it is recommended that people stick to expressing compatability with
stable versions (e.g. ">= 1.26").

This patch does not support requiring specific MediaWiki core WMF
branches, since those do not follow the standard semver format that
composer parses. If we are unable to parse $wgVersion, all checking will
be skipped and reported as compatible.

[1] https://getcomposer.org/doc/01-basic-usage.md#package-versions

Bug: T99084
Change-Id: I7785827216e16c596356d0ae42d6b30f3f179f10
2015-09-21 09:56:53 -07:00

38 lines
1.3 KiB
PHP

<?php
/**
* @covers CoreVersionChecker
*/
class CoreVersionCheckerTest extends PHPUnit_Framework_TestCase {
/**
* @dataProvider provideCheck
*/
public function testCheck( $coreVersion, $constraint, $expected ) {
$checker = new CoreVersionChecker( $coreVersion );
$this->assertEquals( $expected, $checker->check( $constraint ) );
}
public static function provideCheck() {
return array(
// array( $wgVersion, constraint, expected )
array( '1.25alpha', '>= 1.26', false ),
array( '1.25.0', '>= 1.26', false ),
array( '1.26alpha', '>= 1.26', true ),
array( '1.26alpha', '>= 1.26.0', true ),
array( '1.26alpha', '>= 1.26.0-stable', false ),
array( '1.26.0', '>= 1.26.0-stable', true ),
array( '1.26.1', '>= 1.26.0-stable', true ),
array( '1.27.1', '>= 1.26.0-stable', true ),
array( '1.26alpha', '>= 1.26.1', false ),
array( '1.26alpha', '>= 1.26alpha', true ),
array( '1.26alpha', '>= 1.25', true ),
array( '1.26.0-alpha.14', '>= 1.26.0-alpha.15', false ),
array( '1.26.0-alpha.14', '>= 1.26.0-alpha.10', true ),
array( '1.26.1', '>= 1.26.2, <=1.26.0', false ),
array( '1.26.1', '^1.26.2', false ),
// Accept anything for un-parsable version strings
array( '1.26mwf14', '== 1.25alpha', true ),
array( 'totallyinvalid', '== 1.0', true ),
);
}
}