MDL-50893 questions: cannot create a question with name 0

This commit is contained in:
Tim Hunt 2015-07-28 18:17:45 +01:00
parent d84625438e
commit 1f17e41e9a
2 changed files with 26 additions and 4 deletions

View File

@ -335,9 +335,9 @@ class question_type {
$question->generalfeedbackformat = !empty($form->generalfeedback['format']) ?
$form->generalfeedback['format'] : 0;
if (empty($question->name)) {
if ($question->name === '') {
$question->name = shorten_text(strip_tags($form->questiontext['text']), 15);
if (empty($question->name)) {
if ($question->name === '') {
$question->name = '-';
}
}

View File

@ -36,10 +36,32 @@ require_once($CFG->dirroot . '/question/type/questiontypebase.php');
* @copyright 2008 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class question_type_test extends advanced_testcase {
class question_type_testcase extends advanced_testcase {
public static $includecoverage = array('question/type/questiontypebase.php');
public function test_not_done_yet() {
public function test_save_question_name() {
$this->resetAfterTest();
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $questiongenerator->create_question_category(array());
$saq = $questiongenerator->create_question('shortanswer', null,
array('category' => $cat->id, 'name' => 'Test question'));
$actual = question_bank::load_question_data($saq->id);
$this->assertSame('Test question', $actual->name);
}
public function test_save_question_zero_name() {
$this->resetAfterTest();
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $questiongenerator->create_question_category(array());
$saq = $questiongenerator->create_question('shortanswer', null,
array('category' => $cat->id, 'name' => '0'));
$actual = question_bank::load_question_data($saq->id);
$this->assertSame('0', $actual->name);
}
}