mirror of
https://github.com/moodle/moodle.git
synced 2025-04-23 09:23:09 +02:00
MDL-67842 questions: Cannot remove the idnumber from a question
This commit is contained in:
parent
cb38ab1e39
commit
2569fb5d2c
question
@ -24,7 +24,6 @@ Feature: A teacher can edit questions in the question bank
|
||||
And I am on "Course 1" course homepage
|
||||
And I navigate to "Question bank > Questions" in current page administration
|
||||
|
||||
@javascript
|
||||
Scenario: Edit a previously created question
|
||||
When I choose "Edit question" action for "Test question to be edited" in the question bank
|
||||
And I set the following fields to these values:
|
||||
@ -36,7 +35,6 @@ Feature: A teacher can edit questions in the question bank
|
||||
And "Edited question name" row "Created by" column of "categoryquestions" table should contain "Admin User"
|
||||
And "Edited question name" row "Last modified by" column of "categoryquestions" table should contain "Teacher 1"
|
||||
|
||||
@javascript
|
||||
Scenario: Editing a question can be cancelled
|
||||
When I choose "Edit question" action for "Test question to be edited" in the question bank
|
||||
And I set the field "Question name" to "Edited question name"
|
||||
@ -44,3 +42,14 @@ Feature: A teacher can edit questions in the question bank
|
||||
Then I should see "Test question to be edited"
|
||||
And "Test question to be edited" row "Created by" column of "categoryquestions" table should contain "Admin User"
|
||||
And "Test question to be edited" row "Last modified by" column of "categoryquestions" table should contain "Admin User"
|
||||
|
||||
Scenario: A question can have its idnumber removed
|
||||
Given the following "questions" exist:
|
||||
| questioncategory | qtype | name | idnumber |
|
||||
| Test questions | essay | Question with idnumber | frog |
|
||||
And I reload the page
|
||||
Then I should see "frog" in the "Question with idnumber" "table_row"
|
||||
When I choose "Edit question" action for "Question with idnumber" in the question bank
|
||||
And I set the field "ID number" to ""
|
||||
And I press "id_submitbutton"
|
||||
Then I should not see "frog" in the "Question with idnumber" "table_row"
|
||||
|
@ -371,16 +371,22 @@ class question_type {
|
||||
$question->defaultmark = $form->defaultmark;
|
||||
}
|
||||
|
||||
if (isset($form->idnumber) && ((string) $form->idnumber !== '')) {
|
||||
// While this check already exists in the form validation, this is a backstop preventing unnecessary errors.
|
||||
if (strpos($form->category, ',') !== false) {
|
||||
list($category, $categorycontextid) = explode(',', $form->category);
|
||||
if (isset($form->idnumber)) {
|
||||
if ((string) $form->idnumber === '') {
|
||||
$question->idnumber = null;
|
||||
} else {
|
||||
$category = $form->category;
|
||||
}
|
||||
if (!$DB->record_exists('question',
|
||||
['idnumber' => $form->idnumber, 'category' => $category])) {
|
||||
$question->idnumber = $form->idnumber;
|
||||
// While this check already exists in the form validation,
|
||||
// this is a backstop preventing unnecessary errors.
|
||||
// Only set the idnumber if it has changed and will not cause a unique index violation.
|
||||
if (strpos($form->category, ',') !== false) {
|
||||
list($category, $categorycontextid) = explode(',', $form->category);
|
||||
} else {
|
||||
$category = $form->category;
|
||||
}
|
||||
if (!$DB->record_exists('question',
|
||||
['idnumber' => $form->idnumber, 'category' => $category])) {
|
||||
$question->idnumber = $form->idnumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user