MDL-20438 finishing the updatenotifybuilds feature

Unit tests say that all.
This commit is contained in:
David Mudrak
2012-03-30 11:05:42 +02:00
parent 21cde6ac14
commit 4442cc8036
2 changed files with 68 additions and 7 deletions
+36 -3
View File
@@ -577,6 +577,8 @@ class available_update_checker {
protected $recentresponse = null;
/** @var null|string the numerical version of the local Moodle code */
protected $currentversion = null;
/** @var null|string the release info of the local Moodle code */
protected $currentrelease = null;
/** @var null|string branch of the local Moodle code */
protected $currentbranch = null;
/** @var array of (string)frankestyle => (string)version list of additional plugins deployed at this site */
@@ -680,7 +682,9 @@ class available_update_checker {
if ($update->version <= $this->currentversion) {
continue;
}
// todo notifybuild check
if (empty($options['notifybuilds']) and $this->is_same_release($update->release)) {
continue;
}
}
$updates[] = $update;
}
@@ -899,7 +903,7 @@ class available_update_checker {
}
/**
* Sets the properties currentversion, currentbranch and currentplugins
* Sets the properties currentversion, currentrelease, currentbranch and currentplugins
*
* @param bool $forcereload
*/
@@ -913,7 +917,7 @@ class available_update_checker {
require($CFG->dirroot.'/version.php');
$this->currentversion = $version;
$this->currentrelease = $release;
$this->currentbranch = moodle_major_version(true);
$pluginman = plugin_manager::instance();
@@ -1255,6 +1259,35 @@ class available_update_checker {
message_send($message);
}
}
/**
* Compare two release labels and decide if they are the same
*
* @param string $remote release info of the available update
* @param null|string $local release info of the local code, defaults to $release defined in version.php
* @return boolean true if the releases declare the same minor+major version
*/
protected function is_same_release($remote, $local=null) {
if (is_null($local)) {
$this->load_current_environment();
$local = $this->currentrelease;
}
$pattern = '/^([0-9\.\+]+)([^(]*)/';
preg_match($pattern, $remote, $remotematches);
preg_match($pattern, $local, $localmatches);
$remotematches[1] = str_replace('+', '', $remotematches[1]);
$localmatches[1] = str_replace('+', '', $localmatches[1]);
if ($remotematches[1] === $localmatches[1] and rtrim($remotematches[2]) === rtrim($localmatches[2])) {
return true;
} else {
return false;
}
}
}
+32 -4
View File
@@ -147,11 +147,16 @@ class testable_available_update_checker extends available_update_checker {
return parent::compare_responses($old, $new);
}
public function is_same_release($remote, $local=null) {
return parent::is_same_release($remote, $local);
}
protected function load_current_environment($forcereload=false) {
}
public function fake_current_environment($version, $branch, array $plugins) {
public function fake_current_environment($version, $release, $branch, array $plugins) {
$this->currentversion = $version;
$this->currentrelease = $release;
$this->currentbranch = $branch;
$this->currentplugins = $plugins;
}
@@ -290,15 +295,15 @@ class available_update_checker_test extends UnitTestCase {
$provider = testable_available_update_checker::instance();
$this->assertTrue($provider instanceof available_update_checker);
$provider->fake_current_environment(2012060102.00, '2.3', array());
$provider->fake_current_environment(2012060102.00, '2.3.2 (Build: 20121012)', '2.3', array());
$updates = $provider->get_update_info('core');
$this->assertEqual(count($updates), 2);
$provider->fake_current_environment(2012060103.00, '2.3', array());
$provider->fake_current_environment(2012060103.00, '2.3.3 (Build: 20121212)', '2.3', array());
$updates = $provider->get_update_info('core');
$this->assertEqual(count($updates), 1);
$provider->fake_current_environment(2012060103.00, '2.3', array());
$provider->fake_current_environment(2012060103.00, '2.3.3 (Build: 20121212)', '2.3', array());
$updates = $provider->get_update_info('core', array('minmaturity' => MATURITY_STABLE));
$this->assertNull($updates);
}
@@ -486,4 +491,27 @@ class available_update_checker_test extends UnitTestCase {
$this->expectException('available_update_checker_exception');
$cmp = $provider->compare_responses($broken, $broken);
}
public function test_is_same_release_explicit() {
$provider = testable_available_update_checker::instance();
$this->assertTrue($provider->is_same_release('2.3dev (Build: 20120323)', '2.3dev (Build: 20120323)'));
$this->assertTrue($provider->is_same_release('2.3dev (Build: 20120323)', '2.3dev (Build: 20120330)'));
$this->assertFalse($provider->is_same_release('2.3dev (Build: 20120529)', '2.3 (Build: 20120601)'));
$this->assertFalse($provider->is_same_release('2.3dev', '2.3 dev'));
$this->assertFalse($provider->is_same_release('2.3.1', '2.3'));
$this->assertFalse($provider->is_same_release('2.3.1', '2.3.2'));
$this->assertTrue($provider->is_same_release('2.3.2+', '2.3.2')); // yes, really
$this->assertTrue($provider->is_same_release('2.3.2 (Build: 123456)', '2.3.2+ (Build: 123457)'));
$this->assertFalse($provider->is_same_release('3.0 Community Edition', '3.0 Enterprise Edition'));
$this->assertTrue($provider->is_same_release('3.0 Community Edition', '3.0 Community Edition (Build: 20290101)'));
}
public function test_is_same_release_implicit() {
$provider = testable_available_update_checker::instance();
$provider->fake_current_environment(2012060102.00, '2.3.2 (Build: 20121012)', '2.3', array());
$this->assertTrue($provider->is_same_release('2.3.2'));
$this->assertTrue($provider->is_same_release('2.3.2+'));
$this->assertTrue($provider->is_same_release('2.3.2+ (Build: 20121013)'));
$this->assertFalse($provider->is_same_release('2.4dev (Build: 20121012)'));
}
}