From ddc9a30fa17b4eb095e6e7d241611dbf68b71825 Mon Sep 17 00:00:00 2001
From: Michael Hawkins <michaelh@moodle.com>
Date: Sat, 15 Oct 2022 00:37:29 +0800
Subject: [PATCH] MDL-74643 core_user: Added behat page resolver

Currently this supports resolving the Contact Site Support page.
---
 user/tests/behat/behat_user.php | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

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}'.");
+        }
+    }
 }