From 221bfed37bf9706cf9803879997d472631206804 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 16 Aug 2019 08:50:33 +0800 Subject: [PATCH] MDL-66378 behat: Fix use of before/after selectors --- mod/glossary/tests/behat/categories.feature | 5 ++--- question/tests/generator/lib.php | 13 +++++++++++-- search/tests/behat/search_by_user.feature | 14 +++++++------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/mod/glossary/tests/behat/categories.feature b/mod/glossary/tests/behat/categories.feature index 53597c4728201..2154e7b13f109 100644 --- a/mod/glossary/tests/behat/categories.feature +++ b/mod/glossary/tests/behat/categories.feature @@ -80,8 +80,8 @@ Feature: Glossary entries can be organised in categories And I follow "Browse by category" And "//h3[contains(.,'CATEGORYAUTOLINKS')]" "xpath_element" should appear before "//h3[contains(.,'CATEGORYNOLINKS')]" "xpath_element" And "//h4[contains(.,'EntryCategoryAL')]" "xpath_element" should appear before "//h3[contains(.,'CATEGORYNOLINKS')]" "xpath_element" - And "//h4[contains(.,'EntryCategoryBoth')]" "xpath_element" should appear before "//h3[contains(.,'CATEGORYNOLINKS')]" "xpath_element" - And "//h3[contains(.,'CATEGORYNOLINKS')]" "xpath_element" should appear before "//h4[contains(.,'EntryCategoryBoth')]" "xpath_element" + And "(//h4[contains(.,'EntryCategoryBoth')])[1]" "xpath_element" should appear before "//h3[contains(.,'CATEGORYNOLINKS')]" "xpath_element" + And "//h3[contains(.,'CATEGORYNOLINKS')]" "xpath_element" should appear before "(//h4[contains(.,'EntryCategoryBoth')])[2]" "xpath_element" And "//h4[contains(.,'EntryCategoryNL')]" "xpath_element" should appear after "//h3[contains(.,'CATEGORYNOLINKS')]" "xpath_element" And I should not see "EntryNoCategory" And I set the field "hook" to "Not categorised" @@ -116,4 +116,3 @@ Feature: Glossary entries can be organised in categories And I should see "EntryNoCategory" And I should see "EntryCategoryAL" And I should not see "EntryCategoryBoth" - And I log out diff --git a/question/tests/generator/lib.php b/question/tests/generator/lib.php index 4d09630e4c63b..5d10eb812d0c5 100644 --- a/question/tests/generator/lib.php +++ b/question/tests/generator/lib.php @@ -102,7 +102,7 @@ public function create_question($qtype, $which = null, $overrides = null) { * @param array|stdClass $overrides any fields that should be different from the base example. */ public function update_question($question, $which = null, $overrides = null) { - global $CFG; + global $CFG, $DB; require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); $qtype = $question->qtype; @@ -113,7 +113,16 @@ public function update_question($question, $which = null, $overrides = null) { $fromform = (object) $this->datagenerator->combine_defaults_and_record( (array) $fromform, $overrides); - return question_bank::get_qtype($qtype)->save_question($question, $fromform); + $question = question_bank::get_qtype($qtype)->save_question($question, $fromform); + + if ($overrides && array_key_exists('createdby', $overrides)) { + // Manually update the createdby because questiontypebase forces current user and some tests require a + // specific user. + $question->createdby = $overrides['createdby']; + $DB->update_record('question', $question); + } + + return $question; } /** diff --git a/search/tests/behat/search_by_user.feature b/search/tests/behat/search_by_user.feature index a14beda9af04e..e5c1093fabbb8 100644 --- a/search/tests/behat/search_by_user.feature +++ b/search/tests/behat/search_by_user.feature @@ -34,10 +34,10 @@ Feature: Select users when searching for user-created content | activity | PAGE1 | And I search for "frogs" using the header global search box And I expand all fieldsets - And I set the field with xpath "//select[@id='id_userids']/..//input[@type='text']" to "Anne" + When I expand the "Users" autocomplete # Alphabetical surname order. - Then "Anne Additional" "text" should appear before "Anne Ditin" "text" - And "Anne Ditin" "text" should appear before "Anne Other" "text" + Then "Anne Additional" "text" should appear before "Anne Ditin" "text" in the "Users" "autocomplete" + And "Anne Ditin" "text" should appear before "Anne Other" "text" in the "Users" "autocomplete" @javascript Scenario: As administrator, search for users within course @@ -49,9 +49,9 @@ Feature: Select users when searching for user-created content And I search for "frogs" using the header global search box And I expand all fieldsets And I select "Course: Frogs" from the "Search within" singleselect - And I set the field with xpath "//select[@id='id_userids']/..//input[@type='text']" to "Anne" + When I expand the "Users" autocomplete # Users in selected course appear first. - And "Anne Additional" "text" should appear after "Anne Other" "text" + Then "Anne Additional" "text" should appear after "Anne Other" "text" in the "Users" "autocomplete" @javascript Scenario: As student, cannot see users on other courses @@ -62,6 +62,6 @@ Feature: Select users when searching for user-created content | activity | PAGE1 | And I search for "frogs" using the header global search box And I expand all fieldsets - And I set the field with xpath "//select[@id='id_userids']/..//input[@type='text']" to "A" - Then "Anne Ditin" "text" should appear before "Anne Other" "text" + When I expand the "Users" autocomplete + Then "Anne Ditin" "text" should appear before "Anne Other" "text" in the "Users" "autocomplete" And "Anne Additional" "text" should not exist