From ee1052bd18e86f9bba8abab279d634ca30f7edad Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Sat, 3 Mar 2018 16:31:59 +1100 Subject: [PATCH 1/2] MDL-61556 Questions: Fixed moving question categories between contexts --- question/category.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/question/category.php b/question/category.php index faeff3b6649..77ffa39bd58 100644 --- a/question/category.php +++ b/question/category.php @@ -76,8 +76,12 @@ if ($param->moveupcontext || $param->movedowncontext) { } else { $catid = $param->movedowncontext; } + $newtopcat = question_get_top_category($param->tocontext); + if (!$newtopcat) { + print_error('invalidcontext'); + } $oldcat = $DB->get_record('question_categories', array('id' => $catid), '*', MUST_EXIST); - $qcobject->update_category($catid, '0,'.$param->tocontext, $oldcat->name, $oldcat->info); + $qcobject->update_category($catid, "{$newtopcat->id},{$param->tocontext}", $oldcat->name, $oldcat->info); // The previous line does a redirect(). } From 8ece85602a4fb8e4f58257a464108e5a012fc56c Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Mon, 5 Mar 2018 12:45:09 +1100 Subject: [PATCH 2/2] MDL-61556 Questions: Add behat test --- .../behat/move_question_categories.feature | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 question/tests/behat/move_question_categories.feature diff --git a/question/tests/behat/move_question_categories.feature b/question/tests/behat/move_question_categories.feature new file mode 100644 index 00000000000..50f26b2a068 --- /dev/null +++ b/question/tests/behat/move_question_categories.feature @@ -0,0 +1,32 @@ +@core @core_question +Feature: A teacher can move question categories in the question bank + In order to organize my questions + As a teacher + I create question categories and move them in the question bank + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | T1 | Teacher1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + And the following "activities" exist: + | activity | name | course | idnumber | + | quiz | Test quiz | C1 | quiz1 | + And I log in as "teacher1" + And I am on "Course 1" course homepage + + @javascript + Scenario: A question category can be moved to another context + When I follow "Test quiz" + And I navigate to "Categories" in current page administration + And I click on "Parent category" "field" + And I click on "//optgroup[@label='Quiz: Test quiz']//option[normalize-space(text())='Top']" "xpath_element" + And I set the field "Name" to "Test category" + And I press "submitbutton" + And I click on "Share in context for Course: Course 1" "link" in the "Test category" "list_item" + Then I should see "Test category" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' questioncategories ') and contains(concat(' ', normalize-space(@class), ' '), ' contextlevel50 ')]" "xpath_element"