Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
namespace qtype_calculated;
18
 
19
use question_hint;
20
use question_state;
21
 
22
defined('MOODLE_INTERNAL') || die();
23
 
24
global $CFG;
25
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
26
 
27
 
28
/**
29
 * Unit tests for the calculated question type.
30
 *
31
 * @package    qtype_calculated
32
 * @copyright  2011 The Open University
33
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
1441 ariadna 35
final class walkthrough_test extends \qbehaviour_walkthrough_test_base {
11 efrain 36
    public function test_interactive(): void {
1 efrain 37
 
38
        // Create a gapselect question.
39
        $q = \test_question_maker::make_question('calculated');
40
        $q->hints = array(
41
            new question_hint(1, 'This is the first hint.', FORMAT_HTML),
42
            new question_hint(2, 'This is the second hint.', FORMAT_HTML),
43
        );
44
        $this->start_attempt_at_question($q, 'interactive', 3, 1);
45
        $values = $q->vs->get_values();
46
        $this->assertEquals($values, $q->datasetloader->load_values(1));
47
 
48
        // Check the initial state.
49
        $this->check_current_state(question_state::$todo);
50
        $this->check_current_mark(null);
51
        $this->check_current_output(
52
                $this->get_contains_marked_out_of_summary(),
53
                $this->get_contains_submit_button_expectation(true),
54
                $this->get_does_not_contain_feedback_expectation(),
55
                $this->get_does_not_contain_validation_error_expectation(),
56
                $this->get_does_not_contain_try_again_button_expectation(),
57
                $this->get_no_hint_visible_expectation());
58
 
59
        // Submit blank.
60
        $this->process_submission(array('-submit' => 1, 'answer' => ''));
61
 
62
        // Verify.
63
        $this->check_current_state(question_state::$invalid);
64
        $this->check_current_mark(null);
65
        $this->check_current_output(
66
                $this->get_contains_marked_out_of_summary(),
67
                $this->get_contains_submit_button_expectation(true),
68
                $this->get_does_not_contain_feedback_expectation(),
69
                $this->get_contains_validation_error_expectation(),
70
                $this->get_does_not_contain_try_again_button_expectation(),
71
                $this->get_no_hint_visible_expectation());
72
 
73
        // Sumit something that does not look like a number.
74
        $this->process_submission(array('-submit' => 1, 'answer' => 'newt'));
75
 
76
        // Verify.
77
        $this->check_current_state(question_state::$invalid);
78
        $this->check_current_mark(null);
79
        $this->check_current_output(
80
                $this->get_contains_marked_out_of_summary(),
81
                $this->get_contains_submit_button_expectation(true),
82
                $this->get_does_not_contain_feedback_expectation(),
83
                $this->get_contains_validation_error_expectation(),
84
                new \question_pattern_expectation('/' .
85
                        preg_quote(get_string('invalidnumber', 'qtype_numerical'), '/') . '/'),
86
                $this->get_does_not_contain_try_again_button_expectation(),
87
                $this->get_no_hint_visible_expectation());
88
 
89
        // Now get it right.
90
        $this->process_submission(array('-submit' => 1, 'answer' => $values['a'] + $values['b']));
91
 
92
        // Verify.
93
        $this->check_current_state(question_state::$gradedright);
94
        $this->check_current_mark(3);
95
        $this->check_current_output(
96
                $this->get_contains_mark_summary(3),
97
                $this->get_does_not_contain_submit_button_expectation(),
98
                $this->get_contains_correct_expectation(),
99
                $this->get_does_not_contain_validation_error_expectation(),
100
                $this->get_no_hint_visible_expectation());
101
    }
102
}