mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-50893 questions: cannot create a question with name 0
This commit is contained in:
parent
d84625438e
commit
1f17e41e9a
@ -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 = '-';
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user