Commit 9064f17b authored by Simey Lameze's avatar Simey Lameze
Browse files

MDL-5311 qtype_multichoice: add php unit tests for the new option

parent 1ff39876
......@@ -133,6 +133,17 @@ class qtype_multichoice_multi_question_test extends advanced_testcase {
$this->assertEquals('B; C', $summary);
}
public function test_summarise_response_clearchoice() {
$mc = test_question_maker::make_a_multichoice_multi_question();
$mc->shuffleanswers = false;
$mc->start_attempt(new question_attempt_step(), 1);
$summary = $mc->summarise_response($mc->prepare_simulated_post_data(array('clearchoice' => -1)),
test_question_maker::get_a_qa($mc));
$this->assertNull($summary);
}
public function test_classify_response() {
$mc = test_question_maker::make_a_multichoice_multi_question();
$mc->start_attempt(new question_attempt_step(), 1);
......
......@@ -47,6 +47,8 @@ class qtype_multichoice_single_question_test extends advanced_testcase {
$this->assertFalse($question->is_complete_response(array()));
$this->assertTrue($question->is_complete_response(array('answer' => '0')));
$this->assertTrue($question->is_complete_response(array('answer' => '2')));
$this->assertFalse($question->is_complete_response(array('answer' => '-1')));
$this->assertFalse($question->is_complete_response(array('answer' => -1)));
}
public function test_is_gradable_response() {
......@@ -55,6 +57,7 @@ class qtype_multichoice_single_question_test extends advanced_testcase {
$this->assertFalse($question->is_gradable_response(array()));
$this->assertTrue($question->is_gradable_response(array('answer' => '0')));
$this->assertTrue($question->is_gradable_response(array('answer' => '2')));
$this->assertFalse($question->is_gradable_response(array('answer' => '-1')));
}
public function test_is_same_response() {
......@@ -80,6 +83,22 @@ class qtype_multichoice_single_question_test extends advanced_testcase {
$this->assertTrue($question->is_same_response(
array('answer' => '2'),
array('answer' => '2')));
$this->assertFalse($question->is_same_response(
array('answer' => '0'),
array('answer' => '-1')));
$this->assertFalse($question->is_same_response(
array('answer' => '-1'),
array('answer' => '0')));
$this->assertTrue($question->is_same_response(
array('answer' => '-1'),
array('answer' => '-1')));
$this->assertTrue($question->is_same_response(
array(),
array('answer' => '-1')));
}
public function test_grading() {
......@@ -138,6 +157,9 @@ class qtype_multichoice_single_question_test extends advanced_testcase {
test_question_maker::get_a_qa($mc));
$this->assertEquals('A', $summary);
$this->assertNull($mc->summarise_response(array(), test_question_maker::get_a_qa($mc)));
$this->assertNull($mc->summarise_response(array('answer' => '-1'), test_question_maker::get_a_qa($mc)));
}
public function test_classify_response() {
......@@ -149,7 +171,11 @@ class qtype_multichoice_single_question_test extends advanced_testcase {
$this->assertEquals(array(
$mc->id => question_classified_response::no_response(),
), $mc->classify_response(array()));
), $mc->classify_response(array()));
$this->assertEquals(array(
$mc->id => question_classified_response::no_response(),
), $mc->classify_response(array('answer' => '-1')));
}
public function test_make_html_inline() {
......
......@@ -97,4 +97,73 @@ class qtype_multichoice_walkthrough_test extends qbehaviour_walkthrough_test_bas
new question_pattern_expectation('/class="r0 correct"/'),
new question_pattern_expectation('/class="r1"/'));
}
/**
* Test for clear choice option.
*/
public function test_deferredfeedback_feedback_multichoice_clearchoice() {
// Create a multichoice, single question.
$mc = test_question_maker::make_a_multichoice_single_question();
$mc->shuffleanswers = false;
$clearchoice = -1;
$rightchoice = 0;
$wrongchoice = 2;
$this->start_attempt_at_question($mc, 'deferredfeedback', 3);
// Let's first submit the wrong choice (2).
$this->process_submission(array('answer' => $wrongchoice)); // Wrong choice (2).
$this->check_current_mark(null);
// Clear choice radio should not be checked.
$this->check_current_output(
$this->get_contains_mc_radio_expectation($rightchoice, true, false), // Not checked.
$this->get_contains_mc_radio_expectation($rightchoice + 1, true, false), // Not checked.
$this->get_contains_mc_radio_expectation($rightchoice + 2, true, true), // Wrong choice (2) checked.
$this->get_contains_mc_radio_expectation($clearchoice, true, false), // Not checked.
$this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_feedback_expectation()
);
// Now, let's clear our previous choice.
$this->process_submission(array('answer' => $clearchoice)); // Clear choice (-1).
$this->check_current_mark(null);
// This time, the clear choice radio should be the only one checked.
$this->check_current_output(
$this->get_contains_mc_radio_expectation($rightchoice, true, false), // Not checked.
$this->get_contains_mc_radio_expectation($rightchoice + 1, true, false), // Not checked.
$this->get_contains_mc_radio_expectation($rightchoice + 2, true, false), // Not checked.
$this->get_contains_mc_radio_expectation($clearchoice, true, true), // Clear choice radio checked.
$this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_feedback_expectation()
);
// Finally, let's submit the right choice.
$this->process_submission(array('answer' => $rightchoice)); // Right choice (0).
$this->check_current_state(question_state::$complete);
$this->check_current_mark(null);
$this->check_current_output(
$this->get_contains_mc_radio_expectation($rightchoice, true, true),
$this->get_contains_mc_radio_expectation($rightchoice + 1, true, false),
$this->get_contains_mc_radio_expectation($rightchoice + 2, true, false),
$this->get_contains_mc_radio_expectation($clearchoice, true, false),
$this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_feedback_expectation()
);
// Finish the attempt.
$this->finish();
// Verify.
$this->check_current_state(question_state::$gradedright);
$this->check_current_mark(3);
$this->check_current_output(
$this->get_contains_mc_radio_expectation($rightchoice, false, true),
$this->get_contains_correct_expectation(),
new question_pattern_expectation('/class="r0 correct"/'),
new question_pattern_expectation('/class="r1"/'));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment