Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 32... Línea 32...
32
 * @category   test
32
 * @category   test
33
 * @copyright  2009 The Open University
33
 * @copyright  2009 The Open University
34
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
35
 */
36
class questionattemptstep_test extends \advanced_testcase {
36
class questionattemptstep_test extends \advanced_testcase {
37
    public function test_initial_state_unprocessed() {
37
    public function test_initial_state_unprocessed(): void {
38
        $step = new question_attempt_step();
38
        $step = new question_attempt_step();
39
        $this->assertEquals(question_state::$unprocessed, $step->get_state());
39
        $this->assertEquals(question_state::$unprocessed, $step->get_state());
40
    }
40
    }
Línea 41... Línea 41...
41
 
41
 
42
    public function test_get_set_state() {
42
    public function test_get_set_state(): void {
43
        $step = new question_attempt_step();
43
        $step = new question_attempt_step();
44
        $step->set_state(question_state::$gradedright);
44
        $step->set_state(question_state::$gradedright);
45
        $this->assertEquals(question_state::$gradedright, $step->get_state());
45
        $this->assertEquals(question_state::$gradedright, $step->get_state());
Línea 46... Línea 46...
46
    }
46
    }
47
 
47
 
48
    public function test_initial_fraction_null() {
48
    public function test_initial_fraction_null(): void {
49
        $step = new question_attempt_step();
49
        $step = new question_attempt_step();
Línea 50... Línea 50...
50
        $this->assertNull($step->get_fraction());
50
        $this->assertNull($step->get_fraction());
51
    }
51
    }
52
 
52
 
53
    public function test_get_set_fraction() {
53
    public function test_get_set_fraction(): void {
54
        $step = new question_attempt_step();
54
        $step = new question_attempt_step();
Línea 55... Línea 55...
55
        $step->set_fraction(0.5);
55
        $step->set_fraction(0.5);
56
        $this->assertEquals(0.5, $step->get_fraction());
56
        $this->assertEquals(0.5, $step->get_fraction());
57
    }
57
    }
58
 
58
 
59
    public function test_has_var() {
59
    public function test_has_var(): void {
60
        $step = new question_attempt_step(array('x' => 1, '-y' => 'frog'));
60
        $step = new question_attempt_step(array('x' => 1, '-y' => 'frog'));
61
        $this->assertTrue($step->has_qt_var('x'));
61
        $this->assertTrue($step->has_qt_var('x'));
Línea 62... Línea 62...
62
        $this->assertTrue($step->has_behaviour_var('y'));
62
        $this->assertTrue($step->has_behaviour_var('y'));
63
        $this->assertFalse($step->has_qt_var('y'));
63
        $this->assertFalse($step->has_qt_var('y'));
64
        $this->assertFalse($step->has_behaviour_var('x'));
64
        $this->assertFalse($step->has_behaviour_var('x'));
65
    }
65
    }
66
 
66
 
67
    public function test_get_var() {
67
    public function test_get_var(): void {
Línea 68... Línea 68...
68
        $step = new question_attempt_step(array('x' => 1, '-y' => 'frog'));
68
        $step = new question_attempt_step(array('x' => 1, '-y' => 'frog'));
69
        $this->assertEquals('1', $step->get_qt_var('x'));
69
        $this->assertEquals('1', $step->get_qt_var('x'));
70
        $this->assertEquals('frog', $step->get_behaviour_var('y'));
70
        $this->assertEquals('frog', $step->get_behaviour_var('y'));
71
        $this->assertNull($step->get_qt_var('y'));
71
        $this->assertNull($step->get_qt_var('y'));
72
    }
72
    }
73
 
73
 
74
    public function test_set_var() {
74
    public function test_set_var(): void {
Línea 75... Línea 75...
75
        $step = new question_attempt_step();
75
        $step = new question_attempt_step();
76
        $step->set_qt_var('_x', 1);
76
        $step->set_qt_var('_x', 1);
77
        $step->set_behaviour_var('_x', 2);
77
        $step->set_behaviour_var('_x', 2);
78
        $this->assertEquals('1', $step->get_qt_var('_x'));
78
        $this->assertEquals('1', $step->get_qt_var('_x'));
79
        $this->assertEquals('2', $step->get_behaviour_var('_x'));
79
        $this->assertEquals('2', $step->get_behaviour_var('_x'));
Línea 80... Línea 80...
80
    }
80
    }
81
 
81
 
82
    public function test_cannot_set_qt_var_without_underscore() {
82
    public function test_cannot_set_qt_var_without_underscore(): void {
83
        $step = new question_attempt_step();
83
        $step = new question_attempt_step();
84
        $this->expectException('moodle_exception');
84
        $this->expectException('moodle_exception');
Línea 85... Línea 85...
85
        $step->set_qt_var('x', 1);
85
        $step->set_qt_var('x', 1);
86
    }
86
    }
87
 
87
 
88
    public function test_cannot_set_behaviour_var_without_underscore() {
88
    public function test_cannot_set_behaviour_var_without_underscore(): void {
89
        $step = new question_attempt_step();
89
        $step = new question_attempt_step();
90
        $this->expectException('moodle_exception');
90
        $this->expectException('moodle_exception');
Línea 91... Línea 91...
91
        $step->set_behaviour_var('x', 1);
91
        $step->set_behaviour_var('x', 1);
92
    }
92
    }
93
 
93
 
94
    public function test_get_data() {
94
    public function test_get_data(): void {
95
        $step = new question_attempt_step(array('x' => 1, '-y' => 'frog', ':flagged' => 1));
95
        $step = new question_attempt_step(array('x' => 1, '-y' => 'frog', ':flagged' => 1));
96
        $this->assertEquals(array('x' => '1'), $step->get_qt_data());
96
        $this->assertEquals(array('x' => '1'), $step->get_qt_data());
Línea 97... Línea 97...
97
        $this->assertEquals(array('y' => 'frog'), $step->get_behaviour_data());
97
        $this->assertEquals(array('y' => 'frog'), $step->get_behaviour_data());
98
        $this->assertEquals(array('x' => 1, '-y' => 'frog', ':flagged' => 1), $step->get_all_data());
98
        $this->assertEquals(array('x' => 1, '-y' => 'frog', ':flagged' => 1), $step->get_all_data());
99
    }
99
    }
100
 
100
 
101
    public function test_get_submitted_data() {
101
    public function test_get_submitted_data(): void {
102
        $step = new question_attempt_step(array('x' => 1, '-y' => 'frog'));
102
        $step = new question_attempt_step(array('x' => 1, '-y' => 'frog'));
103
        $step->set_qt_var('_x', 1);
103
        $step->set_qt_var('_x', 1);
Línea 104... Línea 104...
104
        $step->set_behaviour_var('_x', 2);
104
        $step->set_behaviour_var('_x', 2);
Línea 105... Línea 105...
105
        $this->assertEquals(array('x' => 1, '-y' => 'frog'), $step->get_submitted_data());
105
        $this->assertEquals(array('x' => 1, '-y' => 'frog'), $step->get_submitted_data());
106
    }
106
    }
107
 
107
 
108
    public function test_constructor_default_params() {
108
    public function test_constructor_default_params(): void {
109
        global $USER;
109
        global $USER;
110
        $step = new question_attempt_step();
110
        $step = new question_attempt_step();
Línea 126... Línea 126...
126
    }
126
    }
Línea 127... Línea 127...
127
 
127
 
128
    /**
128
    /**
129
     * Test get_user function.
129
     * Test get_user function.
130
     */
130
     */
131
    public function test_get_user() {
131
    public function test_get_user(): void {
132
        $this->resetAfterTest(true);
132
        $this->resetAfterTest(true);
Línea 133... Línea 133...
133
        $student = $this->getDataGenerator()->create_user();
133
        $student = $this->getDataGenerator()->create_user();
134
 
134
 
Línea 139... Línea 139...
139
    }
139
    }
Línea 140... Línea 140...
140
 
140
 
141
    /**
141
    /**
142
     * Test get_user_fullname function.
142
     * Test get_user_fullname function.
143
     */
143
     */
144
    public function test_get_user_fullname() {
144
    public function test_get_user_fullname(): void {
145
        $this->resetAfterTest(true);
145
        $this->resetAfterTest(true);
Línea 146... Línea 146...
146
        $student = $this->getDataGenerator()->create_user();
146
        $student = $this->getDataGenerator()->create_user();
147
 
147
 
Línea 152... Línea 152...
152
    }
152
    }
Línea 153... Línea 153...
153
 
153
 
154
    /**
154
    /**
155
     * Test add_full_user_object function.
155
     * Test add_full_user_object function.
156
     */
156
     */
157
    public function test_add_full_user_object() {
157
    public function test_add_full_user_object(): void {
158
        $this->resetAfterTest(true);
158
        $this->resetAfterTest(true);
159
        $student1 = $this->getDataGenerator()->create_user();
159
        $student1 = $this->getDataGenerator()->create_user();
Línea 160... Línea 160...
160
        $student2 = $this->getDataGenerator()->create_user();
160
        $student2 = $this->getDataGenerator()->create_user();