From ed369e32efd86efeb3b6ea902efc8448b089d172 Mon Sep 17 00:00:00 2001 From: Stefan Hanauska Date: Sat, 10 Sep 2022 15:44:09 +0200 Subject: [PATCH 1/2] MDL-75714 navigation: Check if node is false --- lib/classes/navigation/views/secondary.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/classes/navigation/views/secondary.php b/lib/classes/navigation/views/secondary.php index 90089eb3713..89de15a8bd1 100644 --- a/lib/classes/navigation/views/secondary.php +++ b/lib/classes/navigation/views/secondary.php @@ -1027,7 +1027,10 @@ class secondary extends view { $coursesecondarynode = navigation_node::create(get_string('course'), null, self::TYPE_COURSE, null, 'course'); $this->load_course_navigation($coursesecondarynode); // Remove the unnecessary 'Course' child node generated in load_course_navigation(). - $coursesecondarynode->find('coursehome', self::TYPE_COURSE)->remove(); + $coursehomenode = $coursesecondarynode->find('coursehome', self::TYPE_COURSE); + if (!empty($coursehomenode)) { + $coursehomenode->remove(); + } // Add the 'Course' node to the secondary navigation only if this node has children nodes. if (count($coursesecondarynode->children) > 0) { From 6e672c0a825a51a7775a2993df94b49ddbeb326d Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Wed, 14 Sep 2022 23:28:08 +0200 Subject: [PATCH 2/2] MDL-75714 navigation: Cover a couple of situations with behat - Guest user attempting to access to single-activity course. - Not enrolled user attempt to access to single-activity course. Both should, by default, land to the "cannot access/enrol" page. --- .../tests/behat/activity_navigation.feature | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/course/format/singleactivity/tests/behat/activity_navigation.feature b/course/format/singleactivity/tests/behat/activity_navigation.feature index 7d3aed1dcff..6849f7e0a9c 100644 --- a/course/format/singleactivity/tests/behat/activity_navigation.feature +++ b/course/format/singleactivity/tests/behat/activity_navigation.feature @@ -9,6 +9,7 @@ Feature: Activity navigation in a single activity course | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@example.com | | student1 | Student | 1 | student1@example.com | + | student2 | Student | 2 | student2@example.com | And the following "courses" exist: | fullname | shortname | format | activitytype | | Course 1 | C1 | singleactivity | forum | @@ -65,3 +66,13 @@ Feature: Activity navigation in a single activity course Then "#prev-activity-link" "css_element" should not exist And "#next-activity-link" "css_element" should not exist And "Jump to..." "field" should not exist + + Scenario: The activity navigation asks for login to guest user + Given I log in as "guest" + When I am on "Course 1" course homepage + Then I should see "Guests cannot access this course. Please log in" + + Scenario: The activity navigation asks for login to not enrolled user + Given I log in as "student2" + When I am on "Course 1" course homepage + Then I should see "You cannot enrol yourself in this course"