MDL-47494 ddimageortext: NOBUG changed unit tests to use PHPUnit
This commit is contained in:
@@ -1,856 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the drag-and-drop onto image question type.
|
||||
*
|
||||
* @package qtype_ddimageortext
|
||||
* @copyright 2010 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php');
|
||||
require_once($CFG->dirroot . '/question/type/ddimageortext/simpletest/helper.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for the drag-and-drop onto image question type.
|
||||
*
|
||||
* @copyright 2010 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class qtype_ddimageortext_walkthrough_test extends qbehaviour_walkthrough_test_base {
|
||||
|
||||
protected function get_contains_drag_image_home_expectation($dragitemno, $choice, $group) {
|
||||
$class = 'group' . $group;
|
||||
$class .= ' draghome dragitemhomes' . $dragitemno. ' choice'.$choice.' yui3-cssfonts';
|
||||
|
||||
$expectedattrs = array();
|
||||
$expectedattrs['class'] = $class;
|
||||
|
||||
return new ContainsTagWithAttributes('div', $expectedattrs);
|
||||
}
|
||||
|
||||
public function test_interactive_behaviour() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$dd->hints = array(
|
||||
new question_hint_with_parts(13, 'This is the first hint.', FORMAT_HTML, false, false),
|
||||
new question_hint_with_parts(14, 'This is the second hint.', FORMAT_HTML, true, true),
|
||||
);
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, 'interactive', 12);
|
||||
|
||||
// Check the initial state.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4'),
|
||||
$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' => '1', 'p3' => '2', 'p4' => '1'));
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', 1),
|
||||
$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());
|
||||
// Submit the wrong answer.
|
||||
$this->process_submission(
|
||||
array('p1' => '2', 'p2' => '1', 'p3' => '2', 'p4' => '1', '-submit' => 1));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', 1),
|
||||
$this->get_contains_try_again_button_expectation(true),
|
||||
new PatternExpectation('/' .
|
||||
preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
|
||||
$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_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', '2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', '1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', '2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', '1'),
|
||||
$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' => '2', 'p3' => '1', 'p4' => '2', '-submit' => 1));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$gradedright);
|
||||
$this->check_current_mark(8);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', '1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', '2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', '1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', '2'),
|
||||
$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(8);
|
||||
}
|
||||
|
||||
public function test_deferred_feedback() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, 'deferredfeedback', 12);
|
||||
|
||||
// Check the initial state.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4'),
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
|
||||
// Save a partial answer.
|
||||
$this->process_submission(array('p1' => '2', 'p2' => '1'));
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$invalid);
|
||||
$this->check_current_mark(null);
|
||||
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', ''),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
// Save the right answer.
|
||||
$this->process_submission(
|
||||
array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2'));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$complete);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', 2),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
|
||||
// Finish the attempt.
|
||||
$this->quba->finish_all_questions();
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$gradedright);
|
||||
$this->check_current_mark(12);
|
||||
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', 2),
|
||||
$this->get_contains_correct_expectation());
|
||||
|
||||
// Change the right answer a bit.
|
||||
$dd->rightchoices[2] = 1;
|
||||
|
||||
// Check regrading does not mess anything up.
|
||||
$this->quba->regrade_all_questions();
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$gradedpartial);
|
||||
$this->check_current_mark(9);
|
||||
}
|
||||
|
||||
public function test_deferred_feedback_unanswered() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, 'deferredfeedback', 12);
|
||||
|
||||
// Check the initial state.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4'),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
$this->check_step_count(1);
|
||||
|
||||
// Save a blank response.
|
||||
$this->process_submission(array('p1' => '', 'p2' => '', 'p3' => '', 'p4' => ''));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', ''),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
$this->check_step_count(1);
|
||||
|
||||
// Finish the attempt.
|
||||
$this->quba->finish_all_questions();
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$gaveup);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2));
|
||||
}
|
||||
|
||||
public function test_deferred_feedback_partial_answer() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, 'deferredfeedback', 3);
|
||||
|
||||
// Check the initial state.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4'),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
|
||||
// Save a partial response.
|
||||
$this->process_submission(array('p1' => '1', 'p2' => '2', 'p3' => '', 'p4' => ''));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$invalid);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', ''),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
|
||||
// Finish the attempt.
|
||||
$this->quba->finish_all_questions();
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$gradedpartial);
|
||||
$this->check_current_mark(1.5);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_partcorrect_expectation());
|
||||
}
|
||||
|
||||
public function test_interactive_grading() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$dd->hints = array(
|
||||
new question_hint_with_parts(1, 'This is the first hint.',
|
||||
FORMAT_MOODLE, true, true),
|
||||
new question_hint_with_parts(2, 'This is the second hint.',
|
||||
FORMAT_MOODLE, true, true),
|
||||
);
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, 'interactive', 12);
|
||||
|
||||
// Check the initial state.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->assertEqual('interactivecountback',
|
||||
$this->quba->get_question_attempt($this->slot)->get_behaviour_name());
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4'),
|
||||
$this->get_contains_submit_button_expectation(true),
|
||||
$this->get_does_not_contain_feedback_expectation(),
|
||||
$this->get_tries_remaining_expectation(3),
|
||||
$this->get_does_not_contain_num_parts_correct(),
|
||||
$this->get_no_hint_visible_expectation());
|
||||
|
||||
// Submit an response with the first two parts right.
|
||||
$this->process_submission(
|
||||
array('p1' => '1', 'p2' => '2', 'p3' => '2', 'p4' => '1', '-submit' => 1));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_submit_button_expectation(false),
|
||||
$this->get_contains_try_again_button_expectation(true),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
new PatternExpectation('/' .
|
||||
preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
|
||||
$this->get_contains_hint_expectation('This is the first hint'),
|
||||
$this->get_contains_num_parts_correct(2),
|
||||
$this->get_contains_standard_partiallycorrect_combined_feedback_expectation(),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', 1));
|
||||
|
||||
// Check that extract responses will return the reset data.
|
||||
$prefix = $this->quba->get_field_prefix($this->slot);
|
||||
$this->assertEqual(array('p1' => '1', 'p2' => '2'),
|
||||
$this->quba->extract_responses($this->slot,
|
||||
array($prefix . 'p1' => '1', $prefix . 'p2' => '2', '-tryagain' => 1)));
|
||||
|
||||
// Do try again.
|
||||
// keys p3 and p4 are extra hidden fields to clear data.
|
||||
$this->process_submission(
|
||||
array('p1' => '1', 'p2' => '2', 'p3' => '', 'p4' => '', '-tryagain' => 1));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', ''),
|
||||
$this->get_contains_submit_button_expectation(true),
|
||||
$this->get_does_not_contain_try_again_button_expectation(),
|
||||
$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 an response with the first and last parts right.
|
||||
$this->process_submission(
|
||||
array('p1' => '1', 'p2' => '1', 'p3' => '2', 'p4' => '2', '-submit' => 1));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_submit_button_expectation(false),
|
||||
$this->get_contains_try_again_button_expectation(true),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
new PatternExpectation('/' .
|
||||
preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
|
||||
$this->get_contains_hint_expectation('This is the second hint'),
|
||||
$this->get_contains_num_parts_correct(2),
|
||||
$this->get_contains_standard_partiallycorrect_combined_feedback_expectation(),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', 2));
|
||||
|
||||
// Do try again.
|
||||
$this->process_submission(
|
||||
array('p1' => '1', 'p2' => '', 'p3' => '', 'p4' => '2', '-tryagain' => 1));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', 2),
|
||||
$this->get_contains_submit_button_expectation(true),
|
||||
$this->get_does_not_contain_try_again_button_expectation(),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
$this->get_does_not_contain_feedback_expectation(),
|
||||
$this->get_tries_remaining_expectation(1),
|
||||
$this->get_no_hint_visible_expectation());
|
||||
|
||||
// Submit the right answer.
|
||||
$this->process_submission(
|
||||
array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2', '-submit' => 1));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$gradedright);
|
||||
$this->check_current_mark(7);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', 2),
|
||||
$this->get_contains_submit_button_expectation(false),
|
||||
$this->get_does_not_contain_try_again_button_expectation(),
|
||||
$this->get_contains_correct_expectation(),
|
||||
$this->get_no_hint_visible_expectation(),
|
||||
$this->get_does_not_contain_num_parts_correct(),
|
||||
$this->get_contains_standard_correct_combined_feedback_expectation());
|
||||
}
|
||||
|
||||
public function test_interactive_correct_no_submit() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$dd->hints = array(
|
||||
new question_hint_with_parts(23, 'This is the first hint.',
|
||||
FORMAT_MOODLE, false, false),
|
||||
new question_hint_with_parts(24, 'This is the second hint.',
|
||||
FORMAT_MOODLE, true, true),
|
||||
);
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, '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_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4'),
|
||||
$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 right answer.
|
||||
$this->process_submission(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2'));
|
||||
|
||||
// Finish the attempt without clicking check.
|
||||
$this->quba->finish_all_questions();
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$gradedright);
|
||||
$this->check_current_mark(3);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$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(3);
|
||||
}
|
||||
|
||||
public function test_interactive_partial_no_submit() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$dd->hints = array(
|
||||
new question_hint_with_parts(23, 'This is the first hint.',
|
||||
FORMAT_MOODLE, false, false),
|
||||
new question_hint_with_parts(24, 'This is the second hint.',
|
||||
FORMAT_MOODLE, true, true),
|
||||
);
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, 'interactive', 4);
|
||||
|
||||
// Check the initial state.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4'),
|
||||
$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 a partially right answer.
|
||||
$this->process_submission(array('p1' => '1', 'p2' => '1', 'p3' => '2', 'p4' => '1'));
|
||||
|
||||
// Finish the attempt without clicking check.
|
||||
$this->quba->finish_all_questions();
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$gradedpartial);
|
||||
$this->check_current_mark(1);
|
||||
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_submit_button_expectation(false),
|
||||
$this->get_contains_partcorrect_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::$gradedpartial);
|
||||
$this->check_current_mark(1);
|
||||
}
|
||||
|
||||
public function test_interactive_no_right_clears() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$dd->hints = array(
|
||||
new question_hint_with_parts(23, 'This is the first hint.', FORMAT_MOODLE, false, true),
|
||||
new question_hint_with_parts(24, 'This is the second hint.', FORMAT_MOODLE, true, true),
|
||||
);
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, '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_marked_out_of_summary(),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4'),
|
||||
$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 a completely wrong answer.
|
||||
$this->process_submission(
|
||||
array('p1' => '2', 'p2' => '1', 'p3' => '2', 'p4' => '1', '-submit' => 1));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_marked_out_of_summary(),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_submit_button_expectation(false),
|
||||
$this->get_contains_hint_expectation('This is the first hint'));
|
||||
|
||||
// Do try again.
|
||||
$this->process_submission(
|
||||
array('p1' => '', 'p2' => '', 'p3' => '', 'p4' => '', '-tryagain' => 1));
|
||||
|
||||
// Check that all the wrong answers have been cleared.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_marked_out_of_summary(),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', ''),
|
||||
$this->get_contains_submit_button_expectation(true),
|
||||
$this->get_does_not_contain_feedback_expectation(),
|
||||
$this->get_tries_remaining_expectation(2),
|
||||
$this->get_no_hint_visible_expectation());
|
||||
}
|
||||
|
||||
public function test_display_of_right_answer_when_shuffled() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$this->start_attempt_at_question($dd, 'deferredfeedback', 3);
|
||||
|
||||
// Check the initial state.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
|
||||
$this->check_current_output(
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4'),
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
|
||||
// Save a partial answer.
|
||||
$this->process_submission($dd->get_correct_response());
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$complete);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1',
|
||||
$dd->get_right_choice_for(1)),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2',
|
||||
$dd->get_right_choice_for(2)),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3',
|
||||
$dd->get_right_choice_for(3)),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4',
|
||||
$dd->get_right_choice_for(4)),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
|
||||
// Finish the attempt.
|
||||
$this->quba->finish_all_questions();
|
||||
|
||||
// Verify.
|
||||
$this->displayoptions->rightanswer = question_display_options::VISIBLE;
|
||||
$this->assertEqual('Drop zone 1 -> {1. quick} '.
|
||||
'Drop zone 2 -> {2. fox} '.
|
||||
'Drop zone 3 -> {1. lazy} '.
|
||||
'Drop zone 4 -> {2. dog}',
|
||||
$dd->get_right_answer_summary());
|
||||
$this->check_current_state(question_state::$gradedright);
|
||||
$this->check_current_mark(3);
|
||||
}
|
||||
}
|
||||
+87
-85
@@ -25,8 +25,9 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php');
|
||||
require_once($CFG->dirroot . '/question/type/ddimageortext/simpletest/helper.php');
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
|
||||
require_once($CFG->dirroot . '/question/type/ddimageortext/tests/helper.php');
|
||||
|
||||
|
||||
/**
|
||||
@@ -34,28 +35,29 @@ require_once($CFG->dirroot . '/question/type/ddimageortext/simpletest/helper.php
|
||||
*
|
||||
* @copyright 2009 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @group qtype_ddimageortext
|
||||
*/
|
||||
class qtype_ddimageortext_question_test extends UnitTestCase {
|
||||
class qtype_ddimageortext_question_test extends basic_testcase {
|
||||
|
||||
public function test_get_question_summary() {
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$this->assertEqual('The quick brown fox jumped over the lazy dog.; '.
|
||||
'[[Drop zone 1]] -> {1. quick / 2. fox}; '.
|
||||
'[[Drop zone 2]] -> {1. quick / 2. fox}; '.
|
||||
'[[Drop zone 3]] -> {1. lazy / 2. dog}; '.
|
||||
'[[Drop zone 4]] -> {1. lazy / 2. dog}',
|
||||
$dd->get_question_summary());
|
||||
$this->assertEquals('The quick brown fox jumped over the lazy dog.; '.
|
||||
'[[Drop zone 1]] -> {1. quick / 2. fox}; '.
|
||||
'[[Drop zone 2]] -> {1. quick / 2. fox}; '.
|
||||
'[[Drop zone 3]] -> {1. lazy / 2. dog}; '.
|
||||
'[[Drop zone 4]] -> {1. lazy / 2. dog}',
|
||||
$dd->get_question_summary());
|
||||
}
|
||||
|
||||
public function test_get_question_summary_maths() {
|
||||
$dd = test_question_maker::make_question('ddimageortext', 'maths');
|
||||
$this->assertEqual('Fill in the operators to make this equation work: '.
|
||||
'7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3; '.
|
||||
'[[Drop zone 1]] -> {1. + / 2. -}; '.
|
||||
'[[Drop zone 2]] -> {1. + / 2. -}; '.
|
||||
'[[Drop zone 3]] -> {1. + / 2. -}; '.
|
||||
'[[Drop zone 4]] -> {1. + / 2. -}',
|
||||
$dd->get_question_summary());
|
||||
$this->assertEquals('Fill in the operators to make this equation work: '.
|
||||
'7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3; '.
|
||||
'[[Drop zone 1]] -> {1. + / 2. -}; '.
|
||||
'[[Drop zone 2]] -> {1. + / 2. -}; '.
|
||||
'[[Drop zone 3]] -> {1. + / 2. -}; '.
|
||||
'[[Drop zone 4]] -> {1. + / 2. -}',
|
||||
$dd->get_question_summary());
|
||||
}
|
||||
|
||||
public function test_summarise_response() {
|
||||
@@ -63,11 +65,11 @@ class qtype_ddimageortext_question_test extends UnitTestCase {
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$this->assertEqual('Drop zone 1 -> {1. quick} '.
|
||||
'Drop zone 2 -> {1. quick} '.
|
||||
'Drop zone 3 -> {1. lazy} '.
|
||||
'Drop zone 4 -> {1. lazy}',
|
||||
$dd->summarise_response(array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
|
||||
$this->assertEquals('Drop zone 1 -> {1. quick} '.
|
||||
'Drop zone 2 -> {1. quick} '.
|
||||
'Drop zone 3 -> {1. lazy} '.
|
||||
'Drop zone 4 -> {1. lazy}',
|
||||
$dd->summarise_response(array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
|
||||
}
|
||||
|
||||
public function test_summarise_response_maths() {
|
||||
@@ -75,21 +77,21 @@ class qtype_ddimageortext_question_test extends UnitTestCase {
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$this->assertEqual('Drop zone 1 -> {1. +} '.
|
||||
'Drop zone 2 -> {2. -} '.
|
||||
'Drop zone 3 -> {1. +} '.
|
||||
'Drop zone 4 -> {2. -}',
|
||||
$dd->summarise_response(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
|
||||
$this->assertEquals('Drop zone 1 -> {1. +} '.
|
||||
'Drop zone 2 -> {2. -} '.
|
||||
'Drop zone 3 -> {1. +} '.
|
||||
'Drop zone 4 -> {2. -}',
|
||||
$dd->summarise_response(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
|
||||
}
|
||||
|
||||
public function test_get_random_guess_score() {
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$this->assertEqual(0.5, $dd->get_random_guess_score());
|
||||
$this->assertEquals(0.5, $dd->get_random_guess_score());
|
||||
}
|
||||
|
||||
public function test_get_random_guess_score_maths() {
|
||||
$dd = test_question_maker::make_question('ddimageortext', 'maths');
|
||||
$this->assertEqual(0.5, $dd->get_random_guess_score());
|
||||
$this->assertEquals(0.5, $dd->get_random_guess_score());
|
||||
}
|
||||
|
||||
public function test_get_right_choice_for() {
|
||||
@@ -97,8 +99,8 @@ class qtype_ddimageortext_question_test extends UnitTestCase {
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$this->assertEqual(1, $dd->get_right_choice_for(1));
|
||||
$this->assertEqual(2, $dd->get_right_choice_for(2));
|
||||
$this->assertEquals(1, $dd->get_right_choice_for(1));
|
||||
$this->assertEquals(2, $dd->get_right_choice_for(2));
|
||||
}
|
||||
|
||||
public function test_get_right_choice_for_maths() {
|
||||
@@ -106,10 +108,10 @@ class qtype_ddimageortext_question_test extends UnitTestCase {
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$this->assertEqual(1, $dd->get_right_choice_for(1));
|
||||
$this->assertEqual(2, $dd->get_right_choice_for(2));
|
||||
$this->assertEqual(1, $dd->get_right_choice_for(3));
|
||||
$this->assertEqual(2, $dd->get_right_choice_for(4));
|
||||
$this->assertEquals(1, $dd->get_right_choice_for(1));
|
||||
$this->assertEquals(2, $dd->get_right_choice_for(2));
|
||||
$this->assertEquals(1, $dd->get_right_choice_for(3));
|
||||
$this->assertEquals(2, $dd->get_right_choice_for(4));
|
||||
}
|
||||
|
||||
public function test_clear_wrong_from_response() {
|
||||
@@ -118,8 +120,8 @@ class qtype_ddimageortext_question_test extends UnitTestCase {
|
||||
$dd->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$initialresponse = array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1');
|
||||
$this->assertEqual(array('p1' => '1', 'p2' => '', 'p3' => '1', 'p4' => ''),
|
||||
$dd->clear_wrong_from_response($initialresponse));
|
||||
$this->assertEquals(array('p1' => '1', 'p2' => '', 'p3' => '1', 'p4' => ''),
|
||||
$dd->clear_wrong_from_response($initialresponse));
|
||||
}
|
||||
|
||||
public function test_get_num_parts_right() {
|
||||
@@ -127,9 +129,9 @@ class qtype_ddimageortext_question_test extends UnitTestCase {
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$this->assertEqual(array(2, 4),
|
||||
$this->assertEquals(array(2, 4),
|
||||
$dd->get_num_parts_right(array('p1' => '1', 'p2' => '1', 'p3' => '2', 'p4' => '2')));
|
||||
$this->assertEqual(array(4, 4),
|
||||
$this->assertEquals(array(4, 4),
|
||||
$dd->get_num_parts_right(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
|
||||
}
|
||||
|
||||
@@ -138,16 +140,16 @@ class qtype_ddimageortext_question_test extends UnitTestCase {
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$this->assertEqual(array(2, 4),
|
||||
$dd->get_num_parts_right(array(
|
||||
'p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
|
||||
$this->assertEquals(array(2, 4),
|
||||
$dd->get_num_parts_right(array(
|
||||
'p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
|
||||
}
|
||||
|
||||
public function test_get_expected_data() {
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$dd->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$this->assertEqual(
|
||||
$this->assertEquals(
|
||||
array('p1' => PARAM_INT, 'p2' => PARAM_INT, 'p3' => PARAM_INT, 'p4' => PARAM_INT),
|
||||
$dd->get_expected_data()
|
||||
);
|
||||
@@ -158,8 +160,8 @@ class qtype_ddimageortext_question_test extends UnitTestCase {
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$this->assertEqual(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2'),
|
||||
$dd->get_correct_response());
|
||||
$this->assertEquals(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2'),
|
||||
$dd->get_correct_response());
|
||||
}
|
||||
|
||||
public function test_get_correct_response_maths() {
|
||||
@@ -167,8 +169,8 @@ class qtype_ddimageortext_question_test extends UnitTestCase {
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$this->assertEqual(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2'),
|
||||
$dd->get_correct_response());
|
||||
$this->assertEquals(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2'),
|
||||
$dd->get_correct_response());
|
||||
}
|
||||
|
||||
public function test_is_same_response() {
|
||||
@@ -176,24 +178,24 @@ class qtype_ddimageortext_question_test extends UnitTestCase {
|
||||
$dd->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$this->assertTrue($dd->is_same_response(
|
||||
array(),
|
||||
array('p1' => '', 'p2' => '', 'p3' => '', 'p4' => '')));
|
||||
array(),
|
||||
array('p1' => '', 'p2' => '', 'p3' => '', 'p4' => '')));
|
||||
|
||||
$this->assertFalse($dd->is_same_response(
|
||||
array(),
|
||||
array('p1' => '1', 'p2' => '', 'p3' => '', 'p4' => '')));
|
||||
array(),
|
||||
array('p1' => '1', 'p2' => '', 'p3' => '', 'p4' => '')));
|
||||
|
||||
$this->assertFalse($dd->is_same_response(
|
||||
array('p1' => '', 'p2' => '', 'p3' => '', 'p4' => ''),
|
||||
array('p1' => '1', 'p2' => '', 'p3' => '', 'p4' => '')));
|
||||
array('p1' => '', 'p2' => '', 'p3' => '', 'p4' => ''),
|
||||
array('p1' => '1', 'p2' => '', 'p3' => '', 'p4' => '')));
|
||||
|
||||
$this->assertTrue($dd->is_same_response(
|
||||
array('p1' => '1', 'p2' => '2', 'p3' => '3', 'p4' => '4'),
|
||||
array('p1' => '1', 'p2' => '2', 'p3' => '3', 'p4' => '4')));
|
||||
array('p1' => '1', 'p2' => '2', 'p3' => '3', 'p4' => '4'),
|
||||
array('p1' => '1', 'p2' => '2', 'p3' => '3', 'p4' => '4')));
|
||||
|
||||
$this->assertFalse($dd->is_same_response(
|
||||
array('p1' => '1', 'p2' => '2', 'p3' => '3', 'p4' => '4'),
|
||||
array('p1' => '1', 'p2' => '2', 'p3' => '2', 'p4' => '4')));
|
||||
array('p1' => '1', 'p2' => '2', 'p3' => '3', 'p4' => '4'),
|
||||
array('p1' => '1', 'p2' => '2', 'p3' => '2', 'p4' => '4')));
|
||||
}
|
||||
public function test_is_complete_response() {
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
@@ -201,10 +203,10 @@ class qtype_ddimageortext_question_test extends UnitTestCase {
|
||||
|
||||
$this->assertFalse($dd->is_complete_response(array()));
|
||||
$this->assertFalse($dd->is_complete_response(
|
||||
array('p1' => '1', 'p2' => '1', 'p3' => '', 'p4' => '')));
|
||||
array('p1' => '1', 'p2' => '1', 'p3' => '', 'p4' => '')));
|
||||
$this->assertFalse($dd->is_complete_response(array('p1' => '1')));
|
||||
$this->assertTrue($dd->is_complete_response(
|
||||
array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
|
||||
array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
|
||||
}
|
||||
|
||||
public function test_is_gradable_response() {
|
||||
@@ -213,12 +215,12 @@ class qtype_ddimageortext_question_test extends UnitTestCase {
|
||||
|
||||
$this->assertFalse($dd->is_gradable_response(array()));
|
||||
$this->assertFalse($dd->is_gradable_response(
|
||||
array('p1' => '', 'p2' => '', 'p3' => '', 'p3' => '')));
|
||||
array('p1' => '', 'p2' => '', 'p3' => '', 'p3' => '')));
|
||||
$this->assertTrue($dd->is_gradable_response(
|
||||
array('p1' => '1', 'p2' => '1', 'p3' => '')));
|
||||
array('p1' => '1', 'p2' => '1', 'p3' => '')));
|
||||
$this->assertTrue($dd->is_gradable_response(array('p1' => '1')));
|
||||
$this->assertTrue($dd->is_gradable_response(
|
||||
array('p1' => '1', 'p2' => '1', 'p3' => '1')));
|
||||
array('p1' => '1', 'p2' => '1', 'p3' => '1')));
|
||||
}
|
||||
|
||||
public function test_grading() {
|
||||
@@ -226,12 +228,12 @@ class qtype_ddimageortext_question_test extends UnitTestCase {
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$this->assertEqual(array(1, question_state::$gradedright),
|
||||
$dd->grade_response(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
|
||||
$this->assertEqual(array(0.25, question_state::$gradedpartial),
|
||||
$dd->grade_response(array('p1' => '1')));
|
||||
$this->assertEqual(array(0, question_state::$gradedwrong),
|
||||
$dd->grade_response(array('p1' => '2', 'p2' => '1', 'p3' => '2', 'p4' => '1')));
|
||||
$this->assertEquals(array(1, question_state::$gradedright),
|
||||
$dd->grade_response(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
|
||||
$this->assertEquals(array(0.25, question_state::$gradedpartial),
|
||||
$dd->grade_response(array('p1' => '1')));
|
||||
$this->assertEquals(array(0, question_state::$gradedwrong),
|
||||
$dd->grade_response(array('p1' => '2', 'p2' => '1', 'p3' => '2', 'p4' => '1')));
|
||||
}
|
||||
|
||||
public function test_grading_maths() {
|
||||
@@ -239,12 +241,12 @@ class qtype_ddimageortext_question_test extends UnitTestCase {
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$this->assertEqual(array(1, question_state::$gradedright),
|
||||
$dd->grade_response(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
|
||||
$this->assertEqual(array(0.5, question_state::$gradedpartial),
|
||||
$dd->grade_response(array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
|
||||
$this->assertEqual(array(0, question_state::$gradedwrong),
|
||||
$dd->grade_response(array('p1' => '', 'p2' => '1', 'p3' => '2', 'p4' => '1')));
|
||||
$this->assertEquals(array(1, question_state::$gradedright),
|
||||
$dd->grade_response(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
|
||||
$this->assertEquals(array(0.5, question_state::$gradedpartial),
|
||||
$dd->grade_response(array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
|
||||
$this->assertEquals(array(0, question_state::$gradedwrong),
|
||||
$dd->grade_response(array('p1' => '', 'p2' => '1', 'p3' => '2', 'p4' => '1')));
|
||||
}
|
||||
|
||||
public function test_classify_response() {
|
||||
@@ -252,17 +254,17 @@ class qtype_ddimageortext_question_test extends UnitTestCase {
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$this->assertEqual(array(
|
||||
1 => new question_classified_response(1, '1. quick', 1),
|
||||
2 => new question_classified_response(2, '2. fox', 1),
|
||||
3 => new question_classified_response(1, '1. lazy', 1),
|
||||
4 => new question_classified_response(2, '2. dog', 1)
|
||||
), $dd->classify_response(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
|
||||
$this->assertEqual(array(
|
||||
1 => question_classified_response::no_response(),
|
||||
2 => new question_classified_response(1, '1. quick', 0),
|
||||
3 => new question_classified_response(2, '2. dog', 0),
|
||||
4 => new question_classified_response(2, '2. dog', 1)
|
||||
), $dd->classify_response(array('p1' => '', 'p2' => '1', 'p3' => '2', 'p4' => '2')));
|
||||
$this->assertEquals(array(
|
||||
1 => new question_classified_response(1, '1. quick', 1),
|
||||
2 => new question_classified_response(2, '2. fox', 1),
|
||||
3 => new question_classified_response(1, '1. lazy', 1),
|
||||
4 => new question_classified_response(2, '2. dog', 1)
|
||||
), $dd->classify_response(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
|
||||
$this->assertEquals(array(
|
||||
1 => question_classified_response::no_response(),
|
||||
2 => new question_classified_response(1, '1. quick', 0),
|
||||
3 => new question_classified_response(2, '2. dog', 0),
|
||||
4 => new question_classified_response(2, '2. dog', 1)
|
||||
), $dd->classify_response(array('p1' => '', 'p2' => '1', 'p3' => '2', 'p4' => '2')));
|
||||
}
|
||||
}
|
||||
+8
-6
@@ -25,8 +25,9 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php');
|
||||
require_once($CFG->dirroot . '/question/type/ddimageortext/simpletest/helper.php');
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
|
||||
require_once($CFG->dirroot . '/question/type/ddimageortext/tests/helper.php');
|
||||
|
||||
|
||||
/**
|
||||
@@ -34,21 +35,22 @@ require_once($CFG->dirroot . '/question/type/ddimageortext/simpletest/helper.php
|
||||
*
|
||||
* @copyright 2010 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @group qtype_ddimageortext
|
||||
*/
|
||||
class qtype_ddimageortext_test extends UnitTestCase {
|
||||
class qtype_ddimageortext_test extends basic_testcase {
|
||||
/** @var qtype_ddimageortext instance of the question type class to test. */
|
||||
protected $qtype;
|
||||
|
||||
public function setUp() {
|
||||
protected function setUp() {
|
||||
$this->qtype = question_bank::get_qtype('ddimageortext');;
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
protected function tearDown() {
|
||||
$this->qtype = null;
|
||||
}
|
||||
|
||||
public function test_name() {
|
||||
$this->assertEqual($this->qtype->name(), 'ddimageortext');
|
||||
$this->assertEquals($this->qtype->name(), 'ddimageortext');
|
||||
}
|
||||
|
||||
public function test_can_analyse_responses() {
|
||||
@@ -0,0 +1,858 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the drag-and-drop onto image question type.
|
||||
*
|
||||
* @package qtype_ddimageortext
|
||||
* @copyright 2010 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
|
||||
require_once($CFG->dirroot . '/question/type/ddimageortext/tests/helper.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for the drag-and-drop onto image question type.
|
||||
*
|
||||
* @copyright 2010 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @group qtype_ddimageortext
|
||||
*/
|
||||
class qtype_ddimageortext_walkthrough_test extends qbehaviour_walkthrough_test_base {
|
||||
|
||||
protected function get_contains_drag_image_home_expectation($dragitemno, $choice, $group) {
|
||||
$class = 'group' . $group;
|
||||
$class .= ' draghome dragitemhomes' . $dragitemno. ' choice'.$choice.' yui3-cssfonts';
|
||||
|
||||
$expectedattrs = array();
|
||||
$expectedattrs['class'] = $class;
|
||||
|
||||
return new question_contains_tag_with_attributes('div', $expectedattrs);
|
||||
}
|
||||
|
||||
public function test_interactive_behaviour() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$dd->hints = array(
|
||||
new question_hint_with_parts(13, 'This is the first hint.', FORMAT_HTML, false, false),
|
||||
new question_hint_with_parts(14, 'This is the second hint.', FORMAT_HTML, true, true),
|
||||
);
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, 'interactive', 12);
|
||||
|
||||
// Check the initial state.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4'),
|
||||
$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' => '1', 'p3' => '2', 'p4' => '1'));
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', 1),
|
||||
$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());
|
||||
// Submit the wrong answer.
|
||||
$this->process_submission(
|
||||
array('p1' => '2', 'p2' => '1', 'p3' => '2', 'p4' => '1', '-submit' => 1));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', 1),
|
||||
$this->get_contains_try_again_button_expectation(true),
|
||||
new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
|
||||
$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_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', '2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', '1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', '2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', '1'),
|
||||
$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' => '2', 'p3' => '1', 'p4' => '2', '-submit' => 1));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$gradedright);
|
||||
$this->check_current_mark(8);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', '1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', '2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', '1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', '2'),
|
||||
$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(8);
|
||||
}
|
||||
|
||||
public function test_deferred_feedback() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, 'deferredfeedback', 12);
|
||||
|
||||
// Check the initial state.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4'),
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
|
||||
// Save a partial answer.
|
||||
$this->process_submission(array('p1' => '2', 'p2' => '1'));
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$invalid);
|
||||
$this->check_current_mark(null);
|
||||
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', ''),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
// Save the right answer.
|
||||
$this->process_submission(
|
||||
array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2'));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$complete);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', 2),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
|
||||
// Finish the attempt.
|
||||
$this->quba->finish_all_questions();
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$gradedright);
|
||||
$this->check_current_mark(12);
|
||||
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', 2),
|
||||
$this->get_contains_correct_expectation());
|
||||
|
||||
// Change the right answer a bit.
|
||||
$dd->rightchoices[2] = 1;
|
||||
|
||||
// Check regrading does not mess anything up.
|
||||
$this->quba->regrade_all_questions();
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$gradedpartial);
|
||||
$this->check_current_mark(9);
|
||||
}
|
||||
|
||||
public function test_deferred_feedback_unanswered() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, 'deferredfeedback', 12);
|
||||
|
||||
// Check the initial state.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4'),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
$this->check_step_count(1);
|
||||
|
||||
// Save a blank response.
|
||||
$this->process_submission(array('p1' => '', 'p2' => '', 'p3' => '', 'p4' => ''));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', ''),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
$this->check_step_count(1);
|
||||
|
||||
// Finish the attempt.
|
||||
$this->quba->finish_all_questions();
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$gaveup);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2));
|
||||
}
|
||||
|
||||
public function test_deferred_feedback_partial_answer() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, 'deferredfeedback', 3);
|
||||
|
||||
// Check the initial state.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4'),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
|
||||
// Save a partial response.
|
||||
$this->process_submission(array('p1' => '1', 'p2' => '2', 'p3' => '', 'p4' => ''));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$invalid);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', ''),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
|
||||
// Finish the attempt.
|
||||
$this->quba->finish_all_questions();
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$gradedpartial);
|
||||
$this->check_current_mark(1.5);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_partcorrect_expectation());
|
||||
}
|
||||
|
||||
public function test_interactive_grading() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$dd->hints = array(
|
||||
new question_hint_with_parts(1, 'This is the first hint.',
|
||||
FORMAT_MOODLE, true, true),
|
||||
new question_hint_with_parts(2, 'This is the second hint.',
|
||||
FORMAT_MOODLE, true, true),
|
||||
);
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, 'interactive', 12);
|
||||
|
||||
// Check the initial state.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->assertEquals('interactivecountback',
|
||||
$this->quba->get_question_attempt($this->slot)->get_behaviour_name());
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4'),
|
||||
$this->get_contains_submit_button_expectation(true),
|
||||
$this->get_does_not_contain_feedback_expectation(),
|
||||
$this->get_tries_remaining_expectation(3),
|
||||
$this->get_does_not_contain_num_parts_correct(),
|
||||
$this->get_no_hint_visible_expectation());
|
||||
|
||||
// Submit an response with the first two parts right.
|
||||
$this->process_submission(
|
||||
array('p1' => '1', 'p2' => '2', 'p3' => '2', 'p4' => '1', '-submit' => 1));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_submit_button_expectation(false),
|
||||
$this->get_contains_try_again_button_expectation(true),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
|
||||
$this->get_contains_hint_expectation('This is the first hint'),
|
||||
$this->get_contains_num_parts_correct(2),
|
||||
$this->get_contains_standard_partiallycorrect_combined_feedback_expectation(),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', 1));
|
||||
|
||||
// Check that extract responses will return the reset data.
|
||||
$prefix = $this->quba->get_field_prefix($this->slot);
|
||||
$this->assertEquals(array('p1' => '1', 'p2' => '2'),
|
||||
$this->quba->extract_responses($this->slot,
|
||||
array($prefix . 'p1' => '1', $prefix . 'p2' => '2', '-tryagain' => 1)));
|
||||
|
||||
// Do try again.
|
||||
// keys p3 and p4 are extra hidden fields to clear data.
|
||||
$this->process_submission(
|
||||
array('p1' => '1', 'p2' => '2', 'p3' => '', 'p4' => '', '-tryagain' => 1));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', ''),
|
||||
$this->get_contains_submit_button_expectation(true),
|
||||
$this->get_does_not_contain_try_again_button_expectation(),
|
||||
$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 an response with the first and last parts right.
|
||||
$this->process_submission(
|
||||
array('p1' => '1', 'p2' => '1', 'p3' => '2', 'p4' => '2', '-submit' => 1));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_submit_button_expectation(false),
|
||||
$this->get_contains_try_again_button_expectation(true),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
|
||||
$this->get_contains_hint_expectation('This is the second hint'),
|
||||
$this->get_contains_num_parts_correct(2),
|
||||
$this->get_contains_standard_partiallycorrect_combined_feedback_expectation(),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', 2));
|
||||
|
||||
// Do try again.
|
||||
$this->process_submission(
|
||||
array('p1' => '1', 'p2' => '', 'p3' => '', 'p4' => '2', '-tryagain' => 1));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', 2),
|
||||
$this->get_contains_submit_button_expectation(true),
|
||||
$this->get_does_not_contain_try_again_button_expectation(),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
$this->get_does_not_contain_feedback_expectation(),
|
||||
$this->get_tries_remaining_expectation(1),
|
||||
$this->get_no_hint_visible_expectation());
|
||||
|
||||
// Submit the right answer.
|
||||
$this->process_submission(
|
||||
array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2', '-submit' => 1));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$gradedright);
|
||||
$this->check_current_mark(7);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', 1),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', 2),
|
||||
$this->get_contains_submit_button_expectation(false),
|
||||
$this->get_does_not_contain_try_again_button_expectation(),
|
||||
$this->get_contains_correct_expectation(),
|
||||
$this->get_no_hint_visible_expectation(),
|
||||
$this->get_does_not_contain_num_parts_correct(),
|
||||
$this->get_contains_standard_correct_combined_feedback_expectation());
|
||||
}
|
||||
|
||||
public function test_interactive_correct_no_submit() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$dd->hints = array(
|
||||
new question_hint_with_parts(23, 'This is the first hint.',
|
||||
FORMAT_MOODLE, false, false),
|
||||
new question_hint_with_parts(24, 'This is the second hint.',
|
||||
FORMAT_MOODLE, true, true),
|
||||
);
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, '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_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4'),
|
||||
$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 right answer.
|
||||
$this->process_submission(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2'));
|
||||
|
||||
// Finish the attempt without clicking check.
|
||||
$this->quba->finish_all_questions();
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$gradedright);
|
||||
$this->check_current_mark(3);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$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(3);
|
||||
}
|
||||
|
||||
public function test_interactive_partial_no_submit() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$dd->hints = array(
|
||||
new question_hint_with_parts(23, 'This is the first hint.',
|
||||
FORMAT_MOODLE, false, false),
|
||||
new question_hint_with_parts(24, 'This is the second hint.',
|
||||
FORMAT_MOODLE, true, true),
|
||||
);
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, 'interactive', 4);
|
||||
|
||||
// Check the initial state.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4'),
|
||||
$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 a partially right answer.
|
||||
$this->process_submission(array('p1' => '1', 'p2' => '1', 'p3' => '2', 'p4' => '1'));
|
||||
|
||||
// Finish the attempt without clicking check.
|
||||
$this->quba->finish_all_questions();
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$gradedpartial);
|
||||
$this->check_current_mark(1);
|
||||
|
||||
$this->check_current_output(
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_submit_button_expectation(false),
|
||||
$this->get_contains_partcorrect_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::$gradedpartial);
|
||||
$this->check_current_mark(1);
|
||||
}
|
||||
|
||||
public function test_interactive_no_right_clears() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$dd->hints = array(
|
||||
new question_hint_with_parts(23, 'This is the first hint.', FORMAT_MOODLE, false, true),
|
||||
new question_hint_with_parts(24, 'This is the second hint.', FORMAT_MOODLE, true, true),
|
||||
);
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, '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_marked_out_of_summary(),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4'),
|
||||
$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 a completely wrong answer.
|
||||
$this->process_submission(
|
||||
array('p1' => '2', 'p2' => '1', 'p3' => '2', 'p4' => '1', '-submit' => 1));
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_marked_out_of_summary(),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_submit_button_expectation(false),
|
||||
$this->get_contains_hint_expectation('This is the first hint'));
|
||||
|
||||
// Do try again.
|
||||
$this->process_submission(
|
||||
array('p1' => '', 'p2' => '', 'p3' => '', 'p4' => '', '-tryagain' => 1));
|
||||
|
||||
// Check that all the wrong answers have been cleared.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_marked_out_of_summary(),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 1),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 1),
|
||||
$this->get_contains_drag_image_home_expectation(1, 1, 2),
|
||||
$this->get_contains_drag_image_home_expectation(2, 2, 2),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3', ''),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4', ''),
|
||||
$this->get_contains_submit_button_expectation(true),
|
||||
$this->get_does_not_contain_feedback_expectation(),
|
||||
$this->get_tries_remaining_expectation(2),
|
||||
$this->get_no_hint_visible_expectation());
|
||||
}
|
||||
|
||||
public function test_display_of_right_answer_when_shuffled() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = test_question_maker::make_question('ddimageortext');
|
||||
$this->start_attempt_at_question($dd, 'deferredfeedback', 3);
|
||||
|
||||
// Check the initial state.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
|
||||
$this->check_current_output(
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3'),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4'),
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
|
||||
// Save a partial answer.
|
||||
$this->process_submission($dd->get_correct_response());
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$complete);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p1',
|
||||
$dd->get_right_choice_for(1)),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p2',
|
||||
$dd->get_right_choice_for(2)),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p3',
|
||||
$dd->get_right_choice_for(3)),
|
||||
$this->get_contains_hidden_expectation(
|
||||
$this->quba->get_field_prefix($this->slot) . 'p4',
|
||||
$dd->get_right_choice_for(4)),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
|
||||
// Finish the attempt.
|
||||
$this->quba->finish_all_questions();
|
||||
|
||||
// Verify.
|
||||
$this->displayoptions->rightanswer = question_display_options::VISIBLE;
|
||||
$this->assertEquals('Drop zone 1 -> {1. quick} '.
|
||||
'Drop zone 2 -> {2. fox} '.
|
||||
'Drop zone 3 -> {1. lazy} '.
|
||||
'Drop zone 4 -> {2. dog}',
|
||||
$dd->get_right_answer_summary());
|
||||
$this->check_current_state(question_state::$gradedright);
|
||||
$this->check_current_mark(3);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user