diff --git a/admin/tool/behat/renderer.php b/admin/tool/behat/renderer.php index 0df7e3a7b98..503bc094c1d 100644 --- a/admin/tool/behat/renderer.php +++ b/admin/tool/behat/renderer.php @@ -89,7 +89,7 @@ class tool_behat_renderer extends plugin_renderer_base { $stepsdefinitions = implode('', $stepsdefinitions); // Replace text selector type arguments with a user-friendly select. - $stepsdefinitions = preg_replace_callback('/(TEXT_SELECTOR_STRING)/', + $stepsdefinitions = preg_replace_callback('/(TEXT_SELECTOR\d?_STRING)/', function ($matches) { return html_writer::select(behat_command::$allowedtextselectors, uniqid()); }, @@ -97,7 +97,7 @@ class tool_behat_renderer extends plugin_renderer_base { ); // Replace selector type arguments with a user-friendly select. - $stepsdefinitions = preg_replace_callback('/(SELECTOR_STRING)/', + $stepsdefinitions = preg_replace_callback('/(SELECTOR\d?_STRING)/', function ($matches) { return html_writer::select(behat_command::$allowedselectors, uniqid()); }, diff --git a/backup/util/ui/tests/behat/duplicate_activities.feature b/backup/util/ui/tests/behat/duplicate_activities.feature new file mode 100644 index 00000000000..f23efc4b70e --- /dev/null +++ b/backup/util/ui/tests/behat/duplicate_activities.feature @@ -0,0 +1,33 @@ +@backup +Feature: Duplicate activities + In order to set up my course contents quickly + As a moodle teacher + I need to duplicate activities inside the same course + + @javascript + Scenario: Duplicate an activity + Given the following "courses" exists: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "users" exists: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@asd.com | + And the following "course enrolments" exists: + | user | course | role | + | teacher1 | C1 | editingteacher | + And I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I add a "Database" to section "1" and I fill the form with: + | Name | Test database name | + | Description | Test database description | + When I click on "Duplicate" "link" in the "#section-1" "css_element" + And I press "Continue" + And I press "Edit the new copy" + And I fill the moodle form with: + | Name | Duplicated database name | + | Description | Duplicated database description | + And I press "Save and return to course" + Then I should see "Test database name" in the "#section-1" "css_element" + And I should see "Duplicated database name" in the "#section-1" "css_element" + And "Test database name" "link" should appear before "Duplicated database name" "link" diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index f8285bc6f1a..ea6b623bad8 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -190,6 +190,60 @@ class behat_general extends behat_base { $this->assertSession()->elementTextNotContains($selector, $locator, $text); } + /** + * Checks, that the first specified element appears before the second one. + * + * @Given /^"(?P(?:[^"]|\\")*)" "(?P(?:[^"]|\\")*)" should appear before "(?P(?:[^"]|\\")*)" "(?P(?:[^"]|\\")*)"$/ + * @throws ExpectationException + * @param string $preelement The locator of the preceding element + * @param string $preselectortype The locator of the preceding element + * @param string $postelement The locator of the latest element + * @param string $postselectortype The selector type of the latest element + */ + public function should_appear_before($preelement, $preselectortype, $postelement, $postselectortype) { + + // We allow postselectortype as a non-text based selector. + list($preselector, $prelocator) = $this->transform_selector($preselectortype, $preelement); + list($postselector, $postlocator) = $this->transform_selector($postselectortype, $postelement); + + $prexpath = $this->find($preselector, $prelocator)->getXpath(); + $postxpath = $this->find($postselector, $postlocator)->getXpath(); + + // Using following xpath axe to find it. + $msg = '"'.$preelement.'" "'.$preselectortype.'" does not appear before "'.$postelement.'" "'.$postselectortype.'"'; + $xpath = $prexpath.'/following::*[contains(., '.$postxpath.')]'; + if (!$this->getSession()->getDriver()->find($xpath)) { + throw new ExpectationException($msg, $this->getSession()); + } + } + + /** + * Checks, that the first specified element appears after the second one. + * + * @Given /^"(?P(?:[^"]|\\")*)" "(?P(?:[^"]|\\")*)" should appear after "(?P(?:[^"]|\\")*)" "(?P(?:[^"]|\\")*)"$/ + * @throws ExpectationException + * @param string $postelement The locator of the latest element + * @param string $postselectortype The selector type of the latest element + * @param string $preelement The locator of the preceding element + * @param string $preselectortype The locator of the preceding element + */ + public function should_appear_after($postelement, $postselectortype, $preelement, $preselectortype) { + + // We allow postselectortype as a non-text based selector. + list($postselector, $postlocator) = $this->transform_selector($postselectortype, $postelement); + list($preselector, $prelocator) = $this->transform_selector($preselectortype, $preelement); + + $postxpath = $this->find($postselector, $postlocator)->getXpath(); + $prexpath = $this->find($preselector, $prelocator)->getXpath(); + + // Using preceding xpath axe to find it. + $msg = '"'.$postelement.'" "'.$postselectortype.'" does not appear after "'.$preelement.'" "'.$preselectortype.'"'; + $xpath = $postxpath.'/preceding::*[contains(., '.$prexpath.')]'; + if (!$this->getSession()->getDriver()->find($xpath)) { + throw new ExpectationException($msg, $this->getSession()); + } + } + /** * Checks, that element of specified type is disabled. *