Skip to content

Commit

Permalink
MDL-66378 behat: Fix use of before/after selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Aug 19, 2019
1 parent f782dcf commit 5680713
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
5 changes: 2 additions & 3 deletions mod/glossary/tests/behat/categories.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
13 changes: 11 additions & 2 deletions question/tests/generator/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand Down
14 changes: 7 additions & 7 deletions search/tests/behat/search_by_user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 5680713

Please sign in to comment.