Merge branch 'MDL-58454-master' of git://github.com/junpataleta/moodle
[moodle.git] / lib / tests / progress_display_test.php
blob278c7ea6bda1c4c321b08f8570541f1959435f5f
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.
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 /**
19 * @package
20 * @copyright 2016 The Open University
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 defined('MOODLE_INTERNAL') || die();
26 class progress_display_test extends \advanced_testcase {
28 /**
29 * Test basic function of progress_display, updating status and outputting wibbler.
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->assertContains('wibbler', $output);
46 $this->assertContains('wibble state0', $output);
47 $this->assertContains('wibble state1', $output);
50 /**
51 * Test wibbler states. Wibbler should reverse direction at the start and end of its sequence.
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());
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());
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->assertContains('wibbler', $output);
74 $this->assertContains('wibble state0', $output);
75 $this->assertContains('wibble state13', $output);
81 /**
82 * Helper class that allows access to private values
84 class core_mock_progress_display extends \core\progress\display {
85 public function get_last_wibble() {
86 return $this->lastwibble;
89 public function get_current_state() {
90 return $this->currentstate;
93 public function get_direction() {
94 return $this->direction;
97 public function set_current_state($state) {
98 $this->currentstate = $state;
101 public function set_direction($direction) {
102 $this->direction = $direction;