Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Commit

Permalink
Merge branch 'MDL-41817-master' of git://github.com/sammarshallou/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed Sep 17, 2013
2 parents 26c9c58 + 6a0189e commit d4d9762
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions backup/util/progress/core_backup_progress.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
28 changes: 25 additions & 3 deletions backup/util/progress/tests/progress_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,28 @@ public function test_realistic() {
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.
*/
Expand Down Expand Up @@ -245,12 +267,12 @@ public function test_exceptions() {
$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.
Expand Down

0 comments on commit d4d9762

Please sign in to comment.