diff --git a/lib/classes/navigation/views/primary.php b/lib/classes/navigation/views/primary.php index c1b8108e3e9..8305a98dd79 100644 --- a/lib/classes/navigation/views/primary.php +++ b/lib/classes/navigation/views/primary.php @@ -45,23 +45,21 @@ class primary extends view { $sitehome = $this->add(get_string('home'), new \moodle_url('/'), self::TYPE_SYSTEM, null, 'home', new \pix_icon('i/home', '')); } - if (isloggedin() ) { - if (!isguestuser()) { - $homepage = get_home_page(); - if ($homepage == HOMEPAGE_MY || $homepage == HOMEPAGE_MYCOURSES) { - // We need to stop automatic redirection. - if ($showhomenode) { - $sitehome->action->param('redirect', '0'); - } + if (isloggedin() && !isguestuser()) { + $homepage = get_home_page(); + if ($homepage == HOMEPAGE_MY || $homepage == HOMEPAGE_MYCOURSES) { + // We need to stop automatic redirection. + if ($showhomenode) { + $sitehome->action->param('redirect', '0'); } + } - // Add the dashboard link. - $showmyhomenode = empty($this->page->theme->removedprimarynavitems) || - !in_array('myhome', $this->page->theme->removedprimarynavitems); - if ($showmyhomenode) { - $this->add(get_string('myhome'), new \moodle_url('/my/'), - self::TYPE_SETTING, null, 'myhome', new \pix_icon('i/dashboard', '')); - } + // Add the dashboard link. + $showmyhomenode = empty($this->page->theme->removedprimarynavitems) || + !in_array('myhome', $this->page->theme->removedprimarynavitems); + if ($showmyhomenode) { + $this->add(get_string('myhome'), new \moodle_url('/my/'), + self::TYPE_SETTING, null, 'myhome', new \pix_icon('i/dashboard', '')); } // Add the mycourses link. diff --git a/lib/tests/navigation/views/primary_test.php b/lib/tests/navigation/views/primary_test.php index b4193c975e2..ca48e6314e7 100644 --- a/lib/tests/navigation/views/primary_test.php +++ b/lib/tests/navigation/views/primary_test.php @@ -61,7 +61,7 @@ class primary_test extends \advanced_testcase { */ public function test_setting_initialise_provider() { return [ - 'Testing as a guest user' => ['guest', ['home', 'courses']], + 'Testing as a guest user' => ['guest', ['home']], 'Testing as an admin' => ['admin', ['home', 'myhome', 'courses', 'siteadminnode']], 'Testing as a regular user' => ['user', ['home', 'myhome', 'courses']] ]; diff --git a/theme/boost/tests/behat/primarynav.feature b/theme/boost/tests/behat/primarynav.feature index 8edf0852324..dc154ea6b15 100644 --- a/theme/boost/tests/behat/primarynav.feature +++ b/theme/boost/tests/behat/primarynav.feature @@ -54,3 +54,12 @@ Feature: Primary navigation And "Side panel" "button" should exist And I click on "Side panel" "button" And I should see "Home" in the "theme_boost-drawers-primary" "region" + + @theme_boost + Scenario: Guest users can only see the Home item in the primary navigation menu + Given I log in as "guest" + When I am on site homepage + Then I should see "Home" in the ".primary-navigation" "css_element" + And I should not see "Dashboard" in the ".primary-navigation" "css_element" + And I should not see "My courses" in the ".primary-navigation" "css_element" + And I should not see "Site administration" in the ".primary-navigation" "css_element"