示例#1
0
 public function test_interactive_behaviour()
 {
     // Create a gapselect question.
     $q = qtype_gapselect_test_helper::make_a_gapselect_question();
     $q->hints = array(new question_hint_with_parts(1, 'This is the first hint.', FORMAT_HTML, false, false), new question_hint_with_parts(2, 'This is the second hint.', FORMAT_HTML, true, true));
     $q->shufflechoices = false;
     $this->start_attempt_at_question($q, 'interactive', 3);
     // Check the initial state.
     $this->check_current_state(question_state::$todo);
     $this->check_current_mark(null);
     $this->check_current_output($this->get_contains_select_expectation('p1', array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), null, true), $this->get_contains_select_expectation('p2', array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), null, true), $this->get_contains_select_expectation('p3', array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), null, true), $this->get_contains_submit_button_expectation(true), $this->get_does_not_contain_feedback_expectation(), $this->get_tries_remaining_expectation(3), $this->get_no_hint_visible_expectation());
     // Save the wrong answer.
     $this->process_submission(array('p1' => '2', 'p2' => '2', 'p3' => '2'));
     // Verify.
     $this->check_current_state(question_state::$todo);
     $this->check_current_mark(null);
     $this->check_current_output($this->get_contains_select_expectation('p1', array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), 2, true), $this->get_contains_select_expectation('p2', array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), 2, true), $this->get_contains_select_expectation('p3', array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), 2, true), $this->get_contains_submit_button_expectation(true), $this->get_does_not_contain_correctness_expectation(), $this->get_does_not_contain_feedback_expectation(), $this->get_tries_remaining_expectation(3), $this->get_no_hint_visible_expectation());
     // Submit the wrong answer.
     $this->process_submission(array('p1' => '2', 'p2' => '2', 'p3' => '2', '-submit' => 1));
     // Verify.
     $this->check_current_state(question_state::$todo);
     $this->check_current_mark(null);
     $this->check_current_output($this->get_contains_select_expectation('p1', array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), 2, false), $this->get_contains_select_expectation('p2', array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), 2, false), $this->get_contains_select_expectation('p3', array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), 2, false), $this->get_contains_submit_button_expectation(false), $this->get_contains_try_again_button_expectation(true), $this->get_does_not_contain_correctness_expectation(), $this->get_contains_hint_expectation('This is the first hint'));
     // Do try again.
     $this->process_submission(array('-tryagain' => 1));
     // Verify.
     $this->check_current_state(question_state::$todo);
     $this->check_current_mark(null);
     $this->check_current_output($this->get_contains_select_expectation('p1', array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), 2, true), $this->get_contains_select_expectation('p2', array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), 2, true), $this->get_contains_select_expectation('p3', array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), 2, true), $this->get_contains_submit_button_expectation(true), $this->get_does_not_contain_correctness_expectation(), $this->get_does_not_contain_feedback_expectation(), $this->get_tries_remaining_expectation(2), $this->get_no_hint_visible_expectation());
     // Submit the right answer.
     $this->process_submission(array('p1' => '1', 'p2' => '1', 'p3' => '1', '-submit' => 1));
     // Verify.
     $this->check_current_state(question_state::$gradedright);
     $this->check_current_mark(2);
     $this->check_current_output($this->get_contains_select_expectation('p1', array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), 1, false), $this->get_contains_select_expectation('p2', array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), 1, false), $this->get_contains_select_expectation('p3', array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), 1, false), $this->get_contains_submit_button_expectation(false), $this->get_contains_correct_expectation(), $this->get_no_hint_visible_expectation());
     // Check regrading does not mess anything up.
     $this->quba->regrade_all_questions();
     // Verify.
     $this->check_current_state(question_state::$gradedright);
     $this->check_current_mark(2);
 }
示例#2
0
 public function test_classify_response()
 {
     $gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
     $gapselect->shufflechoices = false;
     $gapselect->start_attempt(new question_attempt_step(), 1);
     $this->assertEquals(array(1 => new question_classified_response(1, 'quick', 1 / 3), 2 => new question_classified_response(2, 'dog', 0), 3 => new question_classified_response(1, 'lazy', 1 / 3)), $gapselect->classify_response(array('p1' => '1', 'p2' => '2', 'p3' => '1')));
     $this->assertEquals(array(1 => question_classified_response::no_response(), 2 => new question_classified_response(1, 'fox', 1 / 3), 3 => new question_classified_response(2, 'assiduous', 0)), $gapselect->classify_response(array('p1' => '0', 'p2' => '1', 'p3' => '2')));
 }
 public function test_initialise_question_instance()
 {
     $qdata = $this->get_test_question_data();
     $expected = qtype_gapselect_test_helper::make_a_gapselect_question();
     $expected->stamp = $qdata->stamp;
     $expected->version = $qdata->version;
     $q = $this->qtype->make_question($qdata);
     $this->assertEquals($expected, $q);
 }