Skip to content

Commit

Permalink
Bugfix: Correct order for in-course breadcrumb when sections exist in…
Browse files Browse the repository at this point in the history
… it (First categories then sections) (#483)
  • Loading branch information
danowar2k authored and abias committed Apr 21, 2024
1 parent 9461b8d commit 690be9e
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 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-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
Expand Down
17 changes: 15 additions & 2 deletions classes/boostnavbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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.
Expand Down
33 changes: 33 additions & 0 deletions tests/behat/behat_theme_boost_union_behat_navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<coursefullname_string>(?:[^"]|\\")*)" 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<section_int>(?:[^"]|\\")*)" page of "(?P<coursefullname_string>(?:[^"]|\\")*)" 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]);
}
}
30 changes: 30 additions & 0 deletions tests/behat/theme_boost_union_feelsettings_navigation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 690be9e

Please sign in to comment.