diff --git a/user/tests/behat/behat_user.php b/user/tests/behat/behat_user.php index eff2a766406..8397c1cf464 100644 --- a/user/tests/behat/behat_user.php +++ b/user/tests/behat/behat_user.php @@ -84,4 +84,26 @@ class behat_user extends behat_base { throw new ExpectationException('The "' . $field . '" field does have purpose "' . $purpose . '"', $this->getSession()); } } + + /** + * Convert page names to URLs for steps like 'When I am on the "[page name]" page'. + * + * Recognised page names are: + * | Page name | Description | + * | Contact Site Support | The Contact Site Support page (user/contactsitesupport.php) | + * + * @param string $page name of the page, with the component name removed e.g. 'Admin notification'. + * @return moodle_url the corresponding URL. + * @throws Exception with a meaningful error message if the specified page cannot be found. + */ + protected function resolve_page_url(string $page): moodle_url { + + switch (strtolower($page)) { + case 'contact site support': + return new moodle_url('/user/contactsitesupport.php'); + + default: + throw new Exception("Unrecognised core_user page type '{$page}'."); + } + } }