diff --git a/blocks/course_list/tests/behat/block_course_list_frontpage.feature b/blocks/course_list/tests/behat/block_course_list_frontpage.feature index c0c6ba286fb..325f7c9f107 100644 --- a/blocks/course_list/tests/behat/block_course_list_frontpage.feature +++ b/blocks/course_list/tests/behat/block_course_list_frontpage.feature @@ -84,6 +84,7 @@ Feature: Enable the course_list block on the frontpage and view it's contents And I add the "Courses" block And I log out When I log in as "guest" + And I am on site homepage Then I should see "Category 1" in the "Course categories" "block" And I should see "Category A" in the "Course categories" "block" And I should see "Category B" in the "Course categories" "block" diff --git a/blocks/navigation/tests/behat/expand_courses_node.feature b/blocks/navigation/tests/behat/expand_courses_node.feature index 7436be0f63a..d6e5498c9e7 100644 --- a/blocks/navigation/tests/behat/expand_courses_node.feature +++ b/blocks/navigation/tests/behat/expand_courses_node.feature @@ -177,7 +177,7 @@ Feature: Expand the courses nodes within the navigation block Scenario: As guest I expand the courses and category nodes to see courses. When I log in as "guest" And I am on site homepage - And I should see "Home" in the "Navigation" "block" + And I should see "Site home" in the "Navigation" "block" And I should see "Courses" in the "Navigation" "block" And I expand "Courses" node And I should see "cat1" in the "Navigation" "block" diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 8d48fa6dc26..a68bb235f0f 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -10081,18 +10081,18 @@ function mnet_get_idp_jump_url($user) { function get_home_page() { global $CFG; - if (isloggedin() && !isguestuser() && !empty($CFG->defaulthomepage)) { + if (isloggedin() && !empty($CFG->defaulthomepage)) { // If dashboard is disabled, home will be set to default page. $defaultpage = get_default_home_page(); - if ($CFG->defaulthomepage == HOMEPAGE_MY) { + if ($CFG->defaulthomepage == HOMEPAGE_MY && (!isguestuser() || !empty($CFG->allowguestmymoodle))) { if (!empty($CFG->enabledashboard)) { return HOMEPAGE_MY; } else { return $defaultpage; } - } else if ($CFG->defaulthomepage == HOMEPAGE_MYCOURSES) { + } else if ($CFG->defaulthomepage == HOMEPAGE_MYCOURSES && !isguestuser()) { return HOMEPAGE_MYCOURSES; - } else { + } else if ($CFG->defaulthomepage == HOMEPAGE_USER && !isguestuser()) { $userhomepage = (int) get_user_preferences('user_home_page_preference', $defaultpage); if (empty($CFG->enabledashboard) && $userhomepage == HOMEPAGE_MY) { // If the user was using the dashboard but it's disabled, return the default home page. diff --git a/lib/tests/moodlelib_test.php b/lib/tests/moodlelib_test.php index fdf139beda0..fd9a80cb3e6 100644 --- a/lib/tests/moodlelib_test.php +++ b/lib/tests/moodlelib_test.php @@ -5164,13 +5164,20 @@ EOT; * @dataProvider get_home_page_provider * @param string $user Whether the user is logged, guest or not logged. * @param int $expected Expected value after calling the get_home_page method. - * @param int $defaulthomepage The $CFG->defaulthomepage setting value. - * @param int $enabledashboard Whether the dashboard should be enabled or not. - * @param int $userpreference User preference for the home page setting. + * @param int|null $defaulthomepage The $CFG->defaulthomepage setting value. + * @param int|null $enabledashboard Whether the dashboard should be enabled or not. + * @param int|null $userpreference User preference for the home page setting. + * $param int|null $allowguestmymoodle The $CFG->allowguestmymoodle setting value. * @covers ::get_home_page */ - public function test_get_home_page(string $user, int $expected, ?int $defaulthomepage = null, ?int $enabledashboard = null, - ?int $userpreference = null): void { + public function test_get_home_page( + string $user, + int $expected, + ?int $defaulthomepage = null, + ?int $enabledashboard = null, + ?int $userpreference = null, + ?int $allowguestmymoodle = null, + ): void { global $CFG, $USER; $this->resetAfterTest(); @@ -5187,6 +5194,9 @@ EOT; if (isset($enabledashboard)) { $CFG->enabledashboard = $enabledashboard; } + if (isset($allowguestmymoodle)) { + $CFG->allowguestmymoodle = $allowguestmymoodle; + } if ($USER) { set_user_preferences(['user_home_page_preference' => $userpreference], $USER->id); @@ -5201,21 +5211,37 @@ EOT; * * @return array */ - public function get_home_page_provider(): array { + public static function get_home_page_provider(): array { return [ 'No logged user' => [ 'user' => 'nologged', 'expected' => HOMEPAGE_SITE, ], - 'Guest user' => [ + 'Guest user. Dashboard set as default home page and enabled for guests' => [ + 'user' => 'guest', + 'expected' => HOMEPAGE_MY, + ], + 'Guest user. Dashboard set as default home page but disabled for guests' => [ 'user' => 'guest', 'expected' => HOMEPAGE_SITE, + 'defaulthomepage' => HOMEPAGE_MY, + 'enabledashboard' => 1, + 'userpreference' => null, + 'allowguestmymoodle' => 0, + ], + 'Guest user. My courses set as default home page' => [ + 'user' => 'guest', + 'expected' => HOMEPAGE_SITE, + 'defaulthomepage' => HOMEPAGE_MYCOURSES, + ], + 'Guest user. User preference set as default page' => [ + 'user' => 'guest', + 'expected' => HOMEPAGE_SITE, + 'defaulthomepage' => HOMEPAGE_USER, ], 'Logged user. Dashboard set as default home page and enabled' => [ 'user' => 'logged', 'expected' => HOMEPAGE_MY, - 'defaulthomepage' => HOMEPAGE_MY, - 'enabledashboard' => 1, ], 'Logged user. Dashboard set as default home page but disabled' => [ 'user' => 'logged', diff --git a/user/tests/behat/contact_site_support.feature b/user/tests/behat/contact_site_support.feature index b7fb715a463..9d610aa73f3 100644 --- a/user/tests/behat/contact_site_support.feature +++ b/user/tests/behat/contact_site_support.feature @@ -36,13 +36,11 @@ Feature: Contact site support method and availability can be customised When I am on site homepage Then I should not see "Contact site support" in the "page-footer" "region" And I am on the "user > Contact Site Support" page - And I should see "Acceptance test site" in the "page-header" "region" And I should not see "Contact site support" in the "page-header" "region" # Confirm someone logged in as guest cannot see the option or directly access the page. And I log in as "guest" And I should not see "Contact site support" in the "page-footer" "region" And I am on the "user > Contact Site Support" page - And I should see "Acceptance test site" in the "page-header" "region" And I should not see "Contact site support" in the "page-header" "region" And I log out # Confirm logged in user has access to the contact form.