diff --git a/admin/category.php b/admin/category.php index b203497bfeb..b0a682eb5a3 100644 --- a/admin/category.php +++ b/admin/category.php @@ -75,7 +75,7 @@ if ($PAGE->user_allowed_editing() && $adminediting != -1) { $USER->editing = $adminediting; } $buttons = null; -if ($PAGE->user_allowed_editing()) { +if ($PAGE->user_allowed_editing() && !$PAGE->theme->haseditswitch) { $url = clone($PAGE->url); if ($PAGE->user_is_editing()) { $caption = get_string('blockseditoff'); diff --git a/admin/settings.php b/admin/settings.php index 24b90244dc9..a3d48fc48c9 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -101,7 +101,7 @@ if (empty($SITE->fullname)) { echo $OUTPUT->render_from_template('core_admin/settings', $context); } else { - if ($PAGE->user_allowed_editing()) { + if ($PAGE->user_allowed_editing() && !$PAGE->theme->haseditswitch) { $url = clone($PAGE->url); if ($PAGE->user_is_editing()) { $caption = get_string('blockseditoff'); diff --git a/admin/tool/availabilityconditions/tests/behat/manage_conditions.feature b/admin/tool/availabilityconditions/tests/behat/manage_conditions.feature index 8fef761c017..4185bb1e341 100644 --- a/admin/tool/availabilityconditions/tests/behat/manage_conditions.feature +++ b/admin/tool/availabilityconditions/tests/behat/manage_conditions.feature @@ -8,7 +8,7 @@ Feature: Manage availability conditions Scenario: Display list of availability conditions # Check the report doesn't show when not enabled. Given I log in as "admin" - And I press "Customise this page" + And I turn editing mode on And I add the "Administration" block if not present And the following config values are set as admin: | enableavailability | 0 | diff --git a/admin/tool/behat/tests/behat/data_generators.feature b/admin/tool/behat/tests/behat/data_generators.feature index 69e536051dc..06f9c0baec1 100644 --- a/admin/tool/behat/tests/behat/data_generators.feature +++ b/admin/tool/behat/tests/behat/data_generators.feature @@ -139,19 +139,19 @@ Feature: Set up contextual data for tests | user5 | custom2 | System | | When I log in as "user1" And I am on site homepage - Then "Edit settings" "link" should exist in current page administration + Then I should see "Edit mode" And I log out And I log in as "user2" And I am on "Course 1" course homepage - And "Turn editing on" "button" should exist + Then I should see "Edit mode" And I log out And I log in as "user3" And I am on "Course 1" course homepage - And "Turn editing on" "button" should exist + Then I should see "Edit mode" And I log out And I log in as "user4" And I am on "Course 1" course homepage - And "Turn editing on" "button" should exist + Then I should see "Edit mode" And I log out And I log in as "user5" And I should see "You are logged in as" diff --git a/admin/tool/oauth2/tests/behat/basic_settings.feature b/admin/tool/oauth2/tests/behat/basic_settings.feature index d2c402c436c..311c84a3e86 100644 --- a/admin/tool/oauth2/tests/behat/basic_settings.feature +++ b/admin/tool/oauth2/tests/behat/basic_settings.feature @@ -6,6 +6,7 @@ Feature: Basic OAuth2 functionality Background: Given I log in as "admin" + And I change window size to "large" And I navigate to "Server > OAuth 2 services" in site administration Scenario: Create, edit and delete standard service for Google diff --git a/badges/tests/behat/add_badge.feature b/badges/tests/behat/add_badge.feature index 82d5c3b1ff9..4c36aff639f 100644 --- a/badges/tests/behat/add_badge.feature +++ b/badges/tests/behat/add_badge.feature @@ -10,7 +10,7 @@ Feature: Add badges to the system @javascript Scenario: Accessing the badges - And I press "Customise this page" + And I turn editing mode on # TODO MDL-57120 site "Badges" link not accessible without navigation block. And I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" @@ -133,7 +133,7 @@ Feature: Add badges to the system @javascript @_file_upload Scenario: Add a badge from Site badges section - Given I press "Customise this page" + Given I turn editing mode on # TODO MDL-57120 site "Badges" link not accessible without navigation block. And I add the "Navigation" block if not present When I click on "Site pages" "list_item" in the "Navigation" "block" diff --git a/badges/tests/behat/award_badge.feature b/badges/tests/behat/award_badge.feature index 9d5c590f713..60158d60192 100644 --- a/badges/tests/behat/award_badge.feature +++ b/badges/tests/behat/award_badge.feature @@ -83,7 +83,7 @@ Feature: Award badges And I should see "Add a new badge" # Teacher 1 should NOT have access to manage/create site badges in the Site badges section. When I am on homepage - And I press "Customise this page" + And I turn editing mode on # TODO MDL-57120 site "Badges" link not accessible without navigation block. And I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" diff --git a/blocks/activity_modules/tests/behat/block_activity_modules.feature b/blocks/activity_modules/tests/behat/block_activity_modules.feature index 63e6dba5d76..9a606bd8a50 100644 --- a/blocks/activity_modules/tests/behat/block_activity_modules.feature +++ b/blocks/activity_modules/tests/behat/block_activity_modules.feature @@ -31,7 +31,7 @@ Feature: Block activity modules When I log in as "admin" And I am on site homepage - And I follow "Turn editing on" + And I turn editing mode on And I add the "Activities" block And I click on "Assignments" "link" in the "Activities" "block" Then I should see "Frontpage assignment name" diff --git a/blocks/activity_results/tests/behat/addblockinactivity.feature b/blocks/activity_results/tests/behat/addblockinactivity.feature index 3a4b42d432d..47a9d1207e9 100644 --- a/blocks/activity_results/tests/behat/addblockinactivity.feature +++ b/blocks/activity_results/tests/behat/addblockinactivity.feature @@ -36,7 +36,6 @@ Feature: The activity results block displays student scores And I am on "Course 1" course homepage with editing mode on And I should see "Test page name" And I navigate to "View > Grader report" in the course gradebook - And I turn editing mode on And I give the grade "90.00" to the user "Student 1" for the grade item "Test assignment 1" And I give the grade "80.00" to the user "Student 2" for the grade item "Test assignment 1" And I give the grade "70.00" to the user "Student 3" for the grade item "Test assignment 1" diff --git a/blocks/activity_results/tests/behat/highscoreswithoutgroups.feature b/blocks/activity_results/tests/behat/highscoreswithoutgroups.feature index 6af65257a1a..b19dbeecc39 100644 --- a/blocks/activity_results/tests/behat/highscoreswithoutgroups.feature +++ b/blocks/activity_results/tests/behat/highscoreswithoutgroups.feature @@ -30,7 +30,6 @@ Feature: The activity results block displays student high scores And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on And I navigate to "View > Grader report" in the course gradebook - And I turn editing mode on And I give the grade "90.00" to the user "Student 1" for the grade item "Test assignment" And I give the grade "80.00" to the user "Student 2" for the grade item "Test assignment" And I give the grade "70.00" to the user "Student 3" for the grade item "Test assignment" diff --git a/blocks/activity_results/tests/behat/highscoreswithscalesandgroups.feature b/blocks/activity_results/tests/behat/highscoreswithscalesandgroups.feature index 3f221f1089f..88acb700f75 100644 --- a/blocks/activity_results/tests/behat/highscoreswithscalesandgroups.feature +++ b/blocks/activity_results/tests/behat/highscoreswithscalesandgroups.feature @@ -63,7 +63,6 @@ Feature: The activity results block displays student in group high scores as sca And I press "Save and return to course" And I am on "Course 1" course homepage And I navigate to "View > Grader report" in the course gradebook - And I turn editing mode on And I give the grade "Excellent!" to the user "Student 1" for the grade item "Test assignment" And I give the grade "Very good" to the user "Student 2" for the grade item "Test assignment" And I give the grade "Very good" to the user "Student 3" for the grade item "Test assignment" diff --git a/blocks/activity_results/tests/behat/highscoreswithseperategroups.feature b/blocks/activity_results/tests/behat/highscoreswithseperategroups.feature index 1b8953be518..251576d5462 100644 --- a/blocks/activity_results/tests/behat/highscoreswithseperategroups.feature +++ b/blocks/activity_results/tests/behat/highscoreswithseperategroups.feature @@ -53,7 +53,6 @@ Feature: The activity results block displays student in separate groups scores And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on And I navigate to "View > Grader report" in the course gradebook - And I turn editing mode on And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment" And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment" And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment" diff --git a/blocks/activity_results/tests/behat/lowscoreswithoutgroups.feature b/blocks/activity_results/tests/behat/lowscoreswithoutgroups.feature index 1c0577d61e9..6188e511b8b 100644 --- a/blocks/activity_results/tests/behat/lowscoreswithoutgroups.feature +++ b/blocks/activity_results/tests/behat/lowscoreswithoutgroups.feature @@ -35,7 +35,6 @@ Feature: The activity results block displays student low scores And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on And I navigate to "View > Grader report" in the course gradebook - And I turn editing mode on And I give the grade "90.00" to the user "Student 1" for the grade item "Test assignment" And I give the grade "80.00" to the user "Student 2" for the grade item "Test assignment" And I give the grade "70.00" to the user "Student 3" for the grade item "Test assignment" diff --git a/blocks/activity_results/tests/behat/lowscoreswithscales.feature b/blocks/activity_results/tests/behat/lowscoreswithscales.feature index 59b3623cc79..62e6238046e 100644 --- a/blocks/activity_results/tests/behat/lowscoreswithscales.feature +++ b/blocks/activity_results/tests/behat/lowscoreswithscales.feature @@ -49,7 +49,6 @@ Feature: The activity results block displays student low scores as scales And I press "Save and return to course" And I am on "Course 1" course homepage And I navigate to "View > Grader report" in the course gradebook - And I turn editing mode on And I give the grade "Excellent!" to the user "Student 1" for the grade item "Test assignment" And I give the grade "Very good" to the user "Student 2" for the grade item "Test assignment" And I give the grade "Good" to the user "Student 3" for the grade item "Test assignment" diff --git a/blocks/activity_results/tests/behat/lowscoreswithscalesandgroups.feature b/blocks/activity_results/tests/behat/lowscoreswithscalesandgroups.feature index ee08e782767..345164b6489 100644 --- a/blocks/activity_results/tests/behat/lowscoreswithscalesandgroups.feature +++ b/blocks/activity_results/tests/behat/lowscoreswithscalesandgroups.feature @@ -74,7 +74,7 @@ Feature: The activity results block displays students in groups low scores as sc And I give the grade "Good" to the user "Student 5" for the grade item "Test assignment" And I give the grade "Average" to the user "Student 6" for the grade item "Test assignment" And I press "Save changes" - And I am on "Course 1" course homepage with editing mode on + And I am on "Course 1" course homepage Scenario: Try to configure the block on the course page to show 1 low score Given I add the "Activity results" block diff --git a/blocks/activity_results/tests/behat/lowscoreswithseperategroups.feature b/blocks/activity_results/tests/behat/lowscoreswithseperategroups.feature index eadf2e9b0d9..523681e74b9 100644 --- a/blocks/activity_results/tests/behat/lowscoreswithseperategroups.feature +++ b/blocks/activity_results/tests/behat/lowscoreswithseperategroups.feature @@ -47,7 +47,6 @@ Feature: The activity results block displays students in separate groups scores And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on And I navigate to "View > Grader report" in the course gradebook - And I turn editing mode on And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment" And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment" And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment" diff --git a/blocks/activity_results/tests/behat/lowscoreswithvisiblegroups.feature b/blocks/activity_results/tests/behat/lowscoreswithvisiblegroups.feature index 13ed3f897fb..29d7a29e9bb 100644 --- a/blocks/activity_results/tests/behat/lowscoreswithvisiblegroups.feature +++ b/blocks/activity_results/tests/behat/lowscoreswithvisiblegroups.feature @@ -53,7 +53,6 @@ Feature: The activity results block displays student in visible groups low score And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on And I navigate to "View > Grader report" in the course gradebook - And I turn editing mode on And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment" And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment" And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment" diff --git a/blocks/badges/tests/behat/block_badges_frontpage.feature b/blocks/badges/tests/behat/block_badges_frontpage.feature index 388f4a30eb9..3a030b79bd4 100644 --- a/blocks/badges/tests/behat/block_badges_frontpage.feature +++ b/blocks/badges/tests/behat/block_badges_frontpage.feature @@ -16,7 +16,7 @@ Feature: Enable Block Badges on the frontpage and view awarded badges | teacher1 | C1 | editingteacher | And I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Latest badges" block And I log out And I log in as "teacher1" diff --git a/blocks/blog_menu/tests/behat/block_blog_menu_frontpage.feature b/blocks/blog_menu/tests/behat/block_blog_menu_frontpage.feature index 8e1df8263f3..f20b2e5c17f 100644 --- a/blocks/blog_menu/tests/behat/block_blog_menu_frontpage.feature +++ b/blocks/blog_menu/tests/behat/block_blog_menu_frontpage.feature @@ -10,7 +10,7 @@ Feature: Enable Block blog menu on the frontpage | student1 | Student | 1 | student1@example.com | S1 | And I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Blog menu" block And I log out diff --git a/blocks/blog_recent/tests/behat/block_blog_recent_frontpage.feature b/blocks/blog_recent/tests/behat/block_blog_recent_frontpage.feature index 38640424a0b..e7403cd513b 100644 --- a/blocks/blog_recent/tests/behat/block_blog_recent_frontpage.feature +++ b/blocks/blog_recent/tests/behat/block_blog_recent_frontpage.feature @@ -10,7 +10,7 @@ Feature: Feature: Students can use the recent blog entries block to view recent | student1 | Student | 1 | student1@example.com | S1 | And I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Recent blog entries" block # TODO MDL-57120 site "Blogs" link not accessible without navigation block. And I add the "Navigation" block if not present @@ -89,7 +89,7 @@ Feature: Feature: Students can use the recent blog entries block to view recent Then I log out And I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I configure the "Recent blog entries" block And I set the following fields to these values: | id_config_numberofrecentblogentries | 2 | diff --git a/blocks/calendar_upcoming/tests/behat/block_calendar_upcoming_frontpage.feature b/blocks/calendar_upcoming/tests/behat/block_calendar_upcoming_frontpage.feature index 8336f521fba..b2d956011d1 100644 --- a/blocks/calendar_upcoming/tests/behat/block_calendar_upcoming_frontpage.feature +++ b/blocks/calendar_upcoming/tests/behat/block_calendar_upcoming_frontpage.feature @@ -16,7 +16,7 @@ Feature: View a site event on the frontpage | id_eventtype | Site | | id_name | My Site Event | And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Upcoming events" block And I log out When I log in as "teacher1" diff --git a/blocks/comments/tests/behat/block_comment_dashboard.feature b/blocks/comments/tests/behat/block_comment_dashboard.feature index 66e49c6e9db..fcb19e7c827 100644 --- a/blocks/comments/tests/behat/block_comment_dashboard.feature +++ b/blocks/comments/tests/behat/block_comment_dashboard.feature @@ -14,7 +14,7 @@ Feature: Enable Block comments on the dashboard and view comments Scenario: Add the comments block on the dashboard and add comments with Javascript disabled When I log in as "teacher1" - And I press "Customise this page" + And I turn editing mode on And I add the "Comments" block And I follow "Show comments" And I add "I'm a comment from the teacher" comment to comments block @@ -23,7 +23,7 @@ Feature: Enable Block comments on the dashboard and view comments @javascript Scenario: Add the comments block on the dashboard and add comments with Javascript enabled When I log in as "teacher1" - And I press "Customise this page" + And I turn editing mode on And I add the "Comments" block And I add "I'm a comment from the teacher" comment to comments block Then I should see "I'm a comment from the teacher" diff --git a/blocks/comments/tests/behat/block_comment_frontpage.feature b/blocks/comments/tests/behat/block_comment_frontpage.feature index 6b883f2cad4..cb8d76dd036 100644 --- a/blocks/comments/tests/behat/block_comment_frontpage.feature +++ b/blocks/comments/tests/behat/block_comment_frontpage.feature @@ -10,7 +10,7 @@ Feature: Enable Block comments on the frontpage and view comments | teacher1 | Teacher | 1 | teacher1@example.com | T1 | And I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Comments" block And I follow "Show comments" And I add "I'm a comment from admin" comment to comments block diff --git a/blocks/course_list/tests/behat/block_course_list_dashboard.feature b/blocks/course_list/tests/behat/block_course_list_dashboard.feature index 873208b477d..2b5df28cbeb 100644 --- a/blocks/course_list/tests/behat/block_course_list_dashboard.feature +++ b/blocks/course_list/tests/behat/block_course_list_dashboard.feature @@ -27,7 +27,7 @@ Feature: Enable the course_list block on the dashboard and view it's contents Scenario: Add the course list block on the dashboard and navigate to the course listing Given I log in as "teacher1" - And I press "Customise this page" + And I turn editing mode on When I add the "Courses" block Then I should see "Course 1" in the "My courses" "block" And I should see "Course 2" in the "My courses" "block" @@ -38,7 +38,7 @@ Feature: Enable the course_list block on the dashboard and view it's contents Scenario: Add the course list block on the dashboard and navigate to another course Given I log in as "teacher1" - And I press "Customise this page" + And I turn editing mode on When I add the "Courses" block Then I should see "Course 1" in the "My courses" "block" And I should see "Course 2" in the "My courses" "block" @@ -49,7 +49,7 @@ Feature: Enable the course_list block on the dashboard and view it's contents Scenario: Add the course list block on the dashboard and view as an admin Given I log in as "admin" - And I press "Customise this page" + And I turn editing mode on When I add the "Courses" block Then I should see "Category 1" in the "Course categories" "block" And I should see "Category A" in the "Course categories" "block" 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 0a897ba84b9..0f8b0c5845c 100644 --- a/blocks/course_list/tests/behat/block_course_list_frontpage.feature +++ b/blocks/course_list/tests/behat/block_course_list_frontpage.feature @@ -28,7 +28,7 @@ Feature: Enable the course_list block on the frontpage and view it's contents Scenario: Add the course list block on the frontpage and navigate to the course listing Given I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Courses" block And I log out When I log in as "teacher1" @@ -43,7 +43,7 @@ Feature: Enable the course_list block on the frontpage and view it's contents Scenario: Add the course list block on the frontpage page and navigate to another course Given I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Courses" block And I log out When I log in as "teacher1" @@ -58,7 +58,7 @@ Feature: Enable the course_list block on the frontpage and view it's contents Scenario: Add the course list block on the frontpage page and view as an admin Given I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on When I add the "Courses" block Then I should see "Category 1" in the "Course categories" "block" And I should see "Category A" in the "Course categories" "block" @@ -72,7 +72,7 @@ Feature: Enable the course_list block on the frontpage and view it's contents Scenario: Add the course list block on the frontpage page and view as a guest Given I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Courses" block And I log out When I log in as "guest" diff --git a/blocks/login/tests/behat/login_block.feature b/blocks/login/tests/behat/login_block.feature index 2f86023f056..b06547a5ccf 100644 --- a/blocks/login/tests/behat/login_block.feature +++ b/blocks/login/tests/behat/login_block.feature @@ -10,7 +10,7 @@ Feature: Login from a block | testuser | testpass | Test | User | student1@example.com | And I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Login" block Scenario: Login block visible to non-logged in users diff --git a/blocks/myprofile/tests/behat/block_myprofile.feature b/blocks/myprofile/tests/behat/block_myprofile.feature index 8801de340d9..d95de68c082 100644 --- a/blocks/myprofile/tests/behat/block_myprofile.feature +++ b/blocks/myprofile/tests/behat/block_myprofile.feature @@ -9,7 +9,7 @@ Feature: The logged in user block allows users to view their profile information | username | firstname | lastname | email | country | | teacher1 | Teacher | One | teacher1@example.com | AU | And I log in as "teacher1" - And I press "Customise this page" + And I turn editing mode on When I add the "Logged in user" block And I configure the "Logged in user" block And I set the following fields to these values: @@ -28,7 +28,7 @@ Feature: The logged in user block allows users to view their profile information | username | firstname | lastname | email | city | | teacher1 | Teacher | One | teacher1@example.com | Perth | And I log in as "teacher1" - And I press "Customise this page" + And I turn editing mode on When I add the "Logged in user" block And I configure the "Logged in user" block And I set the following fields to these values: @@ -47,7 +47,7 @@ Feature: The logged in user block allows users to view their profile information | username | firstname | lastname | email | | teacher1 | Teacher | One | teacher1@example.com | And I log in as "teacher1" - And I press "Customise this page" + And I turn editing mode on When I add the "Logged in user" block And I configure the "Logged in user" block And I set the following fields to these values: @@ -66,7 +66,7 @@ Feature: The logged in user block allows users to view their profile information | username | firstname | lastname | email | phone1 | | teacher1 | Teacher | One | teacher1@example.com | 555-5555 | And I log in as "teacher1" - And I press "Customise this page" + And I turn editing mode on When I add the "Logged in user" block And I configure the "Logged in user" block And I set the following fields to these values: @@ -85,7 +85,7 @@ Feature: The logged in user block allows users to view their profile information | username | firstname | lastname | email | phone2 | | teacher1 | Teacher | One | teacher1@example.com | 555-5555 | And I log in as "teacher1" - And I press "Customise this page" + And I turn editing mode on When I add the "Logged in user" block And I configure the "Logged in user" block And I set the following fields to these values: @@ -104,7 +104,7 @@ Feature: The logged in user block allows users to view their profile information | username | firstname | lastname | email | institution | | teacher1 | Teacher | One | teacher1@example.com | myinstitution | And I log in as "teacher1" - And I press "Customise this page" + And I turn editing mode on When I add the "Logged in user" block And I configure the "Logged in user" block And I set the following fields to these values: @@ -123,7 +123,7 @@ Feature: The logged in user block allows users to view their profile information | username | firstname | lastname | email | address | | teacher1 | Teacher | One | teacher1@example.com | myaddress | And I log in as "teacher1" - And I press "Customise this page" + And I turn editing mode on When I add the "Logged in user" block And I configure the "Logged in user" block And I set the following fields to these values: @@ -142,7 +142,7 @@ Feature: The logged in user block allows users to view their profile information | username | firstname | lastname | email | | teacher1 | Teacher | One | teacher1@example.com | And I log in as "teacher1" - And I press "Customise this page" + And I turn editing mode on When I add the "Logged in user" block And I configure the "Logged in user" block And I set the following fields to these values: @@ -161,7 +161,7 @@ Feature: The logged in user block allows users to view their profile information | username | firstname | lastname | email | | teacher1 | Teacher | One | teacher1@example.com | And I log in as "teacher1" - And I press "Customise this page" + And I turn editing mode on When I add the "Logged in user" block And I configure the "Logged in user" block And I set the following fields to these values: @@ -180,7 +180,7 @@ Feature: The logged in user block allows users to view their profile information | username | firstname | lastname | email | | teacher1 | Teacher | One | teacher1@example.com | And I log in as "teacher1" - And I press "Customise this page" + And I turn editing mode on When I add the "Logged in user" block And I configure the "Logged in user" block And I set the following fields to these values: @@ -199,7 +199,7 @@ Feature: The logged in user block allows users to view their profile information | username | firstname | lastname | email | | teacher1 | Teacher | One | teacher1@example.com | And I log in as "teacher1" - And I press "Customise this page" + And I turn editing mode on When I add the "Logged in user" block And I configure the "Logged in user" block And I set the following fields to these values: diff --git a/blocks/myprofile/tests/behat/block_myprofile_dashboard.feature b/blocks/myprofile/tests/behat/block_myprofile_dashboard.feature index e1305226ce1..da323581aa2 100644 --- a/blocks/myprofile/tests/behat/block_myprofile_dashboard.feature +++ b/blocks/myprofile/tests/behat/block_myprofile_dashboard.feature @@ -9,6 +9,6 @@ Feature: The logged in user block allows users to view their profile information | username | firstname | lastname | email | | teacher1 | Teacher | One | teacher1@example.com | And I log in as "teacher1" - And I press "Customise this page" + And I turn editing mode on When I add the "Logged in user" block Then I should see "Teacher One" in the "Logged in user" "block" diff --git a/blocks/myprofile/tests/behat/block_myprofile_frontpage.feature b/blocks/myprofile/tests/behat/block_myprofile_frontpage.feature index 1e6707848d6..c7d5e37a071 100644 --- a/blocks/myprofile/tests/behat/block_myprofile_frontpage.feature +++ b/blocks/myprofile/tests/behat/block_myprofile_frontpage.feature @@ -10,7 +10,7 @@ Feature: The logged in user block allows users to view their profile information | teacher1 | Teacher | One | teacher1@example.com | T1 | And I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Logged in user" block And I log out diff --git a/blocks/online_users/tests/behat/block_online_users_frontpage.feature b/blocks/online_users/tests/behat/block_online_users_frontpage.feature index e8f9591f6d7..5da03deadab 100644 --- a/blocks/online_users/tests/behat/block_online_users_frontpage.feature +++ b/blocks/online_users/tests/behat/block_online_users_frontpage.feature @@ -21,7 +21,7 @@ Feature: The online users block allow you to see who is currently online on fron Scenario: View the online users block on the front page and see myself Given I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on When I add the "Online users" block Then I should see "Admin User" in the "Online users" "block" And I should see "1 online user" in the "Online users" "block" @@ -29,7 +29,7 @@ Feature: The online users block allow you to see who is currently online on fron Scenario: View the online users block on the front page as a logged in user Given I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Online users" block And I log out And I log in as "student2" @@ -45,7 +45,7 @@ Feature: The online users block allow you to see who is currently online on fron Scenario: View the online users block on the front page as a guest Given I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Online users" block And I log out And I log in as "student2" @@ -65,7 +65,7 @@ Feature: The online users block allow you to see who is currently online on fron | block_online_users_onlinestatushiding | 1 | And I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Online users" block And I log out When I log in as "student1" @@ -104,7 +104,7 @@ Feature: The online users block allow you to see who is currently online on fron | block_online_users_onlinestatushiding | 1 | And I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Online users" block And I log out And I log in as "student1" @@ -125,7 +125,7 @@ Feature: The online users block allow you to see who is currently online on fron | block_online_users_onlinestatushiding | 1 | And I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Online users" block And I log out And I log in as "student1" diff --git a/blocks/private_files/tests/behat/block_private_files_frontpage.feature b/blocks/private_files/tests/behat/block_private_files_frontpage.feature index 0e79d0a911a..cd3ef3b1665 100644 --- a/blocks/private_files/tests/behat/block_private_files_frontpage.feature +++ b/blocks/private_files/tests/behat/block_private_files_frontpage.feature @@ -13,7 +13,7 @@ Feature: The private files block allows users to store files privately in moodle | teacher1 | Teacher | 1 | teacher1@example.com | And I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Private files" block And I log out diff --git a/blocks/recentlyaccesseditems/tests/behat/block_recentlyaccesseditems_dashboard.feature b/blocks/recentlyaccesseditems/tests/behat/block_recentlyaccesseditems_dashboard.feature index f635459c7ae..5d1f562177e 100644 --- a/blocks/recentlyaccesseditems/tests/behat/block_recentlyaccesseditems_dashboard.feature +++ b/blocks/recentlyaccesseditems/tests/behat/block_recentlyaccesseditems_dashboard.feature @@ -22,7 +22,7 @@ Feature: The recently accessed items block allows users to easily access their m | idnumber | Test forum name | | name | Test forum name | And I log in as "student1" - And I press "Customise this page" + And I turn editing mode on And I add the "Recently accessed items" block Scenario: User has not accessed any item diff --git a/blocks/search_forums/tests/behat/block_search_forums_frontpage.feature b/blocks/search_forums/tests/behat/block_search_forums_frontpage.feature index 31d868376cd..53d09348b57 100644 --- a/blocks/search_forums/tests/behat/block_search_forums_frontpage.feature +++ b/blocks/search_forums/tests/behat/block_search_forums_frontpage.feature @@ -10,7 +10,7 @@ Feature: The search forums block allows users to search for forum posts on front | student1 | Student | 1 | student1@example.com | S1 | And I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Search forums" block And I log out diff --git a/blocks/site_main_menu/tests/behat/add_url.feature b/blocks/site_main_menu/tests/behat/add_url.feature index 1b2a7df7682..f5ce28b6471 100644 --- a/blocks/site_main_menu/tests/behat/add_url.feature +++ b/blocks/site_main_menu/tests/behat/add_url.feature @@ -8,7 +8,7 @@ Feature: Add URL to main menu block Scenario: Add a URL in menu block and ensure it appears Given I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + 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 | diff --git a/blocks/site_main_menu/tests/behat/edit_activities.feature b/blocks/site_main_menu/tests/behat/edit_activities.feature index e8aa3315c9a..78701455da5 100644 --- a/blocks/site_main_menu/tests/behat/edit_activities.feature +++ b/blocks/site_main_menu/tests/behat/edit_activities.feature @@ -13,7 +13,7 @@ Feature: Edit activities in main menu block | idnumber | forum | And I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Main menu" block When I set the field "Edit title" in the "My forum name" "block_site_main_menu > Activity" to "New forum name" Then I should not see "My forum name" @@ -28,7 +28,7 @@ Feature: Edit activities in main menu block | allowstealth | 1 | And I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Main menu" block When I add a "Forum" to section "0" and I fill the form with: | Forum name | Visible forum | @@ -61,7 +61,7 @@ Feature: Edit activities in main menu block And the field "Availability" matches value "Make available but not shown on course page" And I press "Save and return to course" And "My forum name" activity in site main menu block should be available but hidden from course page - And I navigate to "Turn editing off" in current page administration + And I turn editing mode off And "My forum name" activity in site main menu block should be available but hidden from course page And I log out And I should not see "My forum name" in the "Main menu" "block" diff --git a/blocks/tag_flickr/tests/behat/configuring_tag_flickr_block.feature b/blocks/tag_flickr/tests/behat/configuring_tag_flickr_block.feature index c9278270013..c6670012b9b 100644 --- a/blocks/tag_flickr/tests/behat/configuring_tag_flickr_block.feature +++ b/blocks/tag_flickr/tests/behat/configuring_tag_flickr_block.feature @@ -7,7 +7,7 @@ Feature: Adding and configuring Flickr block @javascript Scenario: Adding Flickr block to the tags site page Given I log in as "admin" - And I press "Customise this page" + And I turn editing mode on # TODO MDL-57120 site "Tags" link not accessible without navigation block. And I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" diff --git a/blocks/tag_youtube/tests/behat/configure_tag_youtube_block.feature b/blocks/tag_youtube/tests/behat/configure_tag_youtube_block.feature index 6952b95b160..4da87fe05f2 100644 --- a/blocks/tag_youtube/tests/behat/configure_tag_youtube_block.feature +++ b/blocks/tag_youtube/tests/behat/configure_tag_youtube_block.feature @@ -14,7 +14,7 @@ Feature: Adding and configuring YouTube block Given the following config values are set as admin: | apikey | | block_tag_youtube | And I follow "Dashboard" in the user menu - And I press "Customise this page" + And I turn editing mode on # TODO MDL-57120 site "Tags" link not accessible without navigation block. And I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" @@ -34,7 +34,7 @@ Feature: Adding and configuring YouTube block Given the following config values are set as admin: | apikey | invalidapikeyvalue | block_tag_youtube | And I follow "Dashboard" in the user menu - And I press "Customise this page" + And I turn editing mode on And I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" And I click on "Tags" "link" in the "Navigation" "block" diff --git a/blocks/tags/tests/behat/tagcloud.feature b/blocks/tags/tests/behat/tagcloud.feature index 6a8bd414895..dbe47565bed 100644 --- a/blocks/tags/tests/behat/tagcloud.feature +++ b/blocks/tags/tests/behat/tagcloud.feature @@ -23,7 +23,7 @@ Feature: Block tags displaying tag cloud Scenario: Add Tags block on a front page When I log in as "admin" And I am on site homepage - And I follow "Turn editing on" + And I turn editing mode on And I add the "Tags" block And I log out And I am on site homepage diff --git a/blocks/tests/behat/configure_block_throughout_site.feature b/blocks/tests/behat/configure_block_throughout_site.feature index a312ce6d058..f633c84d570 100644 --- a/blocks/tests/behat/configure_block_throughout_site.feature +++ b/blocks/tests/behat/configure_block_throughout_site.feature @@ -30,7 +30,7 @@ Feature: Add and configure blocks throughout the site Scenario: Add and configure a block throughtout the site Given I log in as "manager1" And I am on site homepage - And I follow "Turn editing on" + And I turn editing mode on And I add the "Comments" block And I configure the "Comments" block And I set the following fields to these values: @@ -50,7 +50,7 @@ Feature: Add and configure blocks throughout the site Scenario: Blocks on the dashboard page can have roles assigned to them Given I log in as "manager1" - When I press "Customise this page" + When I turn editing mode on Then I should see "Assign roles in Private files block" Scenario: Blocks on courses can have roles assigned to them @@ -63,7 +63,7 @@ Feature: Add and configure blocks throughout the site Scenario: Blocks can safely be customised Given I log in as "admin" And I am on homepage - And I press "Customise this page" + And I turn editing mode on And I add the "Text" block And I configure the "(new text block)" block And I set the following fields to these values: diff --git a/blocks/tests/behat/hide_blocks.feature b/blocks/tests/behat/hide_blocks.feature index db11e3f529d..0a4f9fae911 100644 --- a/blocks/tests/behat/hide_blocks.feature +++ b/blocks/tests/behat/hide_blocks.feature @@ -23,5 +23,5 @@ Feature: Block visibility And I turn editing mode on And I open the "Search forums" blocks action menu And I click on "Hide Search forums block" "link" in the "Search forums" "block" - And I follow "Turn editing off" + And I turn editing mode off And ".empty-region-side-post" "css_element" should exist in the "body" "css_element" diff --git a/blocks/tests/behat/manage_blocks.feature b/blocks/tests/behat/manage_blocks.feature index 7af0a432a13..2f5b1fcefe1 100644 --- a/blocks/tests/behat/manage_blocks.feature +++ b/blocks/tests/behat/manage_blocks.feature @@ -48,7 +48,7 @@ Feature: Block appearances And I set the following fields to these values: | Display on page types | Any course page | And I press "Save changes" - And I press "Turn editing off" + And I turn editing mode off And I follow "Test survey name" And I should not see "Comments" @@ -58,5 +58,5 @@ Feature: Block appearances And I set the following fields to these values: | Visible | No | And I press "Save changes" - And I press "Turn editing off" + And I turn editing mode off Then I should not see "Comments" diff --git a/calendar/tests/behat/category_events.feature b/calendar/tests/behat/category_events.feature index 021126ad4fe..734c7acddc6 100644 --- a/calendar/tests/behat/category_events.feature +++ b/calendar/tests/behat/category_events.feature @@ -67,7 +67,7 @@ Feature: Course Category Events @javascript Scenario: Manager of a Category can see all child and parent events in their category Given I log in as "managera" - And I press "Customise this page" + And I turn editing mode on # TODO MDL-57120 site "Tags" link not accessible without navigation block. When I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" @@ -80,7 +80,7 @@ Feature: Course Category Events And I should not see "DB2 event" And I log out Given I log in as "managerb" - And I press "Customise this page" + And I turn editing mode on # TODO MDL-57120 site "Tags" link not accessible without navigation block. When I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" @@ -95,7 +95,7 @@ Feature: Course Category Events @javascript Scenario: Users enrolled in a course can see all child and parent events in their category Given I log in as "student1" - And I press "Customise this page" + And I turn editing mode on # TODO MDL-57120 site "Tags" link not accessible without navigation block. When I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" diff --git a/completion/tests/behat/activity_completion_criteria.feature b/completion/tests/behat/activity_completion_criteria.feature index 09f59fe42b2..fbab217b8d3 100644 --- a/completion/tests/behat/activity_completion_criteria.feature +++ b/completion/tests/behat/activity_completion_criteria.feature @@ -116,7 +116,7 @@ Feature: Allow to mark course as completed without cron for activity completion Given I log in as "teacher1" And I am on "Completion course" course homepage And I navigate to "View > Grader report" in the course gradebook - And I press "Turn editing on" + And I turn editing mode on And I give the grade "57" to the user "Student First" for the grade item "Test assignment name" And I press "Save changes" And I log out diff --git a/contentbank/contenttype/h5p/tests/behat/admin_replace_content.feature b/contentbank/contenttype/h5p/tests/behat/admin_replace_content.feature index c91828e0a4f..c34e19f0128 100644 --- a/contentbank/contenttype/h5p/tests/behat/admin_replace_content.feature +++ b/contentbank/contenttype/h5p/tests/behat/admin_replace_content.feature @@ -9,7 +9,7 @@ Feature: Replace H5P file from an existing content | contextlevel | reference | contenttype | user | contentname | filepath | | System | | contenttype_h5p | admin | filltheblanks.h5p | /h5p/tests/fixtures/filltheblanks.h5p | And I log in as "admin" - And I press "Customise this page" + And I turn editing mode on And I add the "Navigation" block if not present And I expand "Site pages" node And I click on "Content bank" "link" diff --git a/contentbank/contenttype/h5p/tests/behat/admin_upload_content.feature b/contentbank/contenttype/h5p/tests/behat/admin_upload_content.feature index 29959c58fe3..dbc596a9a15 100644 --- a/contentbank/contenttype/h5p/tests/behat/admin_upload_content.feature +++ b/contentbank/contenttype/h5p/tests/behat/admin_upload_content.feature @@ -9,7 +9,7 @@ Feature: H5P file upload to content bank for admins And I follow "Manage private files..." And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "Files" filemanager And I click on "Save changes" "button" - And I press "Customise this page" + And I turn editing mode on And I add the "Navigation" block if not present And I expand "Site pages" node And I click on "Content bank" "link" diff --git a/contentbank/contenttype/h5p/tests/behat/teacher_upload_content.feature b/contentbank/contenttype/h5p/tests/behat/teacher_upload_content.feature index 488fde877d5..1146a082656 100644 --- a/contentbank/contenttype/h5p/tests/behat/teacher_upload_content.feature +++ b/contentbank/contenttype/h5p/tests/behat/teacher_upload_content.feature @@ -25,7 +25,7 @@ Feature: H5P file upload to content bank for non admins And I click on "Save changes" "button" Scenario: Teachers can not access system level content bank - Given I press "Customise this page" + Given I turn editing mode on And I add the "Navigation" block if not present When I expand "Site pages" node Then I should not see "Content bank" diff --git a/course/tests/behat/activities_visibility_icons.feature b/course/tests/behat/activities_visibility_icons.feature index d26ae6716b8..f6269f67aa1 100644 --- a/course/tests/behat/activities_visibility_icons.feature +++ b/course/tests/behat/activities_visibility_icons.feature @@ -17,12 +17,15 @@ Feature: Toggle activities visibility from the course page | user | course | role | | teacher1 | C1 | editingteacher | | student1 | C1 | student | + And the following "activity" exists: + | activity | forum | + | course | C1 | + | idnumber | C1F1 | + | name | Test forum name | + | intro | Test forum description | + | visible | 1 | And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on - And I add a "Forum" to section "1" and I fill the form with: - | Forum name | Test forum name | - | Description | Test forum description | - | Availability | Show on course page | When I open "Test forum name" actions menu Then "Test forum name" actions menu should not have "Show" item And "Test forum name" actions menu should not have "Make available" item @@ -60,7 +63,6 @@ Feature: Toggle activities visibility from the course page And I log in as "student1" And I am on "Course 1" course homepage And I should not see "Test forum name" - And I log out @javascript Scenario: Activities can be made available and unavailable inside a hidden section @@ -75,13 +77,17 @@ Feature: Toggle activities visibility from the course page | user | course | role | | teacher1 | C1 | editingteacher | | student1 | C1 | student | + And the following "activity" exists: + | activity | forum | + | course | C1 | + | idnumber | C1F1 | + | section | 2 | + | name | Test forum name | + | intro | Test forum description | + | visible | 1 | And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on And I add the "Recent activity" block - And I add a "Forum" to section "2" and I fill the form with: - | Forum name | Test forum name | - | Description | Test forum description | - | Availability | Show on course page | When I hide section "2" Then "Test forum name" activity should be hidden And I open "Test forum name" actions menu @@ -116,7 +122,6 @@ Feature: Toggle activities visibility from the course page And I click on "Test forum name" "link" in the "Recent activity" "block" And I should see "Test forum name" And I should see "(There are no discussion topics yet in this forum)" - And I log out @javascript Scenario: Activities can be made available but not visible on a course page diff --git a/course/tests/behat/behat_course.php b/course/tests/behat/behat_course.php index a477f391041..bc3d23ba331 100644 --- a/course/tests/behat/behat_course.php +++ b/course/tests/behat/behat_course.php @@ -82,32 +82,6 @@ class behat_course extends behat_base { ]; } - /** - * Turns editing mode on. - * @Given /^I turn editing mode on$/ - */ - public function i_turn_editing_mode_on() { - - try { - $this->execute("behat_forms::press_button", get_string('turneditingon')); - } catch (Exception $e) { - $this->execute("behat_navigation::i_navigate_to_in_current_page_administration", [get_string('turneditingon')]); - } - } - - /** - * Turns editing mode off. - * @Given /^I turn editing mode off$/ - */ - public function i_turn_editing_mode_off() { - - try { - $this->execute("behat_forms::press_button", get_string('turneditingoff')); - } catch (Exception $e) { - $this->execute("behat_navigation::i_navigate_to_in_current_page_administration", [get_string('turneditingoff')]); - } - } - /** * Creates a new course with the provided table data matching course settings names with the desired values. * @@ -733,9 +707,7 @@ class behat_course extends behat_base { * @throws ExpectationException */ public function activity_should_be_hidden($activityname) { - if ($this->is_course_editor()) { - // The activity should exist. $activitynode = $this->get_activity_node($activityname); @@ -758,7 +730,6 @@ class behat_course extends behat_base { } } else { - // It should not exist at all. try { $this->get_activity_node($activityname); @@ -1310,15 +1281,13 @@ class behat_course extends behat_base { * * @return bool */ - protected function is_course_editor() { - - // We don't need to behat_base::spin() here as all is already loaded. - if (!$this->getSession()->getPage()->findButton(get_string('turneditingoff')) && - !$this->getSession()->getPage()->findButton(get_string('turneditingon'))) { + protected function is_course_editor(): bool { + try { + $this->find('field', get_string('editmode'), false, false, 0); + return true; + } catch (ElementNotFoundException $e) { return false; } - - return true; } /** @@ -1327,7 +1296,8 @@ class behat_course extends behat_base { * @return bool */ protected function is_editing_on() { - return $this->getSession()->getPage()->findButton(get_string('turneditingoff')) ? true : false; + $body = $this->find('xpath', "//body", false, false, 0); + return $body->hasClass('editing'); } /** diff --git a/course/tests/behat/coursetags.feature b/course/tests/behat/coursetags.feature index 73d3ec57860..a9e9c6b2285 100644 --- a/course/tests/behat/coursetags.feature +++ b/course/tests/behat/coursetags.feature @@ -47,7 +47,7 @@ Feature: Tagging courses And I press "Save and display" And I log out And I log in as "user1" - And I press "Customise this page" + And I turn editing mode on # TODO MDL-57120 "Tags" link not accessible without navigation block. And I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" @@ -84,7 +84,7 @@ Feature: Tagging courses And I press "Save changes" And I log out And I log in as "user1" - And I press "Customise this page" + And I turn editing mode on # TODO MDL-57120 "Tags" link not accessible without navigation block. And I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" diff --git a/course/tests/behat/frontpage_topic_section.feature b/course/tests/behat/frontpage_topic_section.feature index f2cf92cb4cd..5c9bbfb9385 100644 --- a/course/tests/behat/frontpage_topic_section.feature +++ b/course/tests/behat/frontpage_topic_section.feature @@ -23,23 +23,23 @@ Feature: Front page topic section | assign | Acceptance test site | 1 | Frontpage assignment | Assignment description | assign0 | And I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I click on "Edit summary" "link" in the "region-main" "region" And I click on "Custom" "checkbox" And I set the field "New value for Section name" to "New section name" When I press "Save changes" And I should see "New section name" in the "region-main" "region" - Then I navigate to "Turn editing off" in current page administration + Then I turn editing mode off And I should see "New section name" in the "region-main" "region" @javascript Scenario: Topic description appears in the frontpage Given I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I click on "Edit summary" "link" in the "region-main" "region" And I set the field "Summary" to "New section description" When I press "Save changes" And I should see "New section description" in the "region-main" "region" - Then I navigate to "Turn editing off" in current page administration + Then I turn editing mode off And I should see "New section description" in the "region-main" "region" diff --git a/editmode.php b/editmode.php new file mode 100644 index 00000000000..36c340d4f98 --- /dev/null +++ b/editmode.php @@ -0,0 +1,47 @@ +. + +/** + * Set Mode. + * + * @package core + * @copyright 2021 Andrew Lyons + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once('config.php'); + +$setmode = optional_param('setmode', false, PARAM_BOOL); +$contextid = required_param('context', PARAM_INT); +$pageurl = required_param('pageurl', PARAM_LOCALURL); + +require_sesskey(); +require_login(); + +$context = \context_helper::instance_by_id($contextid); +$PAGE->set_context($context); + +if ($context->id === \context_user::instance($USER->id)->id) { + $PAGE->set_blocks_editing_capability('moodle/my:manageblocks'); +} + +if ($PAGE->user_allowed_editing()) { + $USER->editing = $setmode; +} else { + \core\notification::add(get_string('cannotswitcheditmodeon', 'error'), \core\notification::ERROR); +} + +redirect($pageurl); diff --git a/grade/report/grader/index.php b/grade/report/grader/index.php index 63a3bd17c99..bbd74e3233c 100644 --- a/grade/report/grader/index.php +++ b/grade/report/grader/index.php @@ -81,27 +81,18 @@ if (!isset($USER->grade_last_report)) { $USER->grade_last_report[$course->id] = 'grader'; // Build editing on/off buttons - -if (!isset($USER->gradeediting)) { - $USER->gradeediting = array(); -} - +$buttons = ''; if (has_capability('moodle/grade:edit', $context)) { - if (!isset($USER->gradeediting[$course->id])) { - $USER->gradeediting[$course->id] = 0; - } - if (($edit == 1) and confirm_sesskey()) { - $USER->gradeediting[$course->id] = 1; - } else if (($edit == 0) and confirm_sesskey()) { - $USER->gradeediting[$course->id] = 0; + if (($edit != - 1) and $PAGE->user_allowed_editing()) { + $USER->editing = $edit; } // page params for the turn editting on $options = $gpr->get_options(); $options['sesskey'] = sesskey(); - if ($USER->gradeediting[$course->id]) { + if (isset($USER->editing) && $USER->editing) { $options['edit'] = 0; $string = get_string('turneditingoff'); } else { @@ -109,10 +100,9 @@ if (has_capability('moodle/grade:edit', $context)) { $string = get_string('turneditingon'); } - $buttons = new single_button(new moodle_url('index.php', $options), $string, 'get'); -} else { - $USER->gradeediting[$course->id] = 0; - $buttons = ''; + if (!$PAGE->theme->haseditswitch) { + $buttons = new single_button(new moodle_url('index.php', $options), $string, 'get'); + } } $gradeserror = array(); @@ -147,14 +137,14 @@ if ($report->currentgroup == -2) { exit; } -// processing posted grades & feedback here -if ($data = data_submitted() and confirm_sesskey() and has_capability('moodle/grade:edit', $context)) { +$warnings = []; +$isediting = has_capability('moodle/grade:edit', $context) && isset($USER->editing) && $USER->editing; +if ($isediting && ($data = data_submitted()) && confirm_sesskey()) { + // Processing posted grades & feedback here. $warnings = $report->process_data($data); -} else { - $warnings = array(); } -// final grades MUST be loaded after the processing +// Final grades MUST be loaded after the processing. $report->load_users(); $report->load_final_grades(); echo $report->group_selector; @@ -186,7 +176,7 @@ if ($numusers == 0) { $reporthtml = $report->get_grade_table($displayaverages); // print submit button -if ($USER->gradeediting[$course->id] && ($report->get_pref('showquickfeedback') || $report->get_pref('quickgrading'))) { +if (!empty($USER->editing) && ($report->get_pref('showquickfeedback') || $report->get_pref('quickgrading'))) { echo '
'; // Enforce compatibility with our max_input_vars hack. echo '
'; echo ''; diff --git a/grade/report/grader/lib.php b/grade/report/grader/lib.php index 57624309e60..6d6d0da151a 100644 --- a/grade/report/grader/lib.php +++ b/grade/report/grader/lib.php @@ -883,7 +883,7 @@ class grade_report_grader extends grade_report { $categorycell->scope = 'col'; // Print icons. - if ($USER->gradeediting[$this->courseid]) { + if (!empty($USER->editing)) { $categorycell->text .= $this->get_icons($element); } @@ -1068,7 +1068,7 @@ class grade_report_grader extends grade_report { } // Do not show any icons if no grade (no record in DB to match) - if (!$item->needsupdate and $USER->gradeediting[$this->courseid]) { + if (!$item->needsupdate and !empty($USER->editing)) { $itemcell->text .= $this->get_icons($element); } @@ -1093,7 +1093,7 @@ class grade_report_grader extends grade_report { if ($item->needsupdate) { $itemcell->text .= "" . $strerror . ""; - } else if ($USER->gradeediting[$this->courseid]) { + } else if (!empty($USER->editing)) { if ($item->scaleid && !empty($scalesarray[$item->scaleid])) { $itemcell->attributes['class'] .= ' grade_type_scale'; @@ -1233,7 +1233,7 @@ class grade_report_grader extends grade_report { // Student grades and feedback are already at $jsarguments['feedback'] and $jsarguments['grades'] } - $jsarguments['cfg']['isediting'] = (bool)$USER->gradeediting[$this->courseid]; + $jsarguments['cfg']['isediting'] = !empty($USER->editing); $jsarguments['cfg']['courseid'] = $this->courseid; $jsarguments['cfg']['studentsperpage'] = $this->get_students_per_page(); $jsarguments['cfg']['showquickfeedback'] = (bool) $showquickfeedback; @@ -1246,7 +1246,7 @@ class grade_report_grader extends grade_report { $PAGE->requires->js_init_call('M.gradereport_grader.init_report', $jsarguments, false, $module); $PAGE->requires->strings_for_js(array('addfeedback', 'feedback', 'grade'), 'grades'); $PAGE->requires->strings_for_js(array('ajaxchoosescale', 'ajaxclicktoclose', 'ajaxerror', 'ajaxfailedupdate', 'ajaxfieldchanged'), 'gradereport_grader'); - if (!$enableajax && $USER->gradeediting[$this->courseid]) { + if (!$enableajax && !empty($USER->editing)) { $PAGE->requires->js_call_amd('core_form/changechecker', 'watchFormById', ['gradereport_grader']); } @@ -1298,7 +1298,7 @@ class grade_report_grader extends grade_report { public function get_left_icons_row($rows=array(), $colspan=1) { global $USER; - if ($USER->gradeediting[$this->courseid]) { + if (!empty($USER->editing)) { $controlsrow = new html_table_row(); $controlsrow->attributes['class'] = 'controls'; $controlscell = new html_table_cell(); @@ -1395,7 +1395,7 @@ class grade_report_grader extends grade_report { */ public function get_right_icons_row($rows=array()) { global $USER; - if ($USER->gradeediting[$this->courseid]) { + if (!empty($USER->editing)) { $iconsrow = new html_table_row(); $iconsrow->attributes['class'] = 'controls'; @@ -1575,7 +1575,7 @@ class grade_report_grader extends grade_report { } // Determine which display type to use for this average - if ($USER->gradeediting[$this->courseid]) { + if (!empty($USER->editing)) { $displaytype = GRADE_DISPLAY_TYPE_REAL; } else if ($averagesdisplaytype == GRADE_REPORT_PREFERENCE_INHERIT) { // no ==0 here, please resave the report and user preferences @@ -1685,7 +1685,7 @@ class grade_report_grader extends grade_report { protected function get_icons($element) { global $CFG, $USER, $OUTPUT; - if (!$USER->gradeediting[$this->courseid]) { + if (empty($USER->editing)) { return '
'; } @@ -1981,4 +1981,3 @@ class grade_report_grader extends grade_report { return $this->get_pref('studentsperpage'); } } - diff --git a/grade/report/grader/tests/behat/switch_views.feature b/grade/report/grader/tests/behat/switch_views.feature index 14eb04ccf8c..d4dd29a09b7 100644 --- a/grade/report/grader/tests/behat/switch_views.feature +++ b/grade/report/grader/tests/behat/switch_views.feature @@ -55,7 +55,7 @@ Feature: We can change what we are viewing on the grader report When I am on "Course 1" course homepage with editing mode on And I open "Test assignment name 2" actions menu And I click on "Hide" "link" in the "Test assignment name 2" activity - And I am on "Course 1" course homepage + And I am on "Course 1" course homepage with editing mode off And I navigate to "View > Grader report" in the course gradebook And I should see "Test assignment name 1" And I should see "Test assignment name 2" diff --git a/grade/report/user/lib.php b/grade/report/user/lib.php index 18f72be1ab9..fc03f1a17fc 100644 --- a/grade/report/user/lib.php +++ b/grade/report/user/lib.php @@ -1053,7 +1053,7 @@ class grade_report_user extends grade_report { } // Determine which display type to use for this average - if (!empty($USER->gradeediting) && $USER->gradeediting[$this->courseid]) { + if (isset($USER->editing) && $USER->editing) { $displaytype = GRADE_DISPLAY_TYPE_REAL; } else if ($averagesdisplaytype == GRADE_REPORT_PREFERENCE_INHERIT) { // no ==0 here, please resave the report and user preferences diff --git a/grade/tests/behat/grade_calculated_grade_items.feature b/grade/tests/behat/grade_calculated_grade_items.feature index e3cca8d185f..91f4870d922 100644 --- a/grade/tests/behat/grade_calculated_grade_items.feature +++ b/grade/tests/behat/grade_calculated_grade_items.feature @@ -65,7 +65,7 @@ Feature: Calculated grade items can be used in the gradebook And I set the following settings for grade item "Calc cat": | Maximum grade | 50 | And I navigate to "View > Grader report" in the course gradebook - And I press "Turn editing on" + And I turn editing mode on And I give the grade "75.00" to the user "Student 1" for the grade item "grade item 1" And I press "Save changes" And I navigate to "View > User report" in the course gradebook @@ -131,7 +131,7 @@ Feature: Calculated grade items can be used in the gradebook | Min and max grades used in calculation | Initial min and max grades | And I press "Save changes" And I navigate to "View > Grader report" in the course gradebook - And I press "Turn editing on" + And I turn editing mode on And I give the grade "75.00" to the user "Student 1" for the grade item "grade item 1" And I press "Save changes" And I navigate to "View > User report" in the course gradebook diff --git a/grade/tests/behat/grade_letter_boundary.feature b/grade/tests/behat/grade_letter_boundary.feature index d9d951c3ff8..2b0fa5bb652 100644 --- a/grade/tests/behat/grade_letter_boundary.feature +++ b/grade/tests/behat/grade_letter_boundary.feature @@ -33,10 +33,10 @@ Feature: We can customise the letter boundary of a course. | id_gradeboundary10 | 57 | And I press "Save changes" And I navigate to "View > Grader report" in the course gradebook - And I press "Turn editing on" + And I turn editing mode on And I give the grade "57" to the user "Student 1" for the grade item "Test assignment one" And I press "Save changes" - And I press "Turn editing off" + And I turn editing mode off Then the following should exist in the "user-grades" table: | -1- | -4- | -5- | | Student 1 | D | D | diff --git a/grade/tests/behat/grade_letter_boundary_20160518.feature b/grade/tests/behat/grade_letter_boundary_20160518.feature index 0f5dbc18dcd..b46c43c5ef4 100644 --- a/grade/tests/behat/grade_letter_boundary_20160518.feature +++ b/grade/tests/behat/grade_letter_boundary_20160518.feature @@ -34,10 +34,10 @@ Feature: We can customise the letter boundary of a course in gradebook version 2 | id_gradeboundary10 | 57 | And I press "Save changes" And I navigate to "View > Grader report" in the course gradebook - And I press "Turn editing on" + And I turn editing mode on And I give the grade "57" to the user "Student 1" for the grade item "Test assignment one" And I press "Save changes" - And I press "Turn editing off" + And I turn editing mode off Then the following should exist in the "user-grades" table: | -1- | -4- | -5- | | Student 1 | F | F | diff --git a/grade/tests/behat/grade_to_pass.feature b/grade/tests/behat/grade_to_pass.feature index a2062f26c7c..fc119fd20a2 100644 --- a/grade/tests/behat/grade_to_pass.feature +++ b/grade/tests/behat/grade_to_pass.feature @@ -85,7 +85,6 @@ Feature: We can set the grade to pass value | Grade to pass | 3 | And I press "Save and return to course" And I navigate to "View > Grader report" in the course gradebook - And I turn editing mode on And I click on "Edit assign Test Assignment 1" "link" And I expand all fieldsets Then the field "Grade to pass" matches value "3" @@ -124,7 +123,6 @@ Feature: We can set the grade to pass value | Assessment grade to pass | 10 | And I press "Save and return to course" And I navigate to "View > Grader report" in the course gradebook - And I turn editing mode on And I click on "Edit workshop Test Workshop 1 (submission)" "link" And I expand all fieldsets Then the field "Grade to pass" matches value "40" @@ -168,7 +166,6 @@ Feature: We can set the grade to pass value | Grade to pass | 9.5 | And I press "Save and return to course" And I navigate to "View > Grader report" in the course gradebook - And I turn editing mode on And I click on "Edit quiz Test Quiz 1" "link" And I expand all fieldsets Then the field "Grade to pass" matches value "9.5" @@ -190,7 +187,6 @@ Feature: We can set the grade to pass value | Grade to pass | 90 | And I press "Save and return to course" And I navigate to "View > Grader report" in the course gradebook - And I turn editing mode on And I click on "Edit lesson Test Lesson 1" "link" And I expand all fieldsets Then the field "Grade to pass" matches value "90" @@ -215,7 +211,6 @@ Feature: We can set the grade to pass value | Ratings > Grade to pass | 90 | And I press "Save and return to course" And I navigate to "View > Grader report" in the course gradebook - And I turn editing mode on And I click on "Edit data Test Database 1" "link" And I expand all fieldsets Then the field "Grade to pass" matches value "90" @@ -256,7 +251,6 @@ Feature: We can set the grade to pass value | Ratings > Grade to pass | 90 | And I press "Save and return to course" And I navigate to "View > Grader report" in the course gradebook - And I turn editing mode on And I click on "Edit forum Test Forum 1 rating" "link" And I expand all fieldsets Then the field "Grade to pass" matches value "90" @@ -280,7 +274,6 @@ Feature: We can set the grade to pass value | Ratings > Grade to pass | 90 | And I press "Save and return to course" And I navigate to "View > Grader report" in the course gradebook - And I turn editing mode on And I click on "Edit glossary Test Glossary 1" "link" And I expand all fieldsets Then the field "Grade to pass" matches value "90" diff --git a/grade/tests/report_graderlib_test.php b/grade/tests/report_graderlib_test.php index 431d129a0ac..8200f4fda06 100644 --- a/grade/tests/report_graderlib_test.php +++ b/grade/tests/report_graderlib_test.php @@ -261,7 +261,7 @@ class core_grade_report_graderlib_testcase extends advanced_testcase { // Set current user. $this->setUser($manager); - $USER->gradeediting[$course->id] = false; + $USER->editing = false; // Get the report. $report = $this->create_report($course); diff --git a/lang/en/error.php b/lang/en/error.php index 038f56b074c..ff27f1e21d5 100644 --- a/lang/en/error.php +++ b/lang/en/error.php @@ -152,6 +152,7 @@ $string['cannotsetupblock'] = 'Blocks tables could NOT be set up successfully!'; $string['cannotsetupcapformod'] = 'Could not set up the capabilities for {$a}'; $string['cannotsetupcapforplugin'] = 'Could not set up the capabilities for {$a}'; $string['cannotshowhidecoursesincategory'] = 'Cannot show/hide the courses in category {$a}.'; +$string['cannotswitcheditmodeon'] = 'Could not switch edit mode on'; $string['cannotsignup'] = 'You cannot create a new account because you are already logged in as {$a}.'; $string['cannotunassigncap'] = 'Could not unassign deprecated capability {$a->cap} from role {$a->role}'; $string['cannotunassignrolefrom'] = 'Cannot unassign this user from role id: {$a}'; diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 67e6db0619d..f23cf26386f 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -579,6 +579,7 @@ $string['editfiles'] = 'Edit files'; $string['editgroupprofile'] = 'Edit group profile'; $string['editinga'] = 'Editing {$a}'; $string['editingteachershort'] = 'Editor'; +$string['editmode'] = 'Edit mode'; $string['editlock'] = 'This value cannot be edited!'; $string['editmyprofile'] = 'Edit profile'; $string['editorbgcolor'] = 'Background-color'; @@ -1901,6 +1902,7 @@ $string['serverlocaltime'] = 'Server\'s local time'; $string['sessionforceclean'] = 'As a security precaution, user-generated scripts have been disabled within this session.'; $string['sessiontimeoutsoon'] = 'Your session is about to time out. Do you want to extend your current session?'; $string['setcategorytheme'] = 'Set category theme'; +$string['setmode'] = 'Set mode'; $string['setpassword'] = 'Set password'; $string['setpasswordinstructions'] = 'Please enter your new password below, then save changes.'; $string['settings'] = 'Settings'; diff --git a/lib/adminlib.php b/lib/adminlib.php index d25dbfd4a07..9f13db277ca 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -8836,7 +8836,7 @@ function admin_externalpage_setup($section, $extrabutton = '', array $extraurlpa $visiblepathtosection = array_reverse($extpage->visiblepath); - if ($PAGE->user_allowed_editing()) { + if ($PAGE->user_allowed_editing() && !$PAGE->theme->haseditswitch) { if ($PAGE->user_is_editing()) { $caption = get_string('blockseditoff'); $url = new moodle_url($PAGE->url, array('adminedit'=>'0', 'sesskey'=>sesskey())); diff --git a/lib/amd/build/edit_switch.min.js b/lib/amd/build/edit_switch.min.js new file mode 100644 index 00000000000..23199e13042 --- /dev/null +++ b/lib/amd/build/edit_switch.min.js @@ -0,0 +1,2 @@ +define ("core/edit_switch",["exports","core/ajax","core/event_dispatcher","core/notification"],function(a,b,c,d){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=a.eventTypes=void 0;var e=function(a,c){return(0,b.call)([{methodname:"core_change_editmode",args:{context:a,setmode:c}}])[0]},f=function(a){if(a.checked){a.setAttribute("aria-checked",!0)}else{a.setAttribute("aria-checked",!1)}var b=h(a,a.checked);if(!b.defaultPrevented){window.location=a.dataset.pageurl}},g={editModeSet:"core/edit_switch/editModeSet"};a.eventTypes=g;var h=function(a,b){return(0,c.dispatchEvent)(g.editModeSet,{editMode:b},a,{cancelable:!0})};a.init=function init(a){var b=document.getElementById(a);b.addEventListener("change",function(){e(b.dataset.context,b.checked).then(function(a){if(a.success){f(b)}else{b.checked=!1}}).catch(d.exception)})}}); +//# sourceMappingURL=edit_switch.min.js.map diff --git a/lib/amd/build/edit_switch.min.js.map b/lib/amd/build/edit_switch.min.js.map new file mode 100644 index 00000000000..0488c0d41d0 --- /dev/null +++ b/lib/amd/build/edit_switch.min.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/edit_switch.js"],"names":["setEditMode","context","setmode","methodname","args","toggleEditSwitch","editSwitch","checked","setAttribute","event","notifyEditModeSet","defaultPrevented","window","location","dataset","pageurl","eventTypes","editModeSet","container","editMode","cancelable","init","editingSwitchId","document","getElementById","addEventListener","then","result","success","catch","displayException"],"mappings":"6MAkCMA,CAAAA,CAAW,CAAG,SAACC,CAAD,CAAUC,CAAV,QAAsB,WAAU,CAAC,CACjDC,UAAU,CAAE,sBADqC,CAEjDC,IAAI,CAAE,CACFH,OAAO,CAAPA,CADE,CAEFC,OAAO,CAAPA,CAFE,CAF2C,CAAD,CAAV,EAMtC,CANsC,CAAtB,C,CAedG,CAAgB,CAAG,SAAAC,CAAU,CAAI,CACnC,GAAIA,CAAU,CAACC,OAAf,CAAwB,CACpBD,CAAU,CAACE,YAAX,CAAwB,cAAxB,IACH,CAFD,IAEO,CACHF,CAAU,CAACE,YAAX,CAAwB,cAAxB,IACH,CAED,GAAMC,CAAAA,CAAK,CAAGC,CAAiB,CAACJ,CAAD,CAAaA,CAAU,CAACC,OAAxB,CAA/B,CACA,GAAI,CAACE,CAAK,CAACE,gBAAX,CAA6B,CACzBC,MAAM,CAACC,QAAP,CAAkBP,CAAU,CAACQ,OAAX,CAAmBC,OACxC,CACJ,C,CAQYC,CAAU,CAAG,CAUtBC,WAAW,CAAE,8BAVS,C,mBA0BpBP,CAAAA,CAAiB,CAAG,SAACQ,CAAD,CAAYC,CAAZ,QAAyB,oBAC/CH,CAAU,CAACC,WADoC,CAE/C,CAACE,QAAQ,CAARA,CAAD,CAF+C,CAG/CD,CAH+C,CAI/C,CAACE,UAAU,GAAX,CAJ+C,CAAzB,C,QAYN,QAAPC,CAAAA,IAAO,CAAAC,CAAe,CAAI,CACnC,GAAMhB,CAAAA,CAAU,CAAGiB,QAAQ,CAACC,cAAT,CAAwBF,CAAxB,CAAnB,CACAhB,CAAU,CAACmB,gBAAX,CAA4B,QAA5B,CAAsC,UAAM,CACxCzB,CAAW,CAACM,CAAU,CAACQ,OAAX,CAAmBb,OAApB,CAA6BK,CAAU,CAACC,OAAxC,CAAX,CACCmB,IADD,CACM,SAAAC,CAAM,CAAI,CACZ,GAAIA,CAAM,CAACC,OAAX,CAAoB,CAChBvB,CAAgB,CAACC,CAAD,CACnB,CAFD,IAEO,CACHA,CAAU,CAACC,OAAX,GACH,CAEJ,CARD,EASCsB,KATD,CASOC,WATP,CAUH,CAXD,CAYH,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Controls the edit switch.\n *\n * @module core/edit_switch\n * @copyright 2021 Bas Brands \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {call as fetchMany} from 'core/ajax';\nimport {dispatchEvent} from 'core/event_dispatcher';\nimport {exception as displayException} from 'core/notification';\n\n/**\n * Change the Edit mode.\n *\n * @param {number} context The contextid that editing is being set for\n * @param {bool} setmode Whether editing is set or not\n * @return {Promise} Resolved with an array file the stored file url.\n */\nconst setEditMode = (context, setmode) => fetchMany([{\n methodname: 'core_change_editmode',\n args: {\n context,\n setmode,\n },\n}])[0];\n\n/**\n * Toggle the edit switch\n *\n * @method\n * @protected\n * @param {HTMLElement} editSwitch\n */\nconst toggleEditSwitch = editSwitch => {\n if (editSwitch.checked) {\n editSwitch.setAttribute('aria-checked', true);\n } else {\n editSwitch.setAttribute('aria-checked', false);\n }\n\n const event = notifyEditModeSet(editSwitch, editSwitch.checked);\n if (!event.defaultPrevented) {\n window.location = editSwitch.dataset.pageurl;\n }\n};\n\n/**\n * Names of events for core/edit_switch.\n *\n * @static\n * @property {String} editModeSet See {@link event:core/edit_switch/editModeSet}\n */\nexport const eventTypes = {\n /**\n * An event triggered when the edit mode toggled.\n *\n * @event core/edit_switch/editModeSet\n * @type {CustomEvent}\n * @property {HTMLElement} target The switch used to toggle the edit mode\n * @property {object} detail\n * @property {bool} detail.editMode\n */\n editModeSet: 'core/edit_switch/editModeSet',\n};\n\n/**\n * Dispatch the editModeSet event after changing the edit mode.\n *\n * This event is cancelable.\n *\n * The default action is to reload the page after toggling the edit mode.\n *\n * @method\n * @protected\n * @param {HTMLElement} container\n * @param {bool} editMode\n * @returns {CustomEvent}\n */\nconst notifyEditModeSet = (container, editMode) => dispatchEvent(\n eventTypes.editModeSet,\n {editMode},\n container,\n {cancelable: true}\n);\n\n/**\n * Add the eventlistener for the editswitch.\n *\n * @param {string} editingSwitchId The id of the editing switch to listen for\n */\nexport const init = editingSwitchId => {\n const editSwitch = document.getElementById(editingSwitchId);\n editSwitch.addEventListener('change', () => {\n setEditMode(editSwitch.dataset.context, editSwitch.checked)\n .then(result => {\n if (result.success) {\n toggleEditSwitch(editSwitch);\n } else {\n editSwitch.checked = false;\n }\n return;\n })\n .catch(displayException);\n });\n};\n"],"file":"edit_switch.min.js"} \ No newline at end of file diff --git a/lib/amd/src/edit_switch.js b/lib/amd/src/edit_switch.js new file mode 100644 index 00000000000..e1bacd29108 --- /dev/null +++ b/lib/amd/src/edit_switch.js @@ -0,0 +1,121 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * Controls the edit switch. + * + * @module core/edit_switch + * @copyright 2021 Bas Brands + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +import {call as fetchMany} from 'core/ajax'; +import {dispatchEvent} from 'core/event_dispatcher'; +import {exception as displayException} from 'core/notification'; + +/** + * Change the Edit mode. + * + * @param {number} context The contextid that editing is being set for + * @param {bool} setmode Whether editing is set or not + * @return {Promise} Resolved with an array file the stored file url. + */ +const setEditMode = (context, setmode) => fetchMany([{ + methodname: 'core_change_editmode', + args: { + context, + setmode, + }, +}])[0]; + +/** + * Toggle the edit switch + * + * @method + * @protected + * @param {HTMLElement} editSwitch + */ +const toggleEditSwitch = editSwitch => { + if (editSwitch.checked) { + editSwitch.setAttribute('aria-checked', true); + } else { + editSwitch.setAttribute('aria-checked', false); + } + + const event = notifyEditModeSet(editSwitch, editSwitch.checked); + if (!event.defaultPrevented) { + window.location = editSwitch.dataset.pageurl; + } +}; + +/** + * Names of events for core/edit_switch. + * + * @static + * @property {String} editModeSet See {@link event:core/edit_switch/editModeSet} + */ +export const eventTypes = { + /** + * An event triggered when the edit mode toggled. + * + * @event core/edit_switch/editModeSet + * @type {CustomEvent} + * @property {HTMLElement} target The switch used to toggle the edit mode + * @property {object} detail + * @property {bool} detail.editMode + */ + editModeSet: 'core/edit_switch/editModeSet', +}; + +/** + * Dispatch the editModeSet event after changing the edit mode. + * + * This event is cancelable. + * + * The default action is to reload the page after toggling the edit mode. + * + * @method + * @protected + * @param {HTMLElement} container + * @param {bool} editMode + * @returns {CustomEvent} + */ +const notifyEditModeSet = (container, editMode) => dispatchEvent( + eventTypes.editModeSet, + {editMode}, + container, + {cancelable: true} +); + +/** + * Add the eventlistener for the editswitch. + * + * @param {string} editingSwitchId The id of the editing switch to listen for + */ +export const init = editingSwitchId => { + const editSwitch = document.getElementById(editingSwitchId); + editSwitch.addEventListener('change', () => { + setEditMode(editSwitch.dataset.context, editSwitch.checked) + .then(result => { + if (result.success) { + toggleEditSwitch(editSwitch); + } else { + editSwitch.checked = false; + } + return; + }) + .catch(displayException); + }); +}; diff --git a/lib/behat/classes/behat_session_trait.php b/lib/behat/classes/behat_session_trait.php index 399a882c46a..775c5db06be 100644 --- a/lib/behat/classes/behat_session_trait.php +++ b/lib/behat/classes/behat_session_trait.php @@ -134,7 +134,7 @@ trait behat_session_trait { } // How much we will be waiting for the element to appear. - if (!$timeout) { + if ($timeout === false) { $timeout = self::get_timeout(); $microsleep = false; } else { @@ -339,7 +339,7 @@ trait behat_session_trait { protected function spin($lambda, $args = false, $timeout = false, $exception = false, $microsleep = false) { // Using default timeout which is pretty high. - if (!$timeout) { + if ($timeout === false) { $timeout = self::get_timeout(); } diff --git a/lib/classes/external/editmode.php b/lib/classes/external/editmode.php new file mode 100644 index 00000000000..06bca19447a --- /dev/null +++ b/lib/classes/external/editmode.php @@ -0,0 +1,103 @@ +. + +/** + * A web service to load the mapping of moodle pix names to fontawesome icon names. + * + * @package core + * @category external + * @copyright 2021 Bas Brands + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace core\external; + +use external_api; +use external_function_parameters; +use external_single_structure; +use external_value; + +/** + * Web service to change the edit mode. + * + * @package core + * @copyright 2021 Bas Brands + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class editmode extends external_api { + + /** + * Description of the parameters suitable for the `change_editmode` function. + * + * @return external_function_parameters + */ + public static function change_editmode_parameters(): external_function_parameters { + return new external_function_parameters( + [ + 'setmode' => new external_value(PARAM_BOOL, 'Set edit mode to'), + 'context' => new external_value(PARAM_INT, 'Page context id') + ] + ); + } + + /** + * Save the image and return any warnings and the new image url + * + * @param bool $setmode the current edit mode + * @param int $contextid the current page context id + * @return array the new edit mode. + */ + public static function change_editmode(bool $setmode, int $contextid): array { + global $USER, $PAGE; + + $params = self::validate_parameters( + self::change_editmode_parameters(), + [ + 'setmode' => $setmode, + 'context' => $contextid + ] + ); + + $context = \context_helper::instance_by_id($params['context']); + self::validate_context($context); + $PAGE->set_context($context); + + if ($context->id === \context_user::instance($USER->id)->id) { + $PAGE->set_blocks_editing_capability('moodle/my:manageblocks'); + } + + $success = false; + if ($PAGE->user_allowed_editing()) { + $USER->editing = $setmode; + $success = true; + } + + return ['success' => $success]; + } + + /** + * Description of the return value for the `change_editmode` function. + * + * @return external_single_structure + */ + public static function change_editmode_returns(): external_single_structure { + $keys = [ + 'success' => new external_value(PARAM_BOOL, 'The edit mode was changed', VALUE_REQUIRED), + ]; + + return new external_single_structure($keys, 'editmode'); + } +} diff --git a/lib/db/services.php b/lib/db/services.php index e0da03974a8..beb8dd01eaa 100644 --- a/lib/db/services.php +++ b/lib/db/services.php @@ -2785,7 +2785,13 @@ $functions = array( 'type' => 'read', 'ajax' => true, ], - + 'core_change_editmode' => [ + 'classname' => 'core\external\editmode', + 'methodname' => 'change_editmode', + 'description' => 'Change the editing mode', + 'type' => 'write', + 'ajax' => true, + ], ); $services = array( diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index cee2aa1b104..7107563d9c3 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -2484,7 +2484,7 @@ class grade_item extends grade_object { global $USER; // Determine which display type to use for this average - if (isset($USER->gradeediting) && array_key_exists($this->courseid, $USER->gradeediting) && $USER->gradeediting[$this->courseid]) { + if (isset($USER->editing) && $USER->editing) { $displaytype = GRADE_DISPLAY_TYPE_REAL; } else if ($rangesdisplaytype == GRADE_REPORT_PREFERENCE_INHERIT) { // no ==0 here, please resave report and user prefs diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 7249f9e784f..5d8e1e39ed4 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -5434,7 +5434,7 @@ class settings_navigation extends navigation_node { } $frontpage->id = 'frontpagesettings'; - if ($this->page->user_allowed_editing()) { + if ($this->page->user_allowed_editing() && !$this->page->theme->haseditswitch) { // Add the turn on/off settings $url = new moodle_url('/course/view.php', array('id'=>$course->id, 'sesskey'=>sesskey())); diff --git a/lib/outputlib.php b/lib/outputlib.php index bfc93a0d6cc..0462b35173e 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -754,7 +754,7 @@ class theme_config { 'rendererfactory', 'csspostprocess', 'editor_sheets', 'editor_scss', 'rarrow', 'larrow', 'uarrow', 'darrow', 'hidefromselector', 'doctype', 'yuicssmodules', 'blockrtlmanipulations', 'blockrendermethod', 'scss', 'extrascsscallback', 'prescsscallback', 'csstreepostprocessor', 'addblockposition', - 'iconsystem', 'precompiledcsscallback'); + 'iconsystem', 'precompiledcsscallback', 'haseditswitch'); foreach ($config as $key=>$value) { if (in_array($key, $configurable)) { diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 6667b0d5ddf..58463fa52af 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -2748,6 +2748,9 @@ EOD; */ public function edit_button(moodle_url $url) { + if ($this->page->theme->haseditswitch == true) { + return; + } $url->param('sesskey', sesskey()); if ($this->page->user_is_editing()) { $url->param('edit', 'off'); @@ -2760,6 +2763,27 @@ EOD; return $this->single_button($url, $editstring); } + /** + * Create a navbar switch for toggling editing mode. + * + * @return string Html containing the edit switch + */ + public function edit_switch() { + if ($this->page->user_allowed_editing()) { + + $temp = (object) [ + 'legacyseturl' => (new moodle_url('/editmode.php'))->out(false), + 'pagecontextid' => $this->page->context->id, + 'pageurl' => $this->page->url, + 'sesskey' => sesskey(), + ]; + if ($this->page->user_is_editing()) { + $temp->checked = true; + } + return $this->render_from_template('core/editswitch', $temp); + } + } + /** * Returns HTML to display a simple button to close a window * diff --git a/lib/templates/editswitch.mustache b/lib/templates/editswitch.mustache new file mode 100644 index 00000000000..6c368d3e954 --- /dev/null +++ b/lib/templates/editswitch.mustache @@ -0,0 +1,63 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + + @template theme_boost/editswitch + + This template renders the top navbar. + + Example context (json): + { + "url": "http://localhost/", + "sesskey": "sesskey", + "edit": 1, + "adminedit": true, + "checked": "", + "string": "Edit on" + } +}} + +
+ + + + + + +
+ +{{#js}} +require(['core/edit_switch'], function(editSwitch) { + editSwitch.init('{{uniqid}}-editingswitch'); +}); +{{/js}} diff --git a/lib/tests/behat/behat_navigation.php b/lib/tests/behat/behat_navigation.php index f40bb4058c8..a6ea480ab95 100644 --- a/lib/tests/behat/behat_navigation.php +++ b/lib/tests/behat/behat_navigation.php @@ -833,33 +833,38 @@ class behat_navigation extends behat_base { /** * Open the course homepage with editing mode enabled. * - * @Given /^I am on "(?P(?:[^"]|\\")*)" course homepage with editing mode on$/ - * @throws coding_exception * @param string $coursefullname The course full name of the course. - * @return void */ public function i_am_on_course_homepage_with_editing_mode_on($coursefullname) { + $this->i_am_on_course_homepage_with_editing_mode_set_to($coursefullname, 'on'); + } + + /** + * Open the course homepage with editing mode set to either on, or off. + * + * @Given I am on :coursefullname course homepage with editing mode :onoroff + * @throws coding_exception + * @param string $coursefullname The course full name of the course. + * @param string $onoroff Whehter to switch editing on, or off. + */ + public function i_am_on_course_homepage_with_editing_mode_set_to(string $coursefullname, string $onoroff): void { global $DB; $course = $DB->get_record("course", array("fullname" => $coursefullname), 'id', MUST_EXIST); $url = new moodle_url('/course/view.php', ['id' => $course->id]); - if ($this->running_javascript() && $sesskey = $this->get_sesskey()) { - // Javascript is running so it is possible to grab the session ket and jump straight to editing mode. - $url->param('edit', 1); - $url->param('sesskey', $sesskey); - $this->execute('behat_general::i_visit', [$url]); - - return; - } - // Visit the course page. $this->execute('behat_general::i_visit', [$url]); - try { - $this->execute("behat_forms::press_button", get_string('turneditingon')); - } catch (Exception $e) { - $this->execute("behat_navigation::i_navigate_to_in_current_page_administration", [get_string('turneditingon')]); + switch ($onoroff) { + case 'on': + $this->execute('behat_navigation::i_turn_editing_mode_on'); + break; + case 'off': + $this->execute('behat_navigation::i_turn_editing_mode_off'); + break; + default: + throw new \coding_exception("Unknown editing mode '{$onoroff}'. Accepted values are 'on' and 'off'"); } } @@ -1103,7 +1108,6 @@ class behat_navigation extends behat_base { $this->execute('behat_general::i_visit', [$url]); } - /** * First checks to see if we are on this page via the breadcrumb. If not we then attempt to follow the link name given. * @@ -1193,4 +1197,54 @@ class behat_navigation extends behat_base { "//div[contains(concat(' ', @class, ' '), ' dropdown-menu ')]" . "//div[contains(concat(' ', @class, ' '), ' submenu ')][@aria-label='" . $submenuname . "']"; } + + /** + * Returns whether the user can edit the current page. + * + * @return bool + */ + protected function is_editing_on() { + $body = $this->find('xpath', "//body", false, false, 0); + return $body->hasClass('editing'); + } + + /** + * Turns editing mode on. + * @Given I switch editing mode on + * @Given I turn editing mode on + */ + public function i_turn_editing_mode_on() { + $this->execute('behat_forms::i_set_the_field_to', [get_string('editmode'), 1]); + + if (!$this->running_javascript()) { + $this->execute('behat_general::i_click_on', [ + get_string('setmode', 'core'), + 'button', + ]); + } + + if (!$this->is_editing_on()) { + throw new ExpectationException('The edit mode could not be turned on', $this->getSession()); + } + } + + /** + * Turns editing mode off. + * @Given I switch editing mode off + * @Given I turn editing mode off + */ + public function i_turn_editing_mode_off() { + $this->execute('behat_forms::i_set_the_field_to', [get_string('editmode'), 0]); + + if (!$this->running_javascript()) { + $this->execute('behat_general::i_click_on', [ + get_string('setmode', 'core'), + 'button', + ]); + } + + if ($this->is_editing_on()) { + throw new ExpectationException('The edit mode could not be turned off', $this->getSession()); + } + } } diff --git a/lib/tests/behat/locking.feature b/lib/tests/behat/locking.feature index ad2c1bf9f49..c296c8ed5b8 100644 --- a/lib/tests/behat/locking.feature +++ b/lib/tests/behat/locking.feature @@ -44,15 +44,15 @@ Feature: Context freezing apply to child contexts And I click on "Continue" "button" Then "Add a new discussion topic" "link" should not exist When I am on "courseaa1" course homepage - Then I should see "Turn editing on" + Then "Set mode" "button" should exist When I follow "faa1b" Then "Add a new discussion topic" "link" should exist When I am on "courseaa2" course homepage - Then I should see "Turn editing on" + Then "Set mode" "button" should exist When I follow "faa2" Then "Add a new discussion topic" "link" should exist When I am on "courseb" course homepage - Then I should see "Turn editing on" + Then "Set mode" "button" should exist When I follow "fb" Then "Add a new discussion topic" "link" should exist @@ -61,15 +61,15 @@ Feature: Context freezing apply to child contexts And I follow "faa1" Then "Add a new discussion topic" "link" should not exist When I am on "courseaa1" course homepage - Then I should see "Turn editing on" + Then "Set mode" "button" should exist When I follow "faa1b" Then "Add a new discussion topic" "link" should exist When I am on "courseaa2" course homepage - Then I should see "Turn editing on" + Then "Set mode" "button" should exist When I follow "faa2" Then "Add a new discussion topic" "link" should exist When I am on "courseb" course homepage - Then I should see "Turn editing on" + Then "Set mode" "button" should exist When I follow "fb" And "Add a new discussion topic" "link" should exist @@ -89,23 +89,23 @@ Feature: Context freezing apply to child contexts Scenario: Freeze course should freeze all children Given I am on the "courseaa1" "Course" page logged in as "admin" - And I should see "Turn editing on" + And "Set mode" "button" should exist When I follow "Freeze this context" And I click on "Continue" "button" - Then I should not see "Turn editing on" + Then "Set mode" "button" should not exist Then "Add a new discussion topic" "link" should not exist When I am on "courseaa1" course homepage - Then I should not see "Turn editing on" + Then "Set mode" "button" should not exist And "Unfreeze this context" "link" should exist in current page administration When I follow "faa1b" Then "Add a new discussion topic" "link" should not exist And "Unfreeze this context" "link" should not exist in current page administration When I am on "courseaa2" course homepage - Then I should see "Turn editing on" + Then "Set mode" "button" should exist When I follow "faa2" Then "Add a new discussion topic" "link" should exist When I am on "courseb" course homepage - Then I should see "Turn editing on" + Then "Set mode" "button" should exist When I follow "fb" Then "Add a new discussion topic" "link" should exist @@ -114,15 +114,15 @@ Feature: Context freezing apply to child contexts And I follow "faa1" Then "Add a new discussion topic" "link" should not exist When I am on "courseaa1" course homepage - Then I should not see "Turn editing on" + Then "Set mode" "button" should not exist When I follow "faa1b" Then "Add a new discussion topic" "link" should not exist When I am on "courseaa2" course homepage - Then I should see "Turn editing on" + Then "Set mode" "button" should exist When I follow "faa2" Then "Add a new discussion topic" "link" should exist When I am on "courseb" course homepage - Then I should see "Turn editing on" + Then "Set mode" "button" should exist When I follow "fb" Then "Add a new discussion topic" "link" should exist @@ -146,39 +146,39 @@ Feature: Context freezing apply to child contexts And I click on "managecontextlock" action for "cata" in management category listing And I click on "Continue" "button" And I am on "courseaa1" course homepage - And I should not see "Turn editing on" + And "Set mode" "button" should not exist Then "Add a new discussion topic" "link" should not exist When I am on "courseaa1" course homepage - Then I should not see "Turn editing on" + Then "Set mode" "button" should not exist And "Unfreeze this context" "link" should not exist in current page administration When I follow "faa1b" Then "Add a new discussion topic" "link" should not exist And "Unfreeze this context" "link" should not exist in current page administration When I am on "courseaa2" course homepage - Then I should not see "Turn editing on" + Then "Set mode" "button" should not exist When I follow "faa2" Then "Add a new discussion topic" "link" should not exist And "Unfreeze this context" "link" should not exist in current page administration When I am on "courseb" course homepage - Then I should see "Turn editing on" + Then "Set mode" "button" should exist When I follow "fb" Then "Add a new discussion topic" "link" should exist And I log out When I am on the "courseaa1" "Course" page logged in as "teacher" - Then I should not see "Turn editing on" + Then "Set mode" "button" should not exist And I follow "faa1" Then "Add a new discussion topic" "link" should not exist When I am on "courseaa1" course homepage - Then I should not see "Turn editing on" + Then "Set mode" "button" should not exist When I follow "faa1b" Then "Add a new discussion topic" "link" should not exist When I am on "courseaa2" course homepage - Then I should not see "Turn editing on" + Then "Set mode" "button" should not exist When I follow "faa2" Then "Add a new discussion topic" "link" should not exist When I am on "courseb" course homepage - Then I should see "Turn editing on" + Then "Set mode" "button" should exist When I follow "fb" Then "Add a new discussion topic" "link" should exist diff --git a/lib/tests/behat/switch_editing_mode.feature b/lib/tests/behat/switch_editing_mode.feature new file mode 100644 index 00000000000..d8df9d44d55 --- /dev/null +++ b/lib/tests/behat/switch_editing_mode.feature @@ -0,0 +1,79 @@ +@core @turn_edit_mode_on @javascript +Feature: Turn editing mode on + Users should be able to turn editing mode on and off + + Background: + Given the following "courses" exist: + | fullname | shortname | + | Course 1 | C1 | + And the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + | student1 | Student | 1 | student1@example.com | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And I log in as "teacher1" + And I am on "Course 1" course homepage with editing mode on + And I turn editing mode off + And I log out + + Scenario: Edit mode on page Gradebook + Given the following "activities" exist: + | activity | course | idnumber | name | intro | + | assign | C1 | assign1 | Test Assignment 1 | Test Assignment 1 | + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I navigate to "View > Grader report" in the course gradebook + And I turn editing mode on + And "Edit assign Test Assignment 1" "link" should exist + And I turn editing mode off + Then "Edit assign Test Assignment 1" "link" should not exist + + Scenario: Edit mode on page Course + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I turn editing mode on + And I should see "Add an activity or resource" + And I turn editing mode off + Then I should not see "Add an activity or resource" + + Scenario: Edit mode on page Homepage + Given I log in as "admin" + And I am on site homepage + And I turn editing mode on + And I should see "Add an activity or resource" + And I turn editing mode off + Then I should not see "Add an activity or resource" + + Scenario: Edit mode on page Default profile + Given I log in as "admin" + And I navigate to "Appearance > Default profile page" in site administration + And I turn editing mode on + And I should see "Add a block" + And I turn editing mode off + Then I should not see "Add a block" + + Scenario: Edit mode on page Profile + Given I log in as "admin" + And I follow "View profile" + And I turn editing mode on + And I should see "Add a block" + And I turn editing mode off + Then I should not see "Add a block" + + Scenario: Edit mode on page Default dashboard + Given I log in as "admin" + And I navigate to "Appearance > Default Dashboard page" in site administration + And I turn editing mode on + And I should see "Add a block" + And I turn editing mode off + Then I should not see "Add a block" + + Scenario: Edit mode on page Dashboard + And I log in as "teacher1" + And I turn editing mode on + And I should see "Add a block" + Then I turn editing mode off + Then I should not see "Add a block" diff --git a/media/player/videojs/tests/behat/modules.feature b/media/player/videojs/tests/behat/modules.feature index a0175ddce9d..1cc11953d5d 100644 --- a/media/player/videojs/tests/behat/modules.feature +++ b/media/player/videojs/tests/behat/modules.feature @@ -7,7 +7,7 @@ Feature: Embed videos without the media filter Background: Given I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on @javascript Scenario: Add a video in a URL resource. Make sure media filters work diff --git a/mod/book/lib.php b/mod/book/lib.php index 6f13bbc9d81..bc130833750 100644 --- a/mod/book/lib.php +++ b/mod/book/lib.php @@ -346,7 +346,9 @@ function book_extend_settings_navigation(settings_navigation $settingsnav, navig $url = new moodle_url('/mod/book/view.php', array('id'=>$params['id'], 'chapterid'=>$params['chapterid'], 'edit'=>$edit, 'sesskey'=>sesskey())); $editnode = navigation_node::create($string, $url, navigation_node::TYPE_SETTING); $booknode->add_node($editnode, $firstkey); - $PAGE->set_button($OUTPUT->single_button($url, $string)); + if (!$PAGE->theme->haseditswitch) { + $PAGE->set_button($OUTPUT->single_button($url, $string)); + } } $plugins = core_component::get_plugin_list('booktool'); diff --git a/mod/book/tests/behat/create_chapters.feature b/mod/book/tests/behat/create_chapters.feature index 8c0061dcc1b..e942ed7de68 100644 --- a/mod/book/tests/behat/create_chapters.feature +++ b/mod/book/tests/behat/create_chapters.feature @@ -73,7 +73,7 @@ Feature: In a book, create chapters and sub chapters And "Delete chapter \"1. Dummy first chapter\"" "link" should exist in the "Table of contents" "block" And "Hide chapter \"1. Dummy first chapter\"" "link" should exist in the "Table of contents" "block" And "Add new chapter" "link" should exist in the "Table of contents" "block" - When I press "Turn editing off" + When I turn editing mode off Then "Edit chapter \"1. Dummy first chapter\"" "link" should not exist in the "Table of contents" "block" And "Delete chapter \"1. Dummy first chapter\"" "link" should not exist in the "Table of contents" "block" And "Hide chapter \"1. Dummy first chapter\"" "link" should not exist in the "Table of contents" "block" diff --git a/mod/book/tests/behat/edit_tags.feature b/mod/book/tests/behat/edit_tags.feature index d1b3cc2fa57..8737d6f8c1b 100644 --- a/mod/book/tests/behat/edit_tags.feature +++ b/mod/book/tests/behat/edit_tags.feature @@ -33,7 +33,7 @@ Feature: Edited book chapters handle tags correctly Then I should see "Example" in the ".book-tags" "css_element" And I should see "Chapter" in the ".book-tags" "css_element" And I should see "Cool" in the ".book-tags" "css_element" - And I press "Turn editing on" + And I turn editing mode on And I follow "Edit chapter \"1. Dummy first chapter\"" Then I should see "Example" in the ".form-autocomplete-selection" "css_element" Then I should see "Chapter" in the ".form-autocomplete-selection" "css_element" @@ -42,6 +42,7 @@ Feature: Edited book chapters handle tags correctly @javascript Scenario: Book chapter edition of standard tags works as expected Given I log in as "admin" + And I change window size to "large" And I navigate to "Appearance > Manage tags" in site administration And I follow "Default collection" And I follow "Add standard tags" @@ -61,7 +62,7 @@ Feature: Edited book chapters handle tags correctly Then I should see "OT1" in the ".book-tags" "css_element" And I should see "OT3" in the ".book-tags" "css_element" And I should not see "OT2" in the ".book-tags" "css_element" - And I press "Turn editing on" + And I turn editing mode on And I follow "Edit chapter \"1. Dummy first chapter\"" And I should see "OT1" in the ".form-autocomplete-selection" "css_element" And I should see "OT3" in the ".form-autocomplete-selection" "css_element" diff --git a/mod/data/tests/behat/create_activity.feature b/mod/data/tests/behat/create_activity.feature index a1d46c78043..d8463cde075 100644 --- a/mod/data/tests/behat/create_activity.feature +++ b/mod/data/tests/behat/create_activity.feature @@ -17,7 +17,7 @@ Feature: Teachers can enable comments only if comments are enabled at site level | teacher1 | C1 | editingteacher | When I log in as "teacher1" And I am on "Course 1" course homepage - And I press "Turn editing on" + And I turn editing mode on And I press "Add an activity or resource" And I click on "Add a new Database" "link" in the "Add an activity or resource" "dialogue" And I expand all fieldsets diff --git a/mod/data/view.php b/mod/data/view.php index a50662d5721..6f22273b5e4 100644 --- a/mod/data/view.php +++ b/mod/data/view.php @@ -231,7 +231,7 @@ // The code will be much nicer than this eventually. $title = $courseshortname.': ' . format_string($data->name); - if ($PAGE->user_allowed_editing()) { + if ($PAGE->user_allowed_editing() && !$PAGE->theme->haseditswitch) { // Change URL parameter and block display string value depending on whether editing is enabled or not if ($PAGE->user_is_editing()) { $urlediting = 'off'; diff --git a/mod/feedback/tests/behat/coursemapping.feature b/mod/feedback/tests/behat/coursemapping.feature index cb66f9485dd..72a215081e6 100644 --- a/mod/feedback/tests/behat/coursemapping.feature +++ b/mod/feedback/tests/behat/coursemapping.feature @@ -232,7 +232,7 @@ Feature: Mapping courses in a feedback And I add the "Main menu" block And I click on "Delete" "link" in the "Course feedback" activity And I press "Yes" - And I follow "Turn editing off" + And I turn editing mode off And I am on site homepage Then "Feedback" "block" should not exist And I am on "Course 1" course homepage diff --git a/mod/forum/tests/behat/edit_tags.feature b/mod/forum/tests/behat/edit_tags.feature index 20a1ccf6c42..a6e522c94a8 100644 --- a/mod/forum/tests/behat/edit_tags.feature +++ b/mod/forum/tests/behat/edit_tags.feature @@ -40,6 +40,7 @@ Feature: Edited forum posts handle tags correctly @javascript Scenario: Forum post edition of standard tags works as expected Given I log in as "admin" + And I change window size to "large" And I navigate to "Appearance > Manage tags" in site administration And I follow "Default collection" And I follow "Add standard tags" diff --git a/mod/forum/tests/behat/grade_forum.feature b/mod/forum/tests/behat/grade_forum.feature index 0e7ffb9ac16..da1f30b1a83 100644 --- a/mod/forum/tests/behat/grade_forum.feature +++ b/mod/forum/tests/behat/grade_forum.feature @@ -117,7 +117,6 @@ Feature: I can grade a students interaction across a forum And I set the field "Ratings > Grade to pass" to "4" When I press "Save and return to course" And I navigate to "View > Grader report" in the course gradebook - And I turn editing mode on # There shouldn't be any Whole forum grade gradeitem. Then I should see "Test Forum 1 rating" diff --git a/mod/glossary/tests/behat/edit_tags.feature b/mod/glossary/tests/behat/edit_tags.feature index e26859a8870..6f0d069fba6 100644 --- a/mod/glossary/tests/behat/edit_tags.feature +++ b/mod/glossary/tests/behat/edit_tags.feature @@ -41,6 +41,7 @@ Feature: Edited glossary entries handle tags correctly Scenario: Glossary entry edition of standard tags works as expected Given I log in as "admin" + And I change window size to "large" And I navigate to "Appearance > Manage tags" in site administration And I follow "Default collection" And I follow "Add standard tags" diff --git a/mod/glossary/tests/behat/entries_require_approval.feature b/mod/glossary/tests/behat/entries_require_approval.feature index f45b3a7e45a..29ebe48e220 100644 --- a/mod/glossary/tests/behat/entries_require_approval.feature +++ b/mod/glossary/tests/behat/entries_require_approval.feature @@ -68,7 +68,7 @@ Feature: A teacher can choose whether glossary entries require approval | Tags | Test | And I log out And I log in as "teacher1" - And I press "Customise this page" + And I turn editing mode on And I add the "Navigation" block if not present And I expand "Site pages" node And I click on "Tags" "link" in the "Navigation" "block" diff --git a/mod/wiki/tests/behat/edit_tags.feature b/mod/wiki/tests/behat/edit_tags.feature index fa242ca40b8..7b098fc4454 100644 --- a/mod/wiki/tests/behat/edit_tags.feature +++ b/mod/wiki/tests/behat/edit_tags.feature @@ -42,6 +42,7 @@ Feature: Edited wiki pages handle tags correctly @javascript Scenario: Wiki page edition of standard tags works as expected Given I log in as "admin" + And I change window size to "large" And I navigate to "Appearance > Manage tags" in site administration And I follow "Default collection" And I follow "Add standard tags" diff --git a/my/index.php b/my/index.php index 331954b73c9..fe684a6bba8 100644 --- a/my/index.php +++ b/my/index.php @@ -155,7 +155,10 @@ if (empty($CFG->forcedefaultmymoodle) && $PAGE->user_allowed_editing()) { } $url = new moodle_url("$CFG->wwwroot/my/index.php", $params); - $button = $OUTPUT->single_button($url, $editstring); + $button = ''; + if (!$PAGE->theme->haseditswitch) { + $button = $OUTPUT->single_button($url, $editstring); + } $PAGE->set_button($resetbutton . $button); } else { diff --git a/my/tests/behat/add_blocks.feature b/my/tests/behat/add_blocks.feature index 3728f18e654..8cc75d38382 100644 --- a/my/tests/behat/add_blocks.feature +++ b/my/tests/behat/add_blocks.feature @@ -19,9 +19,9 @@ Feature: Add blocks to dashboard page And I log in as "student1" Scenario: Add blocks to page - When I press "Customise this page" + When I turn editing mode on And I add the "Latest announcements" block - And I press "Stop customising this page" + And I turn editing mode off Then I should see "Latest announcements" in the "Latest announcements" "block" And I should see "Latest badges" in the "Latest badges" "block" And I should see "Calendar" in the "Calendar" "block" diff --git a/my/tests/behat/reset_all_pages.feature b/my/tests/behat/reset_all_pages.feature index 9f24eb80095..ca89da8252b 100644 --- a/my/tests/behat/reset_all_pages.feature +++ b/my/tests/behat/reset_all_pages.feature @@ -18,18 +18,18 @@ Feature: Reset all personalised pages to default And I log in as "student1" And I follow "Dashboard" in the user menu - And I press "Customise this page" + And I turn editing mode on And I add the "Comments" block - And I press "Stop customising this page" + And I turn editing mode off And I should see "Comments" And I log out And I log in as "student2" And I follow "Profile" in the user menu And I should not see "Logged in user" - And I press "Customise this page" + And I turn editing mode on And I add the "Logged in user" block - And I press "Stop customising this page" + And I turn editing mode off And I should see "Logged in user" And I log out @@ -43,12 +43,12 @@ Feature: Reset all personalised pages to default Scenario: Reset Dashboard for all users Given I log in as "admin" And I navigate to "Appearance > Default Dashboard page" in site administration - And I press "Blocks editing on" + And I turn editing mode on And I add the "Latest announcements" block And I open the "Latest badges" blocks action menu And I follow "Delete Latest badges block" And I press "Yes" - And I press "Blocks editing off" + And I turn editing mode off And I log out And I log in as "student1" @@ -91,7 +91,7 @@ Feature: Reset all personalised pages to default Scenario: Reset profile for all users Given I log in as "admin" And I navigate to "Appearance > Default profile page" in site administration - And I press "Blocks editing on" + And I turn editing mode on And I add the "Latest announcements" block And I log out diff --git a/my/tests/behat/reset_page.feature b/my/tests/behat/reset_page.feature index c7fd951b052..0fe871b91ea 100644 --- a/my/tests/behat/reset_page.feature +++ b/my/tests/behat/reset_page.feature @@ -19,7 +19,7 @@ Feature: Reset dashboard page to default And I log in as "student1" Scenario: Add blocks to page and reset - When I press "Customise this page" + When I turn editing mode on And I add the "Latest announcements" block And I add the "Comments" block And I press "Reset page to default" diff --git a/my/tests/behat/restrict_available_blocks.feature b/my/tests/behat/restrict_available_blocks.feature index 14d06b739b3..bc699f2fc38 100644 --- a/my/tests/behat/restrict_available_blocks.feature +++ b/my/tests/behat/restrict_available_blocks.feature @@ -18,7 +18,7 @@ Feature: Restrict which blocks can be added to Dashboard Scenario: The comments block can be added to Dashboard by default And I log in as "student1" - And I press "Customise this page" + And I turn editing mode on Then the add block selector should contain "Comments" block And the add block selector should contain "Courses" block And the add block selector should contain "Text" block @@ -32,7 +32,7 @@ Feature: Restrict which blocks can be added to Dashboard | block/html:myaddinstance | Prohibit | And I log out And I log in as "student1" - And I press "Customise this page" + And I turn editing mode on Then the add block selector should not contain "Comments" block And the add block selector should not contain "Courses" block And the add block selector should not contain "Text" block diff --git a/repository/upload/tests/behat/upload_file.feature b/repository/upload/tests/behat/upload_file.feature index 6a4ff57b64e..c03fe802396 100644 --- a/repository/upload/tests/behat/upload_file.feature +++ b/repository/upload/tests/behat/upload_file.feature @@ -10,7 +10,7 @@ Feature: Upload files | fullname | shortname | category | | Course 1 | C1 | 0 | And I log in as "admin" - And I press "Customise this page" + And I turn editing mode on And I add the "Private files" block if not present When I follow "Manage private files..." And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager diff --git a/tag/tests/behat/collections.feature b/tag/tests/behat/collections.feature index a1deb030b3e..c652b70857e 100644 --- a/tag/tests/behat/collections.feature +++ b/tag/tests/behat/collections.feature @@ -103,7 +103,7 @@ Feature: Managers can create and manage tag collections | Searchable | 0 | And I press "Create" And "Yes" "text" should not exist in the "//table[contains(@class,'tag-collections-table')]//tr[contains(.,'Hiddencoll')]" "xpath_element" - And I press "Blocks editing on" + And I turn editing mode on # TODO MDL-57120 "Tags" link not accessible without navigation block. And I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" diff --git a/tag/tests/behat/edit_tag.feature b/tag/tests/behat/edit_tag.feature index 21fd143a93e..888771129a4 100644 --- a/tag/tests/behat/edit_tag.feature +++ b/tag/tests/behat/edit_tag.feature @@ -31,7 +31,7 @@ Feature: Users can edit tags to add description or rename | moodle/user:viewdetails | Allow | And I log out When I log in as "editor1" - And I press "Customise this page" + And I turn editing mode on # TODO MDL-57120 site "Tags" link not accessible without navigation block. And I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" @@ -56,7 +56,7 @@ Feature: Users can edit tags to add description or rename @javascript Scenario: Manager can change tag description, related tags and rename the tag from tag view page When I log in as "manager1" - And I press "Customise this page" + And I turn editing mode on # TODO MDL-57120 site "Tags" link not accessible without navigation block. And I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" @@ -89,7 +89,7 @@ Feature: Users can edit tags to add description or rename Scenario: Renaming the tag from tag view page When I log in as "manager1" - And I press "Customise this page" + And I turn editing mode on # TODO MDL-57120 site "Tags" link not accessible without navigation block. And I add the "Navigation" block if not present And I click on "Tags" "link" in the "Navigation" "block" diff --git a/tag/tests/behat/flag_tags.feature b/tag/tests/behat/flag_tags.feature index b9fade17cf9..57166f5cd4f 100644 --- a/tag/tests/behat/flag_tags.feature +++ b/tag/tests/behat/flag_tags.feature @@ -24,7 +24,7 @@ Feature: Users can flag tags and manager can reset flags | moodle/user:viewdetails | Allow | And I log out And I log in as "user2" - And I press "Customise this page" + And I turn editing mode on # TODO MDL-57120 site "Tags" link not accessible without navigation block. And I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" @@ -46,7 +46,7 @@ Feature: Users can flag tags and manager can reset flags And I should see "The person responsible will be notified" And I log out And I log in as "user3" - And I press "Customise this page" + And I turn editing mode on # TODO MDL-57120 site "Tags" link not accessible without navigation block. And I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" diff --git a/tag/tests/behat/tagindex.feature b/tag/tests/behat/tagindex.feature index 04f45bad952..7b7ad3afefd 100644 --- a/tag/tests/behat/tagindex.feature +++ b/tag/tests/behat/tagindex.feature @@ -22,7 +22,7 @@ Feature: Browsing tagged items Scenario: Browse tag index with javascript disabled When I log in as "user1" - And I press "Customise this page" + And I turn editing mode on # TODO MDL-57120 "Tags" link not accessible without navigation block. And I add the "Navigation" block if not present And I click on "Tags" "link" in the "Navigation" "block" @@ -69,7 +69,7 @@ Feature: Browsing tagged items @javascript Scenario: Browse tag index with javascript enabled When I log in as "user1" - And I press "Customise this page" + And I turn editing mode on # TODO MDL-57120 "Tags" link not accessible without navigation block. And I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" diff --git a/theme/boost/classes/output/core_renderer.php b/theme/boost/classes/output/core_renderer.php index e5ad7952896..d9d4cff1730 100644 --- a/theme/boost/classes/output/core_renderer.php +++ b/theme/boost/classes/output/core_renderer.php @@ -32,6 +32,9 @@ defined('MOODLE_INTERNAL') || die; class core_renderer extends \core_renderer { public function edit_button(moodle_url $url) { + if ($this->page->theme->haseditswitch) { + return; + } $url->param('sesskey', sesskey()); if ($this->page->user_is_editing()) { $url->param('edit', 'off'); diff --git a/theme/boost/config.php b/theme/boost/config.php index 4f1682d7a09..6db5d20c210 100644 --- a/theme/boost/config.php +++ b/theme/boost/config.php @@ -157,3 +157,4 @@ $THEME->rendererfactory = 'theme_overridden_renderer_factory'; $THEME->requiredblocks = ''; $THEME->addblockposition = BLOCK_ADDBLOCK_POSITION_FLATNAV; $THEME->iconsystem = \core\output\icon_system::FONTAWESOME; +$THEME->haseditswitch = true; diff --git a/theme/boost/templates/navbar.mustache b/theme/boost/templates/navbar.mustache index 3afad628389..d5c6f2c0b56 100644 --- a/theme/boost/templates/navbar.mustache +++ b/theme/boost/templates/navbar.mustache @@ -73,5 +73,6 @@ {{> core/user_menu }} {{/usermenu}}
+ {{{ output.edit_switch }}}
diff --git a/theme/classic/config.php b/theme/classic/config.php index c636e8ecf1b..da34422bc66 100644 --- a/theme/classic/config.php +++ b/theme/classic/config.php @@ -157,3 +157,4 @@ $THEME->scss = function($theme) { }; $THEME->usefallback = true; $THEME->iconsystem = '\\theme_classic\\output\\icon_system_fontawesome'; +$THEME->haseditswitch = false; diff --git a/theme/classic/tests/behat/behat_theme_classic_behat_navigation.php b/theme/classic/tests/behat/behat_theme_classic_behat_navigation.php index d975b8b74ab..f664bbb913e 100644 --- a/theme/classic/tests/behat/behat_theme_classic_behat_navigation.php +++ b/theme/classic/tests/behat/behat_theme_classic_behat_navigation.php @@ -226,4 +226,38 @@ class behat_theme_classic_behat_navigation extends behat_navigation { return $menuxpath; } + + /** + * Turns editing mode off. + */ + public function i_turn_editing_mode_off(): void { + $buttonnames = [get_string('turneditingoff'), get_string('updatemymoodleoff'), get_string('blockseditoff')]; + foreach ($buttonnames as $buttonname) { + if ($editbutton = $this->getSession()->getPage()->findButton($buttonname)) { + $this->execute('behat_general::i_click_on', [$editbutton, 'NodeElement']); + return; + } + } + // Click the turneditingoff link in the Site Administration block. + if ($this->is_editing_on()) { + $this->execute('behat_general::i_click_on', [get_string('turneditingoff'), "link"]); + } + } + + /** + * Turns editing mode on. + */ + public function i_turn_editing_mode_on(): void { + $buttonnames = [get_string('turneditingon'), get_string('updatemymoodleon'), get_string('blocksediton')]; + foreach ($buttonnames as $buttonname) { + if ($editbutton = $this->getSession()->getPage()->findButton($buttonname)) { + $this->execute('behat_general::i_click_on', [$editbutton, 'NodeElement']); + return; + } + } + + if (!$this->is_editing_on()) { + $this->execute('behat_general::i_click_on', [get_string('turneditingon'), "link"]); + } + } } diff --git a/user/profile.php b/user/profile.php index 907d986d2ad..aa272bc01ec 100644 --- a/user/profile.php +++ b/user/profile.php @@ -184,7 +184,10 @@ if ($PAGE->user_allowed_editing()) { } $url = new moodle_url("$CFG->wwwroot/user/profile.php", $params); - $button = $OUTPUT->single_button($url, $editstring); + $button = ''; + if (!$PAGE->theme->haseditswitch) { + $button = $OUTPUT->single_button($url, $editstring); + } $PAGE->set_button($resetbutton . $button); } else { diff --git a/user/tests/behat/add_blocks.feature b/user/tests/behat/add_blocks.feature index a7c5439b59d..18145a843d7 100644 --- a/user/tests/behat/add_blocks.feature +++ b/user/tests/behat/add_blocks.feature @@ -20,6 +20,6 @@ Feature: Add blocks to my profile page And I follow "View profile" Scenario: Add blocks to page - When I press "Customise this page" + When I turn editing mode on And I add the "Latest announcements" block Then I should see "Latest announcements" diff --git a/user/tests/behat/custom_profile_fields.feature b/user/tests/behat/custom_profile_fields.feature index 17c3e35cc5a..de738a2d540 100644 --- a/user/tests/behat/custom_profile_fields.feature +++ b/user/tests/behat/custom_profile_fields.feature @@ -260,7 +260,7 @@ Feature: Custom profile fields should be visible and editable by those with the | moodle/user:editprofile | Allow | parent | User | userwithinformation | Given I log in as "admin" And I am on site homepage - And I navigate to "Turn editing on" in current page administration + And I turn editing mode on And I add the "Mentees" block And I log out And I log in as "parent" diff --git a/user/tests/behat/reset_page.feature b/user/tests/behat/reset_page.feature index c58d1a809ee..d83105ae57f 100644 --- a/user/tests/behat/reset_page.feature +++ b/user/tests/behat/reset_page.feature @@ -20,7 +20,7 @@ Feature: Reset my profile page to default And I follow "View profile" Scenario: Add blocks to page and reset - When I press "Customise this page" + When I turn editing mode on And I add the "Latest announcements" block And I press "Reset page to default" Then I should not see "Latest announcements" diff --git a/user/tests/behat/view_preferences_page.feature b/user/tests/behat/view_preferences_page.feature index 8075576adf8..74e9e10e08d 100644 --- a/user/tests/behat/view_preferences_page.feature +++ b/user/tests/behat/view_preferences_page.feature @@ -54,7 +54,7 @@ Feature: Access to preferences page Scenario: A user with the appropriate permissions can view another user's permissions page. Given I log in as "admin" And I am on site homepage - And I follow "Turn editing on" + And I turn editing mode on And I add the "Mentees" block And I navigate to "Users > Permissions > Define roles" in site administration And I click on "Add a new role" "button" diff --git a/version.php b/version.php index febb0983bbb..87fbb7ac671 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2021092400.03; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2021092400.04; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '4.0dev (Build: 20210924)'; // Human-friendly version name