Merge branch 'MDL-40264-essay-zero' of git://github.com/ktemkin/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2013-06-24 21:24:00 +02:00
commit 293aba00b7
2 changed files with 16 additions and 1 deletions

View File

@ -84,7 +84,7 @@ class qtype_essay_question extends question_with_responses {
}
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) {

View File

@ -137,4 +137,19 @@ class qtype_essay_question_test extends advanced_testcase {
array('answer' => ''),
array('answer' => '0')));
}
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')));
}
}