From 7459856d26f0c57bc40cd338e73db9a379988766 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 31 Mar 2020 10:33:18 +0100 Subject: [PATCH] MDL-68300 questions: un-break duplicating questions without idnumbers This was a regression caused by MDL-67934 --- lib/questionlib.php | 4 +- .../tests/behat/duplicate_questions.feature | 51 +++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 question/tests/behat/duplicate_questions.feature diff --git a/lib/questionlib.php b/lib/questionlib.php index 4b831057b45..8b95027026d 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -2390,11 +2390,11 @@ function question_module_uses_questions($modname) { * So idnum -> null (no digits at the end) idnum0099 -> idnum0100 (if that is unused, * else whichever of idnum0101, idnume0102, ... is unused. idnum9 -> idnum10. * - * @param string $oldidnumber a question idnumber. + * @param string|null $oldidnumber a question idnumber, or can be null. * @param int $categoryid a question category id. * @return string|null suggested new idnumber for a question in that category, or null if one cannot be found. */ -function core_question_find_next_unused_idnumber(string $oldidnumber, int $categoryid):? string { +function core_question_find_next_unused_idnumber(?string $oldidnumber, int $categoryid): ?string { global $DB; // The the old idnumber is not of the right form, bail now. diff --git a/question/tests/behat/duplicate_questions.feature b/question/tests/behat/duplicate_questions.feature new file mode 100644 index 00000000000..1c4abb5ead1 --- /dev/null +++ b/question/tests/behat/duplicate_questions.feature @@ -0,0 +1,51 @@ +@core @core_question +Feature: A teacher can duplicate questions in the question bank + In order to efficiently expand my question bank + As a teacher + I need to be able to duplicate existing questions + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | format | + | Course 1 | C1 | weeks | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + And the following "question categories" exist: + | contextlevel | reference | name | + | Course | C1 | Test questions | + And the following "questions" exist: + | questioncategory | qtype | name | questiontext | + | Test questions | essay | Test question to be copied | Write about whatever you want | + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I navigate to "Question bank > Questions" in current page administration + + Scenario: Duplicate a previously created question + When I choose "Duplicate" action for "Test question to be copied" in the question bank + And I press "id_submitbutton" + Then I should see "Test question to be copied (copy)" + And I should see "Test question to be copied" + And "Test question to be copied (copy)" row "Created by" column of "categoryquestions" table should contain "Teacher 1" + And "Test question to be copied (copy)" row "Last modified by" column of "categoryquestions" table should contain "Teacher 1" + + Scenario: Duplicating a question can be cancelled + When I choose "Duplicate" action for "Test question to be copied" in the question bank + And I set the field "Question name" to "Edited question name" + And I press "Cancel" + Then I should see "Test question to be copied" + And I should not see "Edited question name" + And I should not see "Test question to be copied (copy)" + + Scenario: Duplicating a question with an idnumber increments it + Given the following "questions" exist: + | questioncategory | qtype | name | questiontext | idnumber | + | Test questions | essay | Question with idnumber | Write about whatever you want | id101 | + And I reload the page + When I choose "Duplicate" action for "Question with idnumber" in the question bank + And I press "id_submitbutton" + Then I should see "Question with idnumber (copy)" + Then I should see "id102" in the "Question with idnumber (copy)" "table_row"