mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-40264 fix essay handling of zero-string response
Fixes an inappropriate behavior of the is_complete_response() function for the Essay question type, which caused the string "0" to be inappropriately marked as an incomplete response. Also adds a set of unit tests for the Essay question type's is_complete_response.
This commit is contained in:
parent
6420fea64b
commit
3553982d6d
2 changed files with 16 additions and 1 deletions
|
@ -82,7 +82,7 @@ class qtype_essay_question extends question_with_responses {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function is_complete_response(array $response) {
|
public function is_complete_response(array $response) {
|
||||||
return !empty($response['answer']);
|
return array_key_exists('answer', $response) && ($response['answer'] !== '');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function is_same_response(array $prevresponse, array $newresponse) {
|
public function is_same_response(array $prevresponse, array $newresponse) {
|
||||||
|
|
|
@ -49,4 +49,19 @@ class qtype_essay_question_test extends advanced_testcase {
|
||||||
$this->assertEquals($longstring,
|
$this->assertEquals($longstring,
|
||||||
$essay->summarise_response(array('answer' => $longstring)));
|
$essay->summarise_response(array('answer' => $longstring)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_is_complete_response() {
|
||||||
|
|
||||||
|
$essay = test_question_maker::make_an_essay_question();
|
||||||
|
$essay->start_attempt(new question_attempt_step(), 1);
|
||||||
|
|
||||||
|
// The empty string should be considered an empty response, as should a lack of a response.
|
||||||
|
$this->assertFalse($essay->is_complete_response(array('answer' => '')));
|
||||||
|
$this->assertFalse($essay->is_complete_response(array()));
|
||||||
|
|
||||||
|
// Any nonempty string should be considered a complete response.
|
||||||
|
$this->assertTrue($essay->is_complete_response(array('answer' => 'A student response.')));
|
||||||
|
$this->assertTrue($essay->is_complete_response(array('answer' => '0 times.')));
|
||||||
|
$this->assertTrue($essay->is_complete_response(array('answer' => '0')));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue