1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
/**
|
|
|
17 |
*
|
|
|
18 |
*
|
|
|
19 |
* @package
|
|
|
20 |
* @copyright 2016 The Open University
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
defined('MOODLE_INTERNAL') || die();
|
|
|
25 |
|
|
|
26 |
class progress_display_test extends \advanced_testcase {
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Test basic function of progress_display, updating status and outputting wibbler.
|
|
|
30 |
*/
|
|
|
31 |
public function test_progress_display_update() {
|
|
|
32 |
ob_start();
|
|
|
33 |
$progress = new core_mock_progress_display();
|
|
|
34 |
$progress->start_progress('');
|
|
|
35 |
$this->assertEquals(1, $progress->get_current_state());
|
|
|
36 |
$this->assertEquals(1, $progress->get_direction());
|
|
|
37 |
$this->assertTimeCurrent($progress->get_last_wibble());
|
|
|
38 |
// Wait 1 second to ensure that all code in update_progress is run.
|
|
|
39 |
$this->waitForSecond();
|
|
|
40 |
$progress->update_progress();
|
|
|
41 |
$this->assertEquals(2, $progress->get_current_state());
|
|
|
42 |
$this->assertEquals(1, $progress->get_direction());
|
|
|
43 |
$this->assertTimeCurrent($progress->get_last_wibble());
|
|
|
44 |
$output = ob_get_clean();
|
|
|
45 |
$this->assertStringContainsString('wibbler', $output);
|
|
|
46 |
$this->assertStringContainsString('wibble state0', $output);
|
|
|
47 |
$this->assertStringContainsString('wibble state1', $output);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Test wibbler states. Wibbler should reverse direction at the start and end of its sequence.
|
|
|
52 |
*/
|
|
|
53 |
public function test_progress_display_wibbler() {
|
|
|
54 |
ob_start();
|
|
|
55 |
$progress = new core_mock_progress_display();
|
|
|
56 |
$progress->start_progress('');
|
|
|
57 |
$this->assertEquals(1, $progress->get_direction());
|
|
|
58 |
|
|
|
59 |
// Set wibbler to final state and progress to check that it reverses direction.
|
|
|
60 |
$progress->set_current_state(core_mock_progress_display::WIBBLE_STATES);
|
|
|
61 |
$this->waitForSecond();
|
|
|
62 |
$progress->update_progress();
|
|
|
63 |
$this->assertEquals(core_mock_progress_display::WIBBLE_STATES - 1, $progress->get_current_state());
|
|
|
64 |
$this->assertEquals(-1, $progress->get_direction());
|
|
|
65 |
|
|
|
66 |
// Set wibbler to beginning and progress to check that it reverses direction.
|
|
|
67 |
$progress->set_current_state(0);
|
|
|
68 |
$this->waitForSecond();
|
|
|
69 |
$progress->update_progress();
|
|
|
70 |
$this->assertEquals(1, $progress->get_current_state());
|
|
|
71 |
$this->assertEquals(1, $progress->get_direction());
|
|
|
72 |
$output = ob_get_clean();
|
|
|
73 |
$this->assertStringContainsString('wibbler', $output);
|
|
|
74 |
$this->assertStringContainsString('wibble state0', $output);
|
|
|
75 |
$this->assertStringContainsString('wibble state13', $output);
|
|
|
76 |
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
/**
|
|
|
82 |
* Helper class that allows access to private values
|
|
|
83 |
*/
|
|
|
84 |
class core_mock_progress_display extends \core\progress\display {
|
|
|
85 |
public function get_last_wibble() {
|
|
|
86 |
return $this->lastwibble;
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
public function get_current_state() {
|
|
|
90 |
return $this->currentstate;
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
public function get_direction() {
|
|
|
94 |
return $this->direction;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
public function set_current_state($state) {
|
|
|
98 |
$this->currentstate = $state;
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
public function set_direction($direction) {
|
|
|
102 |
$this->direction = $direction;
|
|
|
103 |
}
|
|
|
104 |
}
|