Skip to content

Commit

Permalink
Upgrade: Adopt changes from MDL-81960 to Behat optimizations and use …
Browse files Browse the repository at this point in the history
…new \core\url class there as well
  • Loading branch information
abias committed Dec 8, 2024
1 parent 2cba6af commit a4c2860
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes

### Unreleased

* 2024-12-08 - Upgrade: Adopt changes from MDL-81960 to Behat optimizations and use new \core\url class there as well.
* 2024-12-06 - Tests: Add several Behat optimisations to bring down the test suite run time, resolves #765.
* 2024-12-06 - Upstream change: Adopt changes from MDL-83759 ('System notification navbar popover is misplaced in Moodle 4.4 and 4.5')
* 2024-12-06 - Upstream change: Adopt changes from MDL-75610 ('Quiz activity name no longer being displayed in quiz landing page when using Safe Exam Browser'), resolves #766.
Expand Down
34 changes: 18 additions & 16 deletions tests/behat/behat_theme_boost_union.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

use core\url;

/**
* Theme Boost Union - Standard behat step data providers.
*
Expand All @@ -38,21 +40,21 @@ class behat_theme_boost_union extends behat_base {
* | Smart menus | Smart menus listing page |
*
* @param string $page name of the page, with the component name removed e.g. 'Admin notification'.
* @return moodle_url the corresponding URL.
* @return 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 {
protected function resolve_page_url(string $page): url {
$parts = explode('>', strtolower($page));
$section = trim($parts[0]);
if (count($parts) < 2) {
return match ($section) {
'settings' => new moodle_url('/theme/boost_union/settings_overview.php'),
'look' => new moodle_url('/admin/settings.php?section=theme_boost_union_look'),
'feel' => new moodle_url('/admin/settings.php?section=theme_boost_union_feel'),
'content' => new moodle_url('/admin/settings.php?section=theme_boost_union_content'),
'functionality' => new moodle_url('/admin/settings.php?section=theme_boost_union_functionality'),
'flavours' => new moodle_url('/theme/boost_union/flavours/overview.php'),
'smart menus' => new moodle_url('/theme/boost_union/smartmenus/menus.php'),
'settings' => new url('/theme/boost_union/settings_overview.php'),
'look' => new url('/admin/settings.php?section=theme_boost_union_look'),
'feel' => new url('/admin/settings.php?section=theme_boost_union_feel'),
'content' => new url('/admin/settings.php?section=theme_boost_union_content'),
'functionality' => new url('/admin/settings.php?section=theme_boost_union_functionality'),
'flavours' => new url('/theme/boost_union/flavours/overview.php'),
'smart menus' => new url('/theme/boost_union/smartmenus/menus.php'),
default => throw new Exception('Unrecognised theme_boost_union page "' . $page . '."')
};
}
Expand Down Expand Up @@ -129,7 +131,7 @@ protected function resolve_page_url(string $page): moodle_url {
if (!in_array($suffix, $tabs)) {
throw new Exception('Unrecognised theme_boost_union page "' . $page . '."');
}
return new moodle_url('/admin/settings.php?section=theme_boost_union_' . $section . '_' . $suffix);
return new url('/admin/settings.php?section=theme_boost_union_' . $section . '_' . $suffix);
}

/**
Expand All @@ -146,10 +148,10 @@ protected function resolve_page_url(string $page): moodle_url {
*
* @param string $type identifies which type of page this is, e.g. 'Smart menu item'.
* @param string $identifier identifies the particular page, e.g. 'Menu 1 > Item 1'.
* @return moodle_url the corresponding URL.
* @return url the corresponding URL.
* @throws Exception with a meaningful error message if the specified page cannot be found.
*/
protected function resolve_page_instance_url(string $type, string $identifier): moodle_url {
protected function resolve_page_instance_url(string $type, string $identifier): url {
$parts = explode('>', strtolower($type));
$pagetype = trim($parts[0]);

Expand All @@ -159,7 +161,7 @@ protected function resolve_page_instance_url(string $type, string $identifier):
if (!in_array($page, ['preview', 'edit'])) {
throw new Exception('Unrecognised theme_boost_union page type "' . $type . '."');
}
return new moodle_url(
return new url(
'/theme/boost_union/flavours/' . $page . '.php',
[
'id' => $this->get_flavour_id_by_title($identifier),
Expand All @@ -173,7 +175,7 @@ protected function resolve_page_instance_url(string $type, string $identifier):
throw new Exception('Unrecognised theme_boost_union page type "' . $type . '."');
}
$idparam = $page == 'edit' ? 'id' : 'menu';
return new moodle_url(
return new url(
'/theme/boost_union/smartmenus/' . $page . '.php',
[
$idparam => $this->get_smartmenu_id_by_title($identifier),
Expand All @@ -186,7 +188,7 @@ protected function resolve_page_instance_url(string $type, string $identifier):
$menutitle = trim($idparts[0]);
$itemtitle = trim($idparts[1]);
$menuid = $this->get_smartmenu_id_by_title($menutitle);
return new moodle_url(
return new url(
'/theme/boost_union/smartmenus/edit_items.php',
[
'id' => $this->get_smartmenu_item_id_by_title($menuid, $itemtitle),
Expand All @@ -195,7 +197,7 @@ protected function resolve_page_instance_url(string $type, string $identifier):
);

case 'course completion':
return new moodle_url(
return new url(
'/course/completion.php',
[
'id' => $this->get_course_id($identifier),
Expand Down

0 comments on commit a4c2860

Please sign in to comment.