From 690be9ea509a6d9a404a09ec0fd3093953c4d372 Mon Sep 17 00:00:00 2001 From: Daniel Poggenpohl Date: Sun, 21 Apr 2024 08:37:46 +0200 Subject: [PATCH] Bugfix: Correct order for in-course breadcrumb when sections exist in it (First categories then sections) (#483) --- CHANGES.md | 1 + classes/boostnavbar.php | 17 ++++++++-- ...hat_theme_boost_union_behat_navigation.php | 33 +++++++++++++++++++ ...oost_union_feelsettings_navigation.feature | 30 +++++++++++++++++ 4 files changed, 79 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9a178c2814b..49cd741981a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Changes ### Unreleased +* 2024-04-20 - Bugfix: Correct order for in-course breadcrumb when sections exist in it (First categories then sections), solves #317. * 2024-04-20 - Cleanup: Add proper JS promise error handling, resolves #435. ### v4.3-r11 diff --git a/classes/boostnavbar.php b/classes/boostnavbar.php index 10d659ce7fb..296313101b3 100644 --- a/classes/boostnavbar.php +++ b/classes/boostnavbar.php @@ -57,7 +57,8 @@ protected function prepare_nodes_for_boost(): void { } if ($this->page->context->contextlevel == CONTEXT_COURSE) { if (get_config('theme_boost_union', 'categorybreadcrumbs') == THEME_BOOST_UNION_SETTING_SELECT_YES) { - // Add the categories breadcrumb navigation nodes. + // Create the categories breadcrumb navigation nodes. + $categorynodes = []; foreach (array_reverse($this->get_categories()) as $category) { $context = \context_coursecat::instance($category->id); if (!\core_course_category::can_view_category($category)) { @@ -72,8 +73,20 @@ protected function prepare_nodes_for_boost(): void { if (!$category->visible) { $categorynode->hidden = true; } - $this->items[] = $categorynode; + $categorynodes[] = $categorynode; } + $itemswithcategories = []; + if (!$this->items) { + $itemswithcategories = $categorynodes; + } else { + foreach ($this->items as $item) { + if ($item->type == \breadcrumb_navigation_node::TYPE_COURSE) { + $itemswithcategories = array_merge($itemswithcategories, $categorynodes); + } + $itemswithcategories[] = $item; + } + } + $this->items = $itemswithcategories; } // Remove any duplicate navbar nodes. diff --git a/tests/behat/behat_theme_boost_union_behat_navigation.php b/tests/behat/behat_theme_boost_union_behat_navigation.php index 63f9ba96822..ff32c0d28e8 100644 --- a/tests/behat/behat_theme_boost_union_behat_navigation.php +++ b/tests/behat/behat_theme_boost_union_behat_navigation.php @@ -41,4 +41,37 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class behat_theme_boost_union_behat_navigation extends behat_theme_boost_behat_navigation { + + /** + * Set the course format options to one page per section. + * + * @Given /^"(?P(?:[^"]|\\")*)" has been set to one page per section$/ + * @param string $coursefullname The full name of the course. + * @return void + */ + public function has_been_set_to_one_page_per_section(string $coursefullname) { + $courseid = $this->get_course_id($coursefullname); + $format = course_get_format($courseid); + $sectionsperpage = new stdClass(); + $sectionsperpage->coursedisplay = COURSE_DISPLAY_MULTIPAGE; + $format->update_course_format_options($sectionsperpage); + } + + /** + * Opens the nth section of the course. + * + * @When /^I am on section "(?P(?:[^"]|\\")*)" page of "(?P(?:[^"]|\\")*)" course$/ + * @param int $section The ID of the section. + * @param string $coursefullname The full name of the course. + * @return void + */ + public function i_am_on_the_nth_section_page_of_course(int $section, string $coursefullname) { + $courseid = $this->get_course_id($coursefullname); + $urlparams = [ + 'id' => $courseid, + 'section' => $section, + ]; + $url = new moodle_url('/course/view.php', $urlparams); + $this->execute('behat_general::i_visit', [$url]); + } } diff --git a/tests/behat/theme_boost_union_feelsettings_navigation.feature b/tests/behat/theme_boost_union_feelsettings_navigation.feature index b08db01b329..d3df8c27228 100644 --- a/tests/behat/theme_boost_union_feelsettings_navigation.feature +++ b/tests/behat/theme_boost_union_feelsettings_navigation.feature @@ -206,6 +206,36 @@ Feature: Configuring the theme_boost_union plugin for the "Navigation" tab on th | yes | should | | no | should not | + Scenario: Setting: Course category breadcrumbs (verify that course sections are properly displayed _after_ the categories) + Given the following "categories" exist: + | name | category | idnumber | category | + | Category E | 0 | CE | 0 | + | Category ED | 1 | CED | CE | + And the following "courses" exist: + | fullname | shortname | category | + | Course C1 | CC1 | CE | + | Course C2 | CC2 | CED | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | CC2 | editingteacher | + And the following config values are set as admin: + | config | value | plugin | + | categorybreadcrumbs | yes | theme_boost_union | + And "Course C1" has been set to one page per section + And "Course C2" has been set to one page per section + When I log in as "teacher1" + And I am on section "1" page of "Course C1" course + Then "Category E" "link" should exist in the ".breadcrumb" "css_element" + And "Enrolment options" "text" should exist in the ".breadcrumb" "css_element" + And "Enrolment options" "text" should appear after "Category E" "link" in the ".breadcrumb" "css_element" + And "Topic 1" "link" should not exist in the ".breadcrumb" "css_element" + And I am on section "1" page of "Course C2" course + And "Category E" "link" should exist in the ".breadcrumb" "css_element" + And "Category ED" "link" should exist in the ".breadcrumb" "css_element" + And "Topic 1" "link" should exist in the ".breadcrumb" "css_element" + And "Category ED" "link" should appear after "Category E" "link" in the ".breadcrumb" "css_element" + And "Topic 1" "link" should appear after "Category ED" "link" in the ".breadcrumb" "css_element" + @javascript Scenario: Setting: back to top button - Enable "Back to top button" Given the following config values are set as admin: