From 6eee428da493a56b3be6fef06a13158a5840781c Mon Sep 17 00:00:00 2001 From: Ferran Recio Date: Wed, 13 Oct 2021 12:53:31 +0200 Subject: [PATCH] MDL-72787 block_site_main_menu: require course_get_format --- .../site_main_menu/block_site_main_menu.php | 4 +- .../tests/behat/add_url.feature | 62 +++++++++++++++++-- 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/blocks/site_main_menu/block_site_main_menu.php b/blocks/site_main_menu/block_site_main_menu.php index 299bb29cc86..b8b2e4998ac 100644 --- a/blocks/site_main_menu/block_site_main_menu.php +++ b/blocks/site_main_menu/block_site_main_menu.php @@ -47,12 +47,12 @@ class block_site_main_menu extends block_list { return $this->content; } + require_once($CFG->dirroot . '/course/lib.php'); + $course = get_site(); $format = course_get_format($course); $courserenderer = $format->get_renderer($this->page); - require_once($CFG->dirroot.'/course/lib.php'); - $context = context_course::instance($course->id); $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context); diff --git a/blocks/site_main_menu/tests/behat/add_url.feature b/blocks/site_main_menu/tests/behat/add_url.feature index f5ce28b6471..3a4964bac6f 100644 --- a/blocks/site_main_menu/tests/behat/add_url.feature +++ b/blocks/site_main_menu/tests/behat/add_url.feature @@ -11,9 +11,63 @@ Feature: Add URL to main menu block And I turn editing mode on And I add the "Main menu" block When I add a "URL" to section "0" and I fill the form with: - | Name | google | - | Description | gooooooooogle | + | Name | reference link | + | Description | gooooooooogle | | External URL | http://www.google.com | - | id_display | In pop-up | - Then "google" "link" should exist in the "Main menu" "block" + | id_display | In pop-up | + Then "reference link" "link" should exist in the "Main menu" "block" And "Add an activity or resource" "button" should exist in the "Main menu" "block" + + @javascript + Scenario: Add a URL in menu block can appear in all pages + Given the following "course" exists: + | fullname | Course 1 | + | shortname | C1 | + | category | 0 | + | enablecompletion | 1 | + When I log in as "admin" + And I am on site homepage + And I turn editing mode on + And I add the "Main menu" block + And I configure the "Main menu" block + And I set the following fields to these values: + | Page contexts | Display throughout the entire site | + And I press "Save changes" + And I add a "URL" to section "0" and I fill the form with: + | Name | reference link | + | Description | gooooooooogle | + | External URL | http://www.google.com | + | id_display | Embed | + Then I follow "reference link" + And "reference link" "link" should exist in the "Main menu" "block" + And I am on the "C1" "Course" page + And "reference link" "link" should exist in the "Main menu" "block" + And I navigate to "Site administration > Badges > Add a new badge" in site administration + And "reference link" "link" should exist in the "Main menu" "block" + + @javascript + Scenario: Add a URL in menu block can appear in all pages + Given the following "course" exists: + | fullname | Course 1 | + | shortname | C1 | + | category | 0 | + | enablecompletion | 1 | + When I log in as "admin" + And I am on site homepage + And I turn editing mode on + And I add the "Main menu" block + And I configure the "Main menu" block + And I set the following fields to these values: + | Page contexts | Display on the front page and any pages added to the front page | + And I press "Save changes" + And I add a "URL" to section "0" and I fill the form with: + | Name | reference link | + | Description | gooooooooogle | + | External URL | http://www.google.com | + | id_display | Embed | + Then I follow "reference link" + And "reference link" "link" should exist in the "Main menu" "block" + And I am on the "C1" "Course" page + And "Main menu" "block" should not exist + And I navigate to "Site administration > Badges > Add a new badge" in site administration + And "Main menu" "block" should not exist