Merge branch 'MDL-41817-master' of git://github.com/sammarshallou/moodle

This commit is contained in:
Sam Hemelryk
2013-09-17 15:26:06 +12:00
2 changed files with 27 additions and 5 deletions
@@ -87,9 +87,9 @@ abstract class core_backup_progress {
*/
public function start_progress($description, $max = self::INDETERMINATE,
$parentcount = 1) {
if ($max != self::INDETERMINATE && $max <= 0) {
if ($max != self::INDETERMINATE && $max < 0) {
throw new coding_exception(
'start_progress() max value cannot be zero or negative');
'start_progress() max value cannot be negative');
}
if ($parentcount < 1) {
throw new coding_exception(
+25 -3
View File
@@ -213,6 +213,28 @@ class backup_progress_testcase extends basic_testcase {
set_time_limit(0);
}
/**
* To avoid causing problems, progress needs to work for sections that have
* zero entries.
*/
public function test_zero() {
$progress = new core_backup_mock_progress();
$progress->start_progress('parent', 100);
$progress->progress(1);
$this->assert_min_max(0.01, 0.01, $progress);
$progress->start_progress('child', 0);
// For 'zero' progress, the progress section as immediately complete
// within the parent count, so it moves up to 2%.
$this->assert_min_max(0.02, 0.02, $progress);
$progress->progress(0);
$this->assert_min_max(0.02, 0.02, $progress);
$progress->end_progress();
$this->assert_min_max(0.02, 0.02, $progress);
set_time_limit(0);
}
/**
* Tests for any exceptions due to invalid calls.
*/
@@ -245,12 +267,12 @@ class backup_progress_testcase extends basic_testcase {
$this->assertEquals(1, preg_match('~must be 1~', $e->getMessage()));
}
// Check invalid start (0).
// Check invalid start (-2).
try {
$progress->start_progress('hello', 0);
$progress->start_progress('hello', -2);
$this->fail();
} catch (coding_exception $e) {
$this->assertEquals(1, preg_match('~cannot be zero or negative~', $e->getMessage()));
$this->assertEquals(1, preg_match('~cannot be negative~', $e->getMessage()));
}
// Indeterminate when value expected.