MDL-43027 core progress : new method keeps track of progress internally

This commit is contained in:
James Pratt
2014-01-27 17:51:09 +07:00
parent ef81a7c30e
commit eb50c6e198
2 changed files with 90 additions and 16 deletions
+60 -1
View File
@@ -64,7 +64,7 @@ class core_progress_testcase extends basic_testcase {
// Do another progress run at same time, it should be ignored.
$progress->progress(3);
$this->assertFalse($progress->was_update_called());
$this->assert_min_max(0.2, 0.2, $progress);
$this->assert_min_max(0.3, 0.3, $progress);
// End the section. This should cause an update.
$progress->end_progress();
@@ -317,6 +317,65 @@ class core_progress_testcase extends basic_testcase {
}
}
public function test_progress_change() {
$progress = new core_mock_progress();
$progress->start_progress('hello', 50);
for ($n = 1; $n <= 10; $n++) {
$progress->increment_progress();
}
// Check numeric position and indeterminate count.
$this->assert_min_max(0.2, 0.2, $progress);
$this->assertEquals(1, $progress->get_progress_count());
// Make some progress and check that the time limit gets added.
$progress->step_time();
for ($n = 1; $n <= 20; $n++) {
$progress->increment_progress();
}
$this->assertTrue($progress->was_update_called());
// Check the new value.
$this->assert_min_max(0.6, 0.6, $progress);
$this->assertEquals(2, $progress->get_progress_count());
for ($n = 1; $n <= 10; $n++) {
$progress->increment_progress();
}
$this->assertFalse($progress->was_update_called());
$this->assert_min_max(0.8, 0.8, $progress);
$this->assertEquals(2, $progress->get_progress_count());
// Do another progress run at same time, it should be ignored.
$progress->increment_progress(5);
$this->assertFalse($progress->was_update_called());
$this->assert_min_max(0.9, 0.9, $progress);
$this->assertEquals(2, $progress->get_progress_count());
for ($n = 1; $n <= 3; $n++) {
$progress->step_time();
$progress->increment_progress(1);
}
$this->assertTrue($progress->was_update_called());
$this->assert_min_max(0.96, 0.96, $progress);
$this->assertEquals(5, $progress->get_progress_count());
// End the section. This should cause an update.
$progress->end_progress();
$this->assertTrue($progress->was_update_called());
$this->assertEquals(5, $progress->get_progress_count());
// Because there are no sections left open, it thinks we finished.
$this->assert_min_max(1.0, 1.0, $progress);
}
/**
* Checks the current progress values are as expected.
*