From 8c9282f5d60242942b7c9526b8fc83e009efb279 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 8 Jul 2020 13:33:34 +0800 Subject: [PATCH 1/4] MDL-69231 tests: Improve existing role generator Support definition of context levels and permissions. --- course/tests/behat/keyholder.feature | 64 ++++++++----------- enrol/self/tests/behat/key_holder.feature | 22 +++---- lib/testing/generator/data_generator.php | 41 +++++++++++- .../tests/behat/user_grade_navigation.feature | 15 +---- .../tests/behat/view_preferences_page.feature | 17 ++--- 5 files changed, 83 insertions(+), 76 deletions(-) diff --git a/course/tests/behat/keyholder.feature b/course/tests/behat/keyholder.feature index db2f6e31ad5..229cebfd82f 100644 --- a/course/tests/behat/keyholder.feature +++ b/course/tests/behat/keyholder.feature @@ -1,61 +1,53 @@ -@core @core_course @javascript +@core @core_course Feature: Keyholder role is listed as course contact As a student I need to know who the keyholder is to enrol in a course Background: - Given I log in as "admin" - And I am on site homepage + Given the following "roles" exist: + | shortname | name | archetype | context_coursecat | context_course | enrol/self:holdkey | + | keyholder | Keyholder | | 1 | 1 | allow | And the following "categories" exist: | name | category | idnumber | | Cat 1 | 0 | CAT1 | - And I navigate to "Users > Permissions > Define roles" in site administration - And I click on "Add a new role" "button" - And I click on "Continue" "button" - And I set the following fields to these values: - | Short name | keyholder | - | Custom full name | Keyholder | - | contextlevel40 | 1 | - | contextlevel50 | 1 | - | enrol/self:holdkey | 1 | - And I click on "Create this role" "button" - And I navigate to "Appearance > Courses" in site administration - And I click on "Keyholder" "checkbox" - And I press "Save changes" And the following "users" exist: - | username | firstname | lastname | email | - | teacher1 | Teacher | 1 | teacher1@example.com | - | keyholder1 | Keyholder | 1 | keyholder1@example.com | - | student1 | Student | 1 | teacher1@example.com | + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + | keyholder1 | Keyholder | 1 | keyholder1@example.com | + | student1 | Student | 1 | teacher1@example.com | And the following "courses" exist: | fullname | shortname | format | coursedisplay | numsections | category | | Course 1 | C1 | topics | 0 | 5 | CAT1 | And I add "Self enrolment" enrolment method in "Course 1" with: + | Course 1 | C1 | topics | 0 | 5 | CAT1 | + When I log in as "admin" + And I navigate to "Appearance > Courses" in site administration + And I set the following fields to these values: + | Keyholder | 1 | + And I press "Save changes" + And I am on "Course 1" course homepage + And I add "Self enrolment" enrolment method with: | Custom instance name | Test student enrolment | - | Enrolment key | letmein | + | Enrolment key | letmein | And I log out Scenario: Keyholder assigned to a course - When I log in as "admin" - And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | - | keyholder1 | C1 | keyholder | - And I log out - And I log in as "student1" + Given the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | keyholder1 | C1 | keyholder | + When I log in as "student1" And I am on site homepage And I follow "Course 1" Then I should see "Keyholder 1" Scenario: Keyholder assigned to a category - When I log in as "admin" - And the following "role assigns" exist: - | user | role | contextlevel | reference | - | keyholder1 | keyholder | Category | CAT1 | + Given the following "role assigns" exist: + | user | role | contextlevel | reference | + | keyholder1 | keyholder | Category | CAT1 | And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | - And I log out - And I log in as "student1" + | user | course | role | + | teacher1 | C1 | editingteacher | + When I log in as "student1" And I am on site homepage And I follow "Course 1" Then I should see "Keyholder 1" diff --git a/enrol/self/tests/behat/key_holder.feature b/enrol/self/tests/behat/key_holder.feature index 46b1efb0702..1186760b0de 100644 --- a/enrol/self/tests/behat/key_holder.feature +++ b/enrol/self/tests/behat/key_holder.feature @@ -5,23 +5,17 @@ Feature: Users can be defined as key holders in courses where self enrolment is I need to auto enrol me in courses Background: - Given the following "users" exist: + Given the following "roles" exist: + | shortname | name | archetype | context_course | enrol/self:holdkey | + | keyholder | Key holder | | 1 | allow | + And the following "users" exist: | username | firstname | lastname | email | | manager1 | Manager | 1 | manager1@example.com | | student1 | Student | 1 | student1@example.com | And the following "courses" exist: | fullname | shortname | format | - | Course 1 | C1 | topics | + | Course 1 | C1 | topics | And I log in as "admin" - And I navigate to "Users > Permissions > Define roles" in site administration - And I click on "Add a new role" "button" - And I click on "Continue" "button" - And I set the following fields to these values: - | Short name | keyholder | - | Custom full name | Key holder | - | contextlevel50 | 1 | - | enrol/self:holdkey | 1 | - And I click on "Create this role" "button" And I navigate to "Appearance > Courses" in site administration And I set the following fields to these values: | Key holder | 1 | @@ -38,11 +32,13 @@ Feature: Users can be defined as key holders in courses where self enrolment is | Custom instance name | Test student enrolment | | Enrolment key | moodle_rules | And I log out - And I log in as "student1" + + Scenario: The key holder name is displayed on site home page + Given I log in as "student1" And I am on "Course 1" course homepage And I should see "You should have received this enrolment key from:" And I should see "Manager 1" - And I set the following fields to these values: + When I set the following fields to these values: | Enrolment key | moodle_rules | And I press "Enrol me" Then I should see "Topic 1" diff --git a/lib/testing/generator/data_generator.php b/lib/testing/generator/data_generator.php index 1dc371438f6..c6d37ae539c 100644 --- a/lib/testing/generator/data_generator.php +++ b/lib/testing/generator/data_generator.php @@ -797,7 +797,20 @@ EOD; // If no archetype was specified we allow it to be added to all contexts, // otherwise we allow it in the archetype contexts. if (!$record['archetype']) { - $contextlevels = array_keys(context_helper::get_all_levels()); + $contextlevels = []; + $usefallback = true; + foreach (context_helper::get_all_levels() as $level => $title) { + if (array_key_exists($title, $record)) { + $usefallback = false; + if (!empty($record[$title])) { + $contextlevels[] = $level; + } + } + } + + if ($usefallback) { + $contextlevels = array_keys(context_helper::get_all_levels()); + } } else { // Copying from the archetype default rol. $archetyperoleid = $DB->get_field( @@ -810,7 +823,6 @@ EOD; set_role_contextlevels($newroleid, $contextlevels); if ($record['archetype']) { - // We copy all the roles the archetype can assign, override, switch to and view. if ($record['archetype']) { $types = array('assign', 'override', 'switch', 'view'); @@ -828,6 +840,31 @@ EOD; role_cap_duplicate($sourcerole, $newroleid); } + $allcapabilities = get_all_capabilities(); + $foundcapabilities = array_intersect(array_keys($allcapabilities), array_keys($record)); + $systemcontext = \context_system::instance(); + + $allpermissions = [ + 'inherit' => CAP_INHERIT, + 'allow' => CAP_ALLOW, + 'prevent' => CAP_PREVENT, + 'prohibit' => CAP_PROHIBIT, + ]; + + foreach ($foundcapabilities as $capability) { + $permission = $record[$capability]; + if (!array_key_exists($permission, $allpermissions)) { + throw new \coding_exception("Unknown capability permissions '{$permission}'"); + } + assign_capability( + $capability, + $allpermissions[$permission], + $newroleid, + $systemcontext->id, + true + ); + } + return $newroleid; } diff --git a/user/tests/behat/user_grade_navigation.feature b/user/tests/behat/user_grade_navigation.feature index 192fd5942c5..dda9119b3e0 100644 --- a/user/tests/behat/user_grade_navigation.feature +++ b/user/tests/behat/user_grade_navigation.feature @@ -59,22 +59,13 @@ Feature: The student can navigate to their grades page and user grade report. Then I should see "My badges from Acceptance test site web site" Scenario: Log in as a parent and view a childs grades. + Given the following "roles" exist: + | shortname | name | archetype | context_user | moodle/user:editprofile | moodle/user:viewalldetails | moodle/user:viewuseractivitiesreport | moodle/user:viewdetails | + | Parent | Parent | | 1 | allow | allow | allow | allow | When I log in as "admin" And I am on site homepage 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" - And I click on "Continue" "button" - And I set the following fields to these values: - | Short name | Parent | - | Custom full name | Parent | - | contextlevel30 | 1 | - | moodle/user:editprofile | 1 | - | moodle/user:viewalldetails | 1 | - | moodle/user:viewuseractivitiesreport | 1 | - | moodle/user:viewdetails | 1 | - And I click on "Create this role" "button" And I am on the "student1" "user > profile" page And I click on "Preferences" "link" in the ".profile_tree" "css_element" And I follow "Assign roles relative to this user" diff --git a/user/tests/behat/view_preferences_page.feature b/user/tests/behat/view_preferences_page.feature index 681738b73b8..64489442ee2 100644 --- a/user/tests/behat/view_preferences_page.feature +++ b/user/tests/behat/view_preferences_page.feature @@ -52,22 +52,13 @@ Feature: Access to preferences page Then I should see "Preferences" in the "region-main" "region" Scenario: A user with the appropriate permissions can view another user's permissions page. - Given I log in as "admin" + Given the following "roles" exist: + | shortname | name | archetype | context_user | moodle/user:editprofile | moodle/user:viewalldetails | moodle/user:viewuseractivitiesreport | moodle/user:viewdetails | + | Parent | Parent | | 1 | allow | allow | allow | allow | + When I log in as "admin" And I am on site homepage 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" - And I click on "Continue" "button" - And I set the following fields to these values: - | Short name | Parent | - | Custom full name | Parent | - | contextlevel30 | 1 | - | moodle/user:editprofile | 1 | - | moodle/user:viewalldetails | 1 | - | moodle/user:viewuseractivitiesreport | 1 | - | moodle/user:viewdetails | 1 | - And I click on "Create this role" "button" And I am on the "student1" "user > profile" page And I click on "Preferences" "link" in the ".profile_tree" "css_element" And I follow "Assign roles relative to this user" From 1a4303c9bc12c547938549f9ac0b8a4fbec708ad Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 9 Jul 2020 07:47:01 +0800 Subject: [PATCH 2/4] MDL-69231 tests: Add role capability setting generator --- .../tests/behat/edit_permissions.feature | 5 +- lib/behat/classes/behat_core_generator.php | 23 +++++++++ lib/testing/generator/data_generator.php | 42 ++++++++++++++++ lib/tests/behat/behat_data_generators.php | 2 +- lib/tests/behat/behat_permissions.php | 49 ++++++++++++++----- 5 files changed, 107 insertions(+), 14 deletions(-) diff --git a/admin/tool/behat/tests/behat/edit_permissions.feature b/admin/tool/behat/tests/behat/edit_permissions.feature index e70832fd6d4..46b0a3ad449 100644 --- a/admin/tool/behat/tests/behat/edit_permissions.feature +++ b/admin/tool/behat/tests/behat/edit_permissions.feature @@ -21,12 +21,15 @@ Feature: Edit capabilities Scenario: Default system capabilities modification Given I log in as "admin" - And I set the following system permissions of "Teacher" role: + When I navigate to "Users > Permissions > Define roles" in site administration + And I click on "Edit Teacher role" "link" + And I fill the capabilities form with the following permissions: | capability | permission | | block/mnet_hosts:myaddinstance | Allow | | moodle/site:messageanyuser | Inherit | | moodle/grade:managesharedforms | Prevent | | moodle/course:request | Prohibit | + And I press "Save changes" When I follow "Edit Teacher role" Then "block/mnet_hosts:myaddinstance" capability has "Allow" permission And "moodle/site:messageanyuser" capability has "Not set" permission diff --git a/lib/behat/classes/behat_core_generator.php b/lib/behat/classes/behat_core_generator.php index 8c7fdfb2f0a..ed447d97787 100644 --- a/lib/behat/classes/behat_core_generator.php +++ b/lib/behat/classes/behat_core_generator.php @@ -156,6 +156,12 @@ class behat_core_generator extends behat_generator_base { 'datagenerator' => 'role', 'required' => ['shortname'], ], + 'role capabilities' => [ + 'singular' => 'role capability', + 'datagenerator' => 'role_capability', + 'required' => ['role'], + 'switchids' => ['role' => 'roleid'], + ], 'grade categories' => [ 'singular' => 'grade category', 'datagenerator' => 'grade_category', @@ -724,6 +730,23 @@ class behat_core_generator extends behat_generator_base { $this->datagenerator->create_role($data); } + /** + * Assign capabilities to a role. + * + * @param array $data + */ + protected function process_role_capability($data): void { + // We require the user to fill the role shortname. + if (empty($data['roleid'])) { + throw new Exception('\'role capability\' requires the field \'roleid\' to be specified'); + } + + $roleid = $data['roleid']; + unset($data['roleid']); + + $this->datagenerator->create_role_capability($roleid, $data, \context_system::instance()); + } + /** * Adds members to cohorts * diff --git a/lib/testing/generator/data_generator.php b/lib/testing/generator/data_generator.php index c6d37ae539c..1f7a752547a 100644 --- a/lib/testing/generator/data_generator.php +++ b/lib/testing/generator/data_generator.php @@ -868,6 +868,48 @@ EOD; return $newroleid; } + /** + * Set role capabilities for the specified role. + * + * @param int $roleid The Role to set capabilities for + * @param array $rolecapabilities The list of capability =>permission to set for this role + * @param context $context The context to apply this capability to + */ + public function create_role_capability(int $roleid, array $rolecapabilities, context $context = null): void { + // Map the capabilities into human-readable names. + $allpermissions = [ + 'inherit' => CAP_INHERIT, + 'allow' => CAP_ALLOW, + 'prevent' => CAP_PREVENT, + 'prohibit' => CAP_PROHIBIT, + ]; + + // Fetch all capabilities to check that they exist. + $allcapabilities = get_all_capabilities(); + foreach ($rolecapabilities as $capability => $permission) { + if ($permission === '') { + // Allow items to be skipped. + continue; + } + + if (!array_key_exists($capability, $allcapabilities)) { + throw new \coding_exception("Unknown capability '{$capability}'"); + } + + if (!array_key_exists($permission, $allpermissions)) { + throw new \coding_exception("Unknown capability permissions '{$permission}'"); + } + + assign_capability( + $capability, + $allpermissions[$permission], + $roleid, + $context->id, + true + ); + } + } + /** * Create a tag. * diff --git a/lib/tests/behat/behat_data_generators.php b/lib/tests/behat/behat_data_generators.php index b803b8caa16..c95b24b6f3f 100644 --- a/lib/tests/behat/behat_data_generators.php +++ b/lib/tests/behat/behat_data_generators.php @@ -121,7 +121,7 @@ class behat_data_generators extends behat_base { } /** - * Creates the specified element. + * Creates the specified (singular) element. * * See the class comment for an overview. * diff --git a/lib/tests/behat/behat_permissions.php b/lib/tests/behat/behat_permissions.php index ec41faeb4a0..8c962e72d54 100644 --- a/lib/tests/behat/behat_permissions.php +++ b/lib/tests/behat/behat_permissions.php @@ -47,22 +47,47 @@ class behat_permissions extends behat_base { * @param TableNode $table */ public function i_set_the_following_system_permissions_of_role($rolename, $table) { + // Applied in the System context. + $context = \context_system::instance(); - $parentnodes = get_string('users', 'admin') . ' > ' . - get_string('permissions', 'role'); + // Translate the specified rolename into a role. + $rolenames = role_get_names($context); + $matched = array_filter($rolenames, function($role) use ($rolename) { + return ($role->localname === $rolename) || ($role->shortname === $rolename) || ($role->description === $rolename); + }); - // Go to home page. - $this->execute("behat_general::i_am_on_homepage"); + if (count($matched) === 0) { + throw new ExpectationException("Unable to find a role with name '{$rolename}'", $this->getSession()); + } else if (count($matched) > 1) { + throw new ExpectationException("Multiple roles matched '{$rolename}'", $this->getSession()); + } - // Navigate to course management page via navigation block. - $this->execute("behat_navigation::i_navigate_to_in_site_administration", - array($parentnodes . ' > ' . get_string('defineroles', 'role')) + $role = reset($matched); + + $permissionmap = [ + get_string('inherit', 'role') => 'inherit', + get_string('allow', 'role') => 'allow', + get_string('prevent', 'role') => 'prevent', + get_string('prohibit', 'role') => 'prohibit', + ]; + + $columns = ['role']; + $newtabledata = [$role->shortname]; + foreach ($table as $data) { + $columns[] = $data['capability']; + $newtabledata[] = $permissionmap[$data['permission']]; + } + + $this->execute( + 'behat_data_generators::the_following_entities_exist', + [ + 'role capabilities', + new TableNode([ + 0 => $columns, + 1 => $newtabledata, + ]) + ] ); - - $this->execute("behat_general::click_link", "Edit " . $this->escape($rolename) . " role"); - $this->execute("behat_permissions::i_fill_the_capabilities_form_with_the_following_permissions", $table); - - $this->execute('behat_forms::press_button', get_string('savechanges')); } /** From aa2fc4048ef31dbdcdf4c64e7f196ebb1a822db6 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 10 Jul 2020 12:11:09 +0800 Subject: [PATCH 3/4] MDL-69231 behat: Update tests to use new generator --- .../tool/lp/tests/behat/plan_workflow.feature | 29 +++++----- .../monitor/tests/behat/subscription.feature | 7 ++- .../policy/tests/behat/acceptances.feature | 54 ++++++++----------- .../behat/restrict_available_blocks.feature | 8 +-- .../tests/behat/create_course.feature | 22 ++++---- course/tests/behat/course_browsing.feature | 18 +++---- course/tests/behat/course_creation.feature | 12 ++--- course/tests/behat/course_request.feature | 16 +++--- course/tests/behat/coursetags.feature | 7 ++- .../tests/behat/navigate_course_list.feature | 8 ++- .../restrict_available_activities.feature | 8 +-- course/tests/behat/role_renaming.feature | 8 ++- .../grader/tests/behat/switch_views.feature | 16 +++--- .../report/user/tests/behat/user_view.feature | 9 ++-- group/tests/behat/auto_creation.feature | 8 ++- group/tests/behat/create_groups.feature | 7 ++- group/tests/behat/delete_groups.feature | 6 +-- group/tests/behat/update_groups.feature | 5 +- .../behat/bulk_remove_submissions.feature | 46 ++++++++++------ .../tests/behat/remove_submission.feature | 8 ++- mod/feedback/tests/behat/anonymous.feature | 16 +++--- .../tests/behat/non_anonymous.feature | 8 ++- .../behat/separate_group_discussions.feature | 8 --- .../tests/behat/link_to_gradebook.feature | 7 ++- my/tests/behat/reset_all_pages.feature | 9 ++-- .../behat/restrict_available_blocks.feature | 13 +++-- tag/tests/behat/edit_tag.feature | 5 +- tag/tests/behat/flag_tags.feature | 10 ++-- user/tests/behat/enrol_cohort_list.feature | 5 +- user/tests/behat/filter_participants.feature | 5 +- user/tests/behat/view_full_profile.feature | 7 ++- 31 files changed, 173 insertions(+), 222 deletions(-) diff --git a/admin/tool/lp/tests/behat/plan_workflow.feature b/admin/tool/lp/tests/behat/plan_workflow.feature index 29d49196ad6..abb075449a8 100644 --- a/admin/tool/lp/tests/behat/plan_workflow.feature +++ b/admin/tool/lp/tests/behat/plan_workflow.feature @@ -15,6 +15,18 @@ Feature: Manage plan workflow | usermanageowndraftplan | User manage own draft plan role | user | | usermanageownplan | User manage own plan role | user | | manageplan | Manager all plans role | manager | + And the following "role capabilities" exist: + | role | moodle/competency:planmanageowndraft | + | usermanageowndraftplan | allow | + | usermanageownplan | allow | + | manageplan | allow | + And the following "role capabilities" exist: + | role | moodle/competency:planmanageown | + | usermanageownplan | allow | + | manageplan | allow | + And the following "role capabilities" exist: + | role | moodle/competency:planmanage | moodle/competency:planview | moodle/competency:planreview | moodle/competency:planrequestreview | + | manageplan | allow | allow | allow | allow | And the following "role assigns" exist: | user | role | contextlevel | reference | | user1 | usermanageowndraftplan | System | | @@ -40,23 +52,6 @@ Feature: Manage plan workflow And the following "blocks" exist: | blockname | contextlevel | reference | pagetypepattern | defaultregion | | lp | System | 1 | my-index | content | - And I log in as "admin" - And I set the following system permissions of "User manage own draft plan role" role: - | capability | permission | - | moodle/competency:planmanageowndraft | Allow | - And I set the following system permissions of "User manage own plan role" role: - | capability | permission | - | moodle/competency:planmanageowndraft | Allow | - | moodle/competency:planmanageown | Allow | - And I set the following system permissions of "Manager all plans role" role: - | capability | permission | - | moodle/competency:planmanage | Allow | - | moodle/competency:planmanagedraft | Allow | - | moodle/competency:planmanageowndraft | Allow | - | moodle/competency:planview | Allow | - | moodle/competency:planreview | Allow | - | moodle/competency:planrequestreview | Allow | - And I log out Scenario: User can manages his own plan draft Given I log in as "user1" diff --git a/admin/tool/monitor/tests/behat/subscription.feature b/admin/tool/monitor/tests/behat/subscription.feature index 8007fd5cfaa..aee912a3f16 100644 --- a/admin/tool/monitor/tests/behat/subscription.feature +++ b/admin/tool/monitor/tests/behat/subscription.feature @@ -169,10 +169,9 @@ Feature: tool_monitor_subscriptions And I should not see "You can manage rules the from the Event monitoring rules page." Scenario: No manage rules link when user does not have permission - Given I log in as "admin" - And I set the following system permissions of "Non-editing teacher" role: - | tool/monitor:managerules | Prohibit | - And I log out + Given the following "role capability" exists: + | role | Non-editing teacher | + | tool/monitor:managerules | Prohibit | And I log in as "teacher1" And I follow "Preferences" in the user menu And I follow "Event monitoring" diff --git a/admin/tool/policy/tests/behat/acceptances.feature b/admin/tool/policy/tests/behat/acceptances.feature index fd54462c7b8..4826fde89e4 100644 --- a/admin/tool/policy/tests/behat/acceptances.feature +++ b/admin/tool/policy/tests/behat/acceptances.feature @@ -48,11 +48,9 @@ Feature: Viewing acceptances reports and accepting on behalf of other users And "Pending" "text" should exist in the "User Two" "table_row" Scenario: Agree on behalf of another user as a manager, single policy, javascript off - Given I log in as "admin" - And I set the following system permissions of "Manager" role: - | capability | permission | - | tool/policy:acceptbehalf | Allow | - And I log out + Given the following "role capability" exists: + | role | manager | + | tool/policy:acceptbehalf | allow | When I log in as "manager" And I press "Next" And I set the field "I agree to the This site policy" to "1" @@ -73,11 +71,9 @@ Feature: Viewing acceptances reports and accepting on behalf of other users @javascript Scenario: Agree on behalf of another user as a manager, single policy, javascript on - Given I log in as "admin" - And I set the following system permissions of "Manager" role: - | capability | permission | - | tool/policy:acceptbehalf | Allow | - And I log out + Given the following "role capabilities" exist: + | role | manager | + | tool/policy:acceptbehalf | allow | When I log in as "manager" And I press "Next" And I set the field "I agree to the This site policy" to "1" @@ -135,13 +131,13 @@ Feature: Viewing acceptances reports and accepting on behalf of other users And "Pending" "text" should exist in the "This privacy policy" "table_row" Scenario: Agree on behalf of another user as a manager, multiple policies, javascript off - Given I log in as "admin" + Given the following "role capability" exists: + | role | manager | + | tool/policy:acceptbehalf | allow | + And I log in as "admin" And I navigate to "Users > Privacy and policies > Manage policies" in site administration And I click on "Set status to \"Active\"" "link" in the "This privacy policy" "table_row" And I press "Continue" - And I set the following system permissions of "Manager" role: - | capability | permission | - | tool/policy:acceptbehalf | Allow | And I log out When I log in as "manager" And I press "Next" @@ -167,14 +163,14 @@ Feature: Viewing acceptances reports and accepting on behalf of other users @javascript Scenario: Agree on behalf of another user as a manager, multiple policies, javascript on + Given the following "role capability" exists: + | role | manager | + | tool/policy:acceptbehalf | allow | Given I log in as "admin" And I navigate to "Users > Privacy and policies > Manage policies" in site administration And I click on "Actions" "link_or_button" in the "This privacy policy" "table_row" And I click on "Set status to \"Active\"" "link" in the "This privacy policy" "table_row" And I press "Activate" - And I set the following system permissions of "Manager" role: - | capability | permission | - | tool/policy:acceptbehalf | Allow | And I log out When I log in as "manager" And I press "Next" @@ -215,11 +211,9 @@ Feature: Viewing acceptances reports and accepting on behalf of other users And I should not see "Policies and agreements" Scenario: Policies and agreements profile link visible also for users who can access on behalf of others - Given I log in as "admin" - And I set the following system permissions of "Manager" role: - | capability | permission | - | tool/policy:acceptbehalf | Allow | - And I log out + Given the following "role capability" exists: + | role | manager | + | tool/policy:acceptbehalf | allow | And I log in as "manager" And I press "Next" And I set the field "I agree to the This site policy" to "1" @@ -231,11 +225,9 @@ Feature: Viewing acceptances reports and accepting on behalf of other users Then I should see "Policies and agreements" Scenario: Agree on behalf of another user as an admin who is logged in as a manager - Given I log in as "admin" - And I set the following system permissions of "Manager" role: - | capability | permission | - | tool/policy:acceptbehalf | Allow | - And I log out + Given the following "role capability" exists: + | role | manager | + | tool/policy:acceptbehalf | allow | When I log in as "manager" And I press "Next" And I set the field "I agree to the This site policy" to "1" @@ -261,14 +253,14 @@ Feature: Viewing acceptances reports and accepting on behalf of other users @javascript Scenario: Bulk agree on behalf of another users as a manager, multiple policies, javascript on - Given I log in as "admin" + Given the following "role capability" exists: + | role | manager | + | tool/policy:acceptbehalf | allow | + And I log in as "admin" And I navigate to "Users > Privacy and policies > Manage policies" in site administration And I click on "Actions" "link_or_button" in the "This privacy policy" "table_row" And I click on "Set status to \"Active\"" "link" in the "This privacy policy" "table_row" And I press "Activate" - And I set the following system permissions of "Manager" role: - | capability | permission | - | tool/policy:acceptbehalf | Allow | And I log out When I log in as "manager" And I press "Next" diff --git a/blocks/tests/behat/restrict_available_blocks.feature b/blocks/tests/behat/restrict_available_blocks.feature index 6ec366113e1..56cd80f65d3 100644 --- a/blocks/tests/behat/restrict_available_blocks.feature +++ b/blocks/tests/behat/restrict_available_blocks.feature @@ -24,10 +24,12 @@ Feature: Allowed blocks controls And I should see "Course completion status" in the "Course completion status" "block" Scenario: Blocks can not be added when the admin restricts the permissions + Given the following "role capability" exists: + | role | editingteacher | + | block/activity_modules:addinstance | prohibit | Given I log in as "admin" - And I set the following system permissions of "Teacher" role: - | block/activity_modules:addinstance | Prohibit | - And I am on the "Course 1" "permissions" page + And I am on "Course 1" course homepage + And I navigate to "Users > Permissions" in current page administration And I override the system permissions of "Teacher" role with: | block/completionstatus:addinstance | Prohibit | And I log out diff --git a/course/format/singleactivity/tests/behat/create_course.feature b/course/format/singleactivity/tests/behat/create_course.feature index 6eee07ff1cf..abce67e9eca 100644 --- a/course/format/singleactivity/tests/behat/create_course.feature +++ b/course/format/singleactivity/tests/behat/create_course.feature @@ -14,19 +14,17 @@ Feature: Courses can be created in Single Activity mode And the following "system role assigns" exist: | user | role | contextlevel | | kevin | creator | System | - And I log in as "admin" - And I set the following system permissions of "Creator" role: - | capability | permission | - | moodle/course:create | Allow | - | moodle/course:update | Allow | - | moodle/course:manageactivities | Allow | - | moodle/course:viewparticipants | Allow | - | moodle/role:assign | Allow | - | mod/quiz:addinstance | Allow | - And I log out - And I log in as "kevin" + And the following "role capability" exists: + | role | creator | + | moodle/course:create | allow | + | moodle/course:update | allow | + | moodle/course:manageactivities | allow | + | moodle/course:viewparticipants | allow | + | moodle/role:assign | allow | + | mod/quiz:addinstance | allow | + When I log in as "kevin" And I am on site homepage - When I press "Add a new course" + And I press "Add a new course" And I set the following fields to these values: | Course full name | My first course | | Course short name | myfirstcourse | diff --git a/course/tests/behat/course_browsing.feature b/course/tests/behat/course_browsing.feature index e4bb0c2e716..abacc36535c 100644 --- a/course/tests/behat/course_browsing.feature +++ b/course/tests/behat/course_browsing.feature @@ -17,24 +17,20 @@ Feature: Restricting access to course lists | English Y1 | ENG1 | ENG | | English Y2 | ENG2 | ENG | | Humanities Y1 | HUM2 | MISC | - Given the following "users" exist: + And the following "users" exist: | username | firstname | lastname | email | | user0 | User | Z | user0@example.com | | userb | User | B | userb@example.com | | usere | User | E | usere@example.com | - Given the following "roles" exist: + And the following "roles" exist: | name | shortname | description | archetype | | Category viewer | coursebrowse | My custom role 1 | | + And the following "role capabilities" exist: + | role | moodle/category:viewcourselist | + | user | prevent | + | guest | prevent | + | coursebrowse | allow | Given I log in as "admin" - And I set the following system permissions of "Authenticated user" role: - | capability | permission | - | moodle/category:viewcourselist | Prevent | - And I set the following system permissions of "Guest" role: - | capability | permission | - | moodle/category:viewcourselist | Prevent | - And I set the following system permissions of "Category viewer" role: - | capability | permission | - | moodle/category:viewcourselist | Allow | And I am on site homepage And I turn editing mode on And the following config values are set as admin: diff --git a/course/tests/behat/course_creation.feature b/course/tests/behat/course_creation.feature index f38714e9346..8deb2a58b35 100644 --- a/course/tests/behat/course_creation.feature +++ b/course/tests/behat/course_creation.feature @@ -75,13 +75,11 @@ Feature: Managers can create courses And the following "system role assigns" exist: | user | role | contextlevel | | kevin | creator | System | - And I log in as "admin" - And I set the following system permissions of "Creator" role: - | capability | permission | - | moodle/course:create | Allow | - | moodle/course:manageactivities | Allow | - | moodle/course:viewparticipants | Allow | - And I log out + And the following "role capability" exists: + | role | creator | + | moodle/course:create | allow | + | moodle/course:manageactivities | allow | + | moodle/course:viewparticipants | allow | And I log in as "kevin" And I am on site homepage When I press "Add a new course" diff --git a/course/tests/behat/course_request.feature b/course/tests/behat/course_request.feature index 89c36c5ae65..8da4d59fdf9 100644 --- a/course/tests/behat/course_request.feature +++ b/course/tests/behat/course_request.feature @@ -17,11 +17,9 @@ Feature: Users can request and approve courses | user2 | Acceptance test site | manager | And the following config values are set as admin: | lockrequestcategory | 1 | - Given I log in as "admin" - And I set the following system permissions of "Authenticated user" role: - | capability | permission | - | moodle/course:request | Allow | - And I log out + And the following "role capability" exists: + | role | user | + | moodle/course:request | allow | When I log in as "user1" And I am on course index And I click on "More actions" "button" @@ -71,11 +69,9 @@ Feature: Users can request and approve courses | user1 | courserequestor | Category | ENG | | user2 | manager | Category | SCI | | user3 | manager | Category | ENG | - Given I log in as "admin" - And I set the following system permissions of "Course requestor" role: - | capability | permission | - | moodle/course:request | Allow | - And I log out + And the following "role capability" exists: + | role | courserequestor | + | moodle/course:request | allow | And I log in as "user1" And I am on course index And I follow "English category" diff --git a/course/tests/behat/coursetags.feature b/course/tests/behat/coursetags.feature index fa29d31e985..a681f0d5fc0 100644 --- a/course/tests/behat/coursetags.feature +++ b/course/tests/behat/coursetags.feature @@ -68,10 +68,9 @@ Feature: Tagging courses And I log out Scenario: User can set course tags using separate form - Given I log in as "admin" - And I set the following system permissions of "Non-editing teacher" role: - | moodle/course:tag | Allow | - And I log out + Given the following "role capability" exists: + | role | Non-editing teacher | + | moodle/course:tag | Allow | When I log in as "teacher2" And I am on "Course 1" course homepage And I navigate to "Course tags" in current page administration diff --git a/course/tests/behat/navigate_course_list.feature b/course/tests/behat/navigate_course_list.feature index 451360bd15a..3e8a94e0a39 100644 --- a/course/tests/behat/navigate_course_list.feature +++ b/course/tests/behat/navigate_course_list.feature @@ -62,11 +62,9 @@ Feature: Browse course list and return back from enrolment page And the following "activities" exist: | activity | name | intro | course | idnumber | | choice | Test choice | Test choice description | C1 | choice1 | - And I log in as "admin" - And I set the following system permissions of "Non-enrolled" role: - | capability | permission | - | moodle/course:view | Allow | - And I log out + And the following "role capability" exists: + | role | custom1 | + | moodle/course:view | allow | When I log in as "user1" And I am on course index And I follow "Category 1" diff --git a/course/tests/behat/restrict_available_activities.feature b/course/tests/behat/restrict_available_activities.feature index 50a5439925b..17fd30f729f 100644 --- a/course/tests/behat/restrict_available_activities.feature +++ b/course/tests/behat/restrict_available_activities.feature @@ -31,9 +31,11 @@ Feature: Restrict activities availability @javascript @skip_chrome_zerosize Scenario: Activities can not be added when the admin restricts the permissions Given I log in as "admin" - And I set the following system permissions of "Teacher" role: - | mod/chat:addinstance | Prohibit | - And I am on the "Course 1" "permissions" page + And the following "role capability" exists: + | role | editingteacher | + | mod/chat:addinstance | prohibit | + And I am on "Course 1" course homepage + And I navigate to "Users > Permissions" in current page administration And I override the system permissions of "Teacher" role with: | mod/glossary:addinstance | Prohibit | And I log out diff --git a/course/tests/behat/role_renaming.feature b/course/tests/behat/role_renaming.feature index b650a347d84..a19a7328023 100644 --- a/course/tests/behat/role_renaming.feature +++ b/course/tests/behat/role_renaming.feature @@ -39,11 +39,9 @@ Feature: Rename roles in a course And I should not see "Learner (Student)" in the "Student 1" "table_row" Scenario: Ability to rename roles can be prevented - Given I log in as "admin" - And I set the following system permissions of "Teacher" role: - | capability | permission | - | moodle/course:renameroles | Inherit | - And I follow "Log out" + Given the following "role capability" exists: + | role | editingteacher | + | moodle/course:renameroles | inherit | When I log in as "teacher1" And I am on "Course 1" course homepage And I navigate to "Settings" in current page administration diff --git a/grade/report/grader/tests/behat/switch_views.feature b/grade/report/grader/tests/behat/switch_views.feature index df7912bb8d6..319f6a7ef26 100644 --- a/grade/report/grader/tests/behat/switch_views.feature +++ b/grade/report/grader/tests/behat/switch_views.feature @@ -71,19 +71,15 @@ Feature: We can change what we are viewing on the grader report @javascript @skip_chrome_zerosize Scenario: Minimise the grader report containing hidden activities without the 'moodle/grade:viewhidden' capability + Given the following "role capability" exists: + | role | Teacher | + | moodle/grade:viewhidden | Prevent | 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 log out - And I log in as "admin" - And I set the following system permissions of "Teacher" role: - | capability | permission | - | moodle/grade:viewhidden | Prevent | - And I log out - 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 should see "Test assignment name 1" in the "user-grades" "table" + Then I should see "Test assignment name 1" in the "user-grades" "table" And I should see "Test assignment name 2" in the "user-grades" "table" And I should see "Manual grade" And I should see "Course total" @@ -100,8 +96,8 @@ Feature: We can change what we are viewing on the grader report | -1- | -1- | -3- | | Student 1 | student1@example.com | 105.71 | And I click on grade item menu "Course 1" of type "course" on "grader" page - And I click on "Show grades only" "link" - And I should see "Test assignment name 1" in the "user-grades" "table" + When I click on "Show grades only" "link" + Then I should see "Test assignment name 1" in the "user-grades" "table" And I should see "Test assignment name 2" in the "user-grades" "table" And I should see "Manual grade" And I should not see "Course total" diff --git a/grade/report/user/tests/behat/user_view.feature b/grade/report/user/tests/behat/user_view.feature index 87b949f4089..cc9e95aab4b 100644 --- a/grade/report/user/tests/behat/user_view.feature +++ b/grade/report/user/tests/behat/user_view.feature @@ -179,12 +179,9 @@ Feature: View the user report as the student will see it | Test assignment six | Scenario: View the report as the student from both the teachers and students perspective when the student can view hidden - Given I log out - And I log in as "admin" - And I set the following system permissions of "Student" role: - | capability | permission | - | moodle/grade:viewhidden | Allow | - And I log out + Given the following "role capability" exists: + | role | student | + | moodle/grade:viewhidden | Allow | And I am on the "C1" "Course" page logged in as "teacher1" And I navigate to "Setup > Course grade settings" in the course gradebook And I set the field with xpath "//select[@name='report_user_showtotalsifcontainhidden']" to "Show totals excluding hidden items" diff --git a/group/tests/behat/auto_creation.feature b/group/tests/behat/auto_creation.feature index ab49a212e74..b1523c5467c 100644 --- a/group/tests/behat/auto_creation.feature +++ b/group/tests/behat/auto_creation.feature @@ -164,11 +164,9 @@ Feature: Automatic creation of groups Scenario: Do not display 'Include only active enrolments' if user does not have the 'moodle/course:viewsuspendedusers' capability Given I log out - And I log in as "admin" - And I set the following system permissions of "Teacher" role: - | capability | permission | - | moodle/course:viewsuspendedusers | Prevent | - And I log out + And the following "role capability" exists: + | role | editingteacher | + | moodle/course:viewsuspendedusers | prevent | And I log in as "teacher1" And I am on the "Course 1" "groups" page When I press "Auto-create groups" diff --git a/group/tests/behat/create_groups.feature b/group/tests/behat/create_groups.feature index 359d502c341..c9da9840fad 100644 --- a/group/tests/behat/create_groups.feature +++ b/group/tests/behat/create_groups.feature @@ -99,10 +99,9 @@ Feature: Organize students into groups And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | - And I log in as "admin" - And I set the following system permissions of "Teacher" role: - | moodle/course:changeidnumber | Prevent | - And I log out + And the following "role capability" exists: + | role | editingteacher | + | moodle/course:changeidnumber | prevent | And I log in as "teacher1" And I am on the "Course 1" "groups" page When I press "Create group" diff --git a/group/tests/behat/delete_groups.feature b/group/tests/behat/delete_groups.feature index 19da124b8fe..553b0972b4f 100644 --- a/group/tests/behat/delete_groups.feature +++ b/group/tests/behat/delete_groups.feature @@ -58,9 +58,9 @@ Feature: Automatic deletion of groups and groupings @javascript @skip_chrome_zerosize Scenario: Delete groups and groupings with and without ID numbers without the 'moodle/course:changeidnumber' capability Given I log out - And I log in as "admin" - And I set the following system permissions of "Teacher" role: - | moodle/course:changeidnumber | Prevent | + And the following "role capability" exists: + | role | Teacher | + | moodle/course:changeidnumber | Prevent | And I log out And I log in as "teacher1" And I am on the "Course 1" "groups" page diff --git a/group/tests/behat/update_groups.feature b/group/tests/behat/update_groups.feature index 878c5baa5b7..d59f912b875 100644 --- a/group/tests/behat/update_groups.feature +++ b/group/tests/behat/update_groups.feature @@ -65,10 +65,9 @@ Feature: Automatic updating of groups and groupings @javascript @skip_chrome_zerosize Scenario: Update groups and groupings with ID numbers without the 'moodle/course:changeidnumber' capability Given I log out - And I log in as "admin" - And I set the following system permissions of "Teacher" role: + And the following "role capability" exists: + | role | Teacher | | moodle/course:changeidnumber | Prevent | - And I log out And I log in as "teacher1" And I am on the "Course 1" "groups" page And I set the field "groups" to "Group (with ID)" diff --git a/mod/assign/tests/behat/bulk_remove_submissions.feature b/mod/assign/tests/behat/bulk_remove_submissions.feature index 98e789a4c5b..30ef6813b55 100644 --- a/mod/assign/tests/behat/bulk_remove_submissions.feature +++ b/mod/assign/tests/behat/bulk_remove_submissions.feature @@ -35,12 +35,9 @@ Feature: Bulk remove submissions | assign | user | onlinetext | | Test assignment name | student1 | I'm the student1 submission | | Test assignment name | student2 | I'm the student2 submission | - And I log in as "admin" - And I set the following system permissions of "Teacher" role: - | capability | permission | - | mod/assign:editothersubmission | Allow | - And I log out - + And the following "role capability" exists: + | role | Teacher | + | mod/assign:editothersubmission | Allow | And I am on the "Test assignment name" Activity page logged in as teacher1 And I follow "View all submissions" And I should see "I'm the student1 submission" @@ -96,13 +93,30 @@ Feature: Bulk remove submissions | assign | user | onlinetext | | Test assignment name | student1 | I'm the student1 submission | | Test assignment name | student2 | I'm the student2 submission | + And the following "role capability" exists: + | role | Teacher | + | mod/assign:editothersubmission | Allow | + And I am on the "Test assignment name" Activity page logged in as teacher1 + And I follow "View all submissions" - And I log in as "admin" - And I set the following system permissions of "Teacher" role: - | capability | permission | - | mod/assign:editothersubmission | Allow | - And I log out - + @javascript + Scenario: Notification should be displayed when non-group users are selected for submission bulk removal + in separate group mode + Given the following "activity" exists: + | activity | assign | + | course | C1 | + | name | Test assignment name | + | assignsubmission_onlinetext_enabled | 1 | + | assignsubmission_file_enabled | 0 | + | groupmode | 1 | + | submissiondrafts | 0 | + And the following "mod_assign > submissions" exist: + | assign | user | onlinetext | + | Test assignment name | student1 | I'm the student1 submission | + | Test assignment name | student2 | I'm the student2 submission | + Given the following "role capability" exists: + | role | Teacher | + | mod/assign:editothersubmission | Allow | And I am on the "Test assignment name" Activity page logged in as teacher1 And I follow "View all submissions" And I should see "I'm the student1 submission" @@ -135,11 +149,9 @@ Feature: Bulk remove submissions | assign | user | onlinetext | | Test assignment name | student1 | I'm the student1 submission | | Test assignment name | student2 | I'm the student2 submission | - And I log in as "admin" - And I set the following system permissions of "Teacher" role: - | capability | permission | - | mod/assign:editothersubmission | Allow | - And I log out + And the following "role capability" exists: + | role | Teacher | + | mod/assign:editothersubmission | Allow | And I am on the "Test assignment name" Activity page logged in as teacher1 And I follow "View all submissions" diff --git a/mod/assign/tests/behat/remove_submission.feature b/mod/assign/tests/behat/remove_submission.feature index aade1877a97..1e8ae35d148 100644 --- a/mod/assign/tests/behat/remove_submission.feature +++ b/mod/assign/tests/behat/remove_submission.feature @@ -5,13 +5,11 @@ Feature: Remove a submission I need to remove a student submission at any time Background: - Given I log in as "admin" - And I set the following system permissions of "Teacher" role: - | capability | permission | - | mod/assign:editothersubmission | Allow | + Given the following "role capability" exists: + | role | Teacher | + | mod/assign:editothersubmission | Allow | And I set the following administration settings values: | Enable timed assignments | 1 | - And I log out And the following "courses" exist: | fullname | shortname | category | groupmode | | Course 1 | C1 | 0 | 0 | diff --git a/mod/feedback/tests/behat/anonymous.feature b/mod/feedback/tests/behat/anonymous.feature index 228b15bec80..5b1dae6ba51 100644 --- a/mod/feedback/tests/behat/anonymous.feature +++ b/mod/feedback/tests/behat/anonymous.feature @@ -58,11 +58,9 @@ Feature: Anonymous feedback @javascript Scenario: Complete anonymous feedback and view analysis on the front page as an authenticated user - And I log in as "admin" - And I set the following system permissions of "Authenticated user on site home" role: - | capability | permission | - | mod/feedback:viewanalysepage | Allow | - And I log out + Given the following "role capability" exists: + | role | Authenticated user on frontpage | + | mod/feedback:viewanalysepage | Allow | And I log in as "user1" And I am on site homepage When I follow "Site feedback" @@ -118,11 +116,9 @@ Feature: Anonymous feedback Scenario: Complete fully anonymous feedback and view analyze on the front page as a guest Given the following config values are set as admin: | feedback_allowfullanonymous | 1 | - And I log in as "admin" - And I set the following system permissions of "Guest" role: - | capability | permission | - | mod/feedback:viewanalysepage | Allow | - And I log out + And the following "role capability" exists: + | role | Guest | + | mod/feedback:viewanalysepage | Allow | When I follow "Site feedback" And I should not see "Preview questions" And I follow "Answer the questions" diff --git a/mod/feedback/tests/behat/non_anonymous.feature b/mod/feedback/tests/behat/non_anonymous.feature index 0e329babc10..30862a87b04 100644 --- a/mod/feedback/tests/behat/non_anonymous.feature +++ b/mod/feedback/tests/behat/non_anonymous.feature @@ -54,11 +54,9 @@ Feature: Non anonymous feedback @javascript Scenario: Complete non anonymous feedback and view analysis on the front page as an authenticated user - And I log in as "admin" - And I set the following system permissions of "Authenticated user on site home" role: - | capability | permission | - | mod/feedback:viewanalysepage | Allow | - And I log out + Given the following "role capability" exists: + | role | Authenticated user on frontpage | + | mod/feedback:viewanalysepage | Allow | When I am on the "Site feedback" "feedback activity" page logged in as user1 And I follow "Answer the questions" And I should see "Do you like our site?" diff --git a/mod/forum/tests/behat/separate_group_discussions.feature b/mod/forum/tests/behat/separate_group_discussions.feature index 4762a1f9f49..1bc84f8bba0 100644 --- a/mod/forum/tests/behat/separate_group_discussions.feature +++ b/mod/forum/tests/behat/separate_group_discussions.feature @@ -266,10 +266,6 @@ Feature: Posting to all groups in a separate group discussion is restricted to u And I should not see "Student -> A" Scenario: Teacher in all groups but without accessallgroups can only post in their groups - And I log in as "admin" - And I set the following system permissions of "Non-editing teacher" role: - | moodle/site:accessallgroups | Prohibit | - And I log out Given I log in as "noneditor1" And I am on "Course 1" course homepage And I follow "Standard forum name" @@ -281,10 +277,6 @@ Feature: Posting to all groups in a separate group discussion is restricted to u And I should see "Post a copy to all groups" Scenario: Teacher in some groups and without accessallgroups can only post in their groups - And I log in as "admin" - And I set the following system permissions of "Non-editing teacher" role: - | moodle/site:accessallgroups | Prohibit | - And I log out Given I log in as "noneditor1" And I am on "Course 1" course homepage And I follow "Standard forum name" diff --git a/mod/lesson/tests/behat/link_to_gradebook.feature b/mod/lesson/tests/behat/link_to_gradebook.feature index 6f581479c3f..6315265a45a 100644 --- a/mod/lesson/tests/behat/link_to_gradebook.feature +++ b/mod/lesson/tests/behat/link_to_gradebook.feature @@ -82,10 +82,9 @@ Feature: link to gradebook on the end of lesson page And I should not see "View grades" Scenario: No link to gradebook if no gradereport/user:view capability - Given I log in as "admin" - And I set the following system permissions of "Student" role: - | capability | permission | - | gradereport/user:view | Prevent | + Given the following "role capability" exists: + | role | student | + | gradereport/user:view | prevent | When I am on the "Test lesson" "lesson activity" page logged in as student1 And I press "Next page" And I press "Next page" diff --git a/my/tests/behat/reset_all_pages.feature b/my/tests/behat/reset_all_pages.feature index 9b909857b95..a321ac039f2 100644 --- a/my/tests/behat/reset_all_pages.feature +++ b/my/tests/behat/reset_all_pages.feature @@ -10,11 +10,10 @@ Feature: Reset all personalised pages to default | student1 | Student | 1 | student1@example.com | | student2 | Student | 2 | student2@example.com | | student3 | Student | 3 | student3@example.com | - And I log in as "admin" - And I set the following system permissions of "Authenticated user" role: - | block/myprofile:addinstance | Allow | - | moodle/block:edit | Allow | - And I log out + And the following "role capability" exists: + | role | user | + | moodle/block:edit | allow | + | block/myprofile:addinstance | allow | And I log in as "student1" And I follow "Dashboard" diff --git a/my/tests/behat/restrict_available_blocks.feature b/my/tests/behat/restrict_available_blocks.feature index d4f161e1f49..2d879390d51 100644 --- a/my/tests/behat/restrict_available_blocks.feature +++ b/my/tests/behat/restrict_available_blocks.feature @@ -24,13 +24,12 @@ Feature: Restrict which blocks can be added to Dashboard And the add block selector should contain "Tags" block Scenario: Remove the ability to add the comments block to Dashboard - When I log in as "admin" - And I set the following system permissions of "Authenticated user" role: - | block/comments:myaddinstance | Prohibit | - | block/course_list:myaddinstance | Prohibit | - | block/html:myaddinstance | Prohibit | - And I log out - And I log in as "student1" + Given the following "role capability" exists: + | role | user | + | block/comments:myaddinstance | prohibit | + | block/course_list:myaddinstance | prohibit | + | block/html:myaddinstance | prohibit | + When I log in as "student1" 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 diff --git a/tag/tests/behat/edit_tag.feature b/tag/tests/behat/edit_tag.feature index 791ce537b8f..f78876a6fec 100644 --- a/tag/tests/behat/edit_tag.feature +++ b/tag/tests/behat/edit_tag.feature @@ -23,9 +23,8 @@ Feature: Users can edit tags to add description or rename @javascript Scenario: User with tag editing capability can change tag description - Given I log in as "admin" - And I set the following system permissions of "Tag editor" role: - | capability | permission | + Given the following "role capability" exists: + | role | Tag editor | | moodle/tag:edit | Allow | | moodle/site:viewparticipants | Allow | | moodle/user:viewdetails | Allow | diff --git a/tag/tests/behat/flag_tags.feature b/tag/tests/behat/flag_tags.feature index b71e6364892..2f2c5859d2e 100644 --- a/tag/tests/behat/flag_tags.feature +++ b/tag/tests/behat/flag_tags.feature @@ -17,12 +17,10 @@ Feature: Users can flag tags and manager can reset flags And the following "tags" exist: | name | isstandard | | Neverusedtag | 1 | - And I log in as "admin" - And I set the following system permissions of "Authenticated user" role: - | capability | permission | - | moodle/site:viewparticipants | Allow | - | moodle/user:viewdetails | Allow | - And I log out + And the following "role capability" exists: + | role | Authenticated user | + | moodle/site:viewparticipants | Allow | + | moodle/user:viewdetails | Allow | And I log in as "user2" And I turn editing mode on And the following config values are set as admin: diff --git a/user/tests/behat/enrol_cohort_list.feature b/user/tests/behat/enrol_cohort_list.feature index fe32af431f6..46e02159ea3 100644 --- a/user/tests/behat/enrol_cohort_list.feature +++ b/user/tests/behat/enrol_cohort_list.feature @@ -21,9 +21,8 @@ Feature: Viewing the list of cohorts to enrol in a course | name | Test cohort name | | idnumber | 1337 | | description | Test cohort description | - And I log in as "admin" - And I set the following system permissions of "Teacher" role: - | capability | permission | + And the following "role capability" exists: + | role | Teacher | | moodle/cohort:manage | Prohibit | | moodle/cohort:view | Prohibit | And I log out diff --git a/user/tests/behat/filter_participants.feature b/user/tests/behat/filter_participants.feature index 4980eaa792f..5c253946473 100644 --- a/user/tests/behat/filter_participants.feature +++ b/user/tests/behat/filter_participants.feature @@ -732,9 +732,10 @@ Feature: Course participants can be filtered @javascript @skip_chrome_zerosize Scenario: Filter by user identity fields when cannot see the field data - Given I log in as "admin" - And I set the following system permissions of "Teacher" role: + Given the following "role capability" exists: + | role | Teacher | | moodle/site:viewuseridentity | Prevent | + And I log in as "admin" And the following config values are set as admin: | showuseridentity | idnumber,email,city,country | And I log out diff --git a/user/tests/behat/view_full_profile.feature b/user/tests/behat/view_full_profile.feature index 75e6220d096..909cd7d3db4 100644 --- a/user/tests/behat/view_full_profile.feature +++ b/user/tests/behat/view_full_profile.feature @@ -57,10 +57,9 @@ Feature: Access to full profiles of users Then I should see "First access to site" Scenario: Viewing full profiles with global permission - Given I log in as "admin" - And I set the following system permissions of "Authenticated user" role: - | moodle/user:viewdetails | Allow | - And I log out + Given the following "role capability" exists: + | role | user | + | moodle/user:viewdetails | allow | When I log in as "student1" And I am on "Course 1" course homepage And I navigate to course participants From 2367bc9ff63f02253196d8d2d87fef1ccbb5c38c Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Mon, 15 May 2023 14:56:28 +0800 Subject: [PATCH 4/4] MDL-69231 behat: remaining work for role capability generator This commit does few things: * Unify data generators usage to role short name. * Replace remaining manual steps to use the new data generator. * Also replaced other manual steps to set config to use data generators. * Tidy up of some tests, aligning pipes and splitting one line steps into multiple lines. * Fixes tests to have one Given/When/Then per scenario. --- .../tests/behat/edit_permissions.feature | 2 +- .../tool/lp/tests/behat/plan_workflow.feature | 21 ++++++------ .../monitor/tests/behat/subscription.feature | 4 +-- .../policy/tests/behat/acceptances.feature | 4 +-- .../tests/behat/participants_link.feature | 8 ++--- .../behat/restrict_available_blocks.feature | 5 ++- course/tests/behat/course_browsing.feature | 2 +- .../behat/course_download_content_cm.feature | 12 +++---- ...ourse_download_content_permissions.feature | 32 ++++++----------- course/tests/behat/coursetags.feature | 4 +-- course/tests/behat/keyholder.feature | 20 +++++------ .../restrict_available_activities.feature | 7 ++-- course/tests/behat/role_renaming.feature | 2 +- enrol/self/tests/behat/key_holder.feature | 10 +++--- .../grader/tests/behat/switch_views.feature | 10 +++--- .../report/user/tests/behat/user_view.feature | 2 +- group/tests/behat/delete_groups.feature | 9 ++--- group/tests/behat/update_groups.feature | 7 ++-- lib/testing/generator/data_generator.php | 6 ++-- .../behat/bulk_remove_submissions.feature | 34 ++++--------------- .../tests/behat/remove_submission.feature | 10 +++--- mod/feedback/tests/behat/anonymous.feature | 8 ++--- .../tests/behat/non_anonymous.feature | 4 +-- .../tests/behat/quiz_user_override.feature | 8 ++--- .../tests/behat/question_comment.feature | 12 +++---- .../behat/question_in_place_editing.feature | 8 ++--- tag/tests/behat/edit_tag.feature | 9 +++-- tag/tests/behat/flag_tags.feature | 6 ++-- user/tests/behat/enrol_cohort_list.feature | 6 ++-- user/tests/behat/filter_participants.feature | 4 +-- .../tests/behat/user_grade_navigation.feature | 11 ++++-- .../tests/behat/view_preferences_page.feature | 11 ++++-- 32 files changed, 127 insertions(+), 171 deletions(-) diff --git a/admin/tool/behat/tests/behat/edit_permissions.feature b/admin/tool/behat/tests/behat/edit_permissions.feature index 46b0a3ad449..955f9981c67 100644 --- a/admin/tool/behat/tests/behat/edit_permissions.feature +++ b/admin/tool/behat/tests/behat/edit_permissions.feature @@ -21,7 +21,7 @@ Feature: Edit capabilities Scenario: Default system capabilities modification Given I log in as "admin" - When I navigate to "Users > Permissions > Define roles" in site administration + And I navigate to "Users > Permissions > Define roles" in site administration And I click on "Edit Teacher role" "link" And I fill the capabilities form with the following permissions: | capability | permission | diff --git a/admin/tool/lp/tests/behat/plan_workflow.feature b/admin/tool/lp/tests/behat/plan_workflow.feature index abb075449a8..c68a07cafff 100644 --- a/admin/tool/lp/tests/behat/plan_workflow.feature +++ b/admin/tool/lp/tests/behat/plan_workflow.feature @@ -16,17 +16,16 @@ Feature: Manage plan workflow | usermanageownplan | User manage own plan role | user | | manageplan | Manager all plans role | manager | And the following "role capabilities" exist: - | role | moodle/competency:planmanageowndraft | - | usermanageowndraftplan | allow | - | usermanageownplan | allow | - | manageplan | allow | - And the following "role capabilities" exist: - | role | moodle/competency:planmanageown | - | usermanageownplan | allow | - | manageplan | allow | - And the following "role capabilities" exist: - | role | moodle/competency:planmanage | moodle/competency:planview | moodle/competency:planreview | moodle/competency:planrequestreview | - | manageplan | allow | allow | allow | allow | + | role | moodle/competency:planmanageowndraft | moodle/competency:planmanageown | + | usermanageowndraftplan | allow | | + | usermanageownplan | allow | allow | + | manageplan | allow | allow | + And the following "role capability" exists: + | role | manageplan | + | moodle/competency:planmanage | allow | + | moodle/competency:planview | allow | + | moodle/competency:planreview | allow | + | moodle/competency:planrequestreview | allow | And the following "role assigns" exist: | user | role | contextlevel | reference | | user1 | usermanageowndraftplan | System | | diff --git a/admin/tool/monitor/tests/behat/subscription.feature b/admin/tool/monitor/tests/behat/subscription.feature index aee912a3f16..47f8d2bab4f 100644 --- a/admin/tool/monitor/tests/behat/subscription.feature +++ b/admin/tool/monitor/tests/behat/subscription.feature @@ -170,8 +170,8 @@ Feature: tool_monitor_subscriptions Scenario: No manage rules link when user does not have permission Given the following "role capability" exists: - | role | Non-editing teacher | - | tool/monitor:managerules | Prohibit | + | role | teacher | + | tool/monitor:managerules | prohibit | And I log in as "teacher1" And I follow "Preferences" in the user menu And I follow "Event monitoring" diff --git a/admin/tool/policy/tests/behat/acceptances.feature b/admin/tool/policy/tests/behat/acceptances.feature index 4826fde89e4..c311811372f 100644 --- a/admin/tool/policy/tests/behat/acceptances.feature +++ b/admin/tool/policy/tests/behat/acceptances.feature @@ -71,7 +71,7 @@ Feature: Viewing acceptances reports and accepting on behalf of other users @javascript Scenario: Agree on behalf of another user as a manager, single policy, javascript on - Given the following "role capabilities" exist: + Given the following "role capability" exists: | role | manager | | tool/policy:acceptbehalf | allow | When I log in as "manager" @@ -166,7 +166,7 @@ Feature: Viewing acceptances reports and accepting on behalf of other users Given the following "role capability" exists: | role | manager | | tool/policy:acceptbehalf | allow | - Given I log in as "admin" + And I log in as "admin" And I navigate to "Users > Privacy and policies > Manage policies" in site administration And I click on "Actions" "link_or_button" in the "This privacy policy" "table_row" And I click on "Set status to \"Active\"" "link" in the "This privacy policy" "table_row" diff --git a/blocks/navigation/tests/behat/participants_link.feature b/blocks/navigation/tests/behat/participants_link.feature index a66edbcdd0c..3901d64b320 100644 --- a/blocks/navigation/tests/behat/participants_link.feature +++ b/blocks/navigation/tests/behat/participants_link.feature @@ -55,11 +55,9 @@ Feature: Displaying the link to the Participants page Then I should not see "Participants" in the "Navigation" "block" And I am on the "Test forum name" "forum activity" page And I should not see "Participants" in the "Navigation" "block" - And I log out - And I log in as "admin" - And I set the following system permissions of "Guest" role: - | capability | permission | - | moodle/course:viewparticipants | Allow | + And the following "role capability" exists: + | role | guest | + | moodle/course:viewparticipants | allow | And I log in as "guest" And I am on "Course1" course homepage And I should see "Participants" in the "Navigation" "block" diff --git a/blocks/tests/behat/restrict_available_blocks.feature b/blocks/tests/behat/restrict_available_blocks.feature index 56cd80f65d3..fe5193f9cd6 100644 --- a/blocks/tests/behat/restrict_available_blocks.feature +++ b/blocks/tests/behat/restrict_available_blocks.feature @@ -27,9 +27,8 @@ Feature: Allowed blocks controls Given the following "role capability" exists: | role | editingteacher | | block/activity_modules:addinstance | prohibit | - Given I log in as "admin" - And I am on "Course 1" course homepage - And I navigate to "Users > Permissions" in current page administration + And I log in as "admin" + And I am on the "Course 1" "permissions" page And I override the system permissions of "Teacher" role with: | block/completionstatus:addinstance | Prohibit | And I log out diff --git a/course/tests/behat/course_browsing.feature b/course/tests/behat/course_browsing.feature index abacc36535c..2cacc8c8661 100644 --- a/course/tests/behat/course_browsing.feature +++ b/course/tests/behat/course_browsing.feature @@ -25,7 +25,7 @@ Feature: Restricting access to course lists And the following "roles" exist: | name | shortname | description | archetype | | Category viewer | coursebrowse | My custom role 1 | | - And the following "role capabilities" exist: + And the following "role capability" exist: | role | moodle/category:viewcourselist | | user | prevent | | guest | prevent | diff --git a/course/tests/behat/course_download_content_cm.feature b/course/tests/behat/course_download_content_cm.feature index 09409df9c3f..e97e0ba3ef0 100644 --- a/course/tests/behat/course_download_content_cm.feature +++ b/course/tests/behat/course_download_content_cm.feature @@ -53,14 +53,10 @@ Feature: Activities content download can be controlled Given I log in as "manager1" And I am on the Folder1 "Folder Activity editing" page And "Include in course content download" "field" should exist - And I log out - And I log in as "admin" - When I set the following system permissions of "Manager" role: - | capability | permission | - | moodle/course:configuredownloadcontent | Prohibit | - And I log out - And I log in as "manager1" - And I am on the Folder1 "Folder Activity editing" page + And the following "role capability" exists: + | role | manager | + | moodle/course:configuredownloadcontent | prohibit | + When I am on the Folder1 "Folder Activity editing" page Then I should see "Include in course content download" And I should see "No" And "Include in course content download" "select" should not exist diff --git a/course/tests/behat/course_download_content_permissions.feature b/course/tests/behat/course_download_content_permissions.feature index 1050b7a5e01..69bc5954ae1 100644 --- a/course/tests/behat/course_download_content_permissions.feature +++ b/course/tests/behat/course_download_content_permissions.feature @@ -16,10 +16,8 @@ Feature: Access to downloading course content can be controlled | user | course | role | | teacher1 | C1 | editingteacher | | student1 | C1 | student | - And I log in as "admin" And the following config values are set as admin: - | downloadcoursecontentallowed | 1 | - And I log out + | downloadcoursecontentallowed | 1 | Scenario: Site admins can remove the download course content feature Given I log in as "admin" @@ -60,25 +58,20 @@ Feature: Access to downloading course content can be controlled Then "Download course content" "link" should not exist in current page administration Scenario: Teachers require a capability to access the download course content feature or modify its availability in a course - Given I log in as "admin" - And I navigate to "Courses > Course default settings" in site administration - And I set the field "Enable download course content" to "Yes" - And I press "Save changes" - And I log out + Given the following config values are set as admin: + | config | value | plugin | + | downloadcontentsitedefault | 1 | moodlecourse | # Check teacher can see download option and enable dropdown. And I log in as "teacher1" And I am on "Hockey 101" course homepage Then "Download course content" "link" should exist in current page administration And I navigate to "Settings" in current page administration And "Enable download course content" "select" should exist - And I log out # Remove teacher's capabilities for download course content. - And I log in as "admin" - And I set the following system permissions of "Teacher" role: - | capability | permission | - | moodle/course:downloadcoursecontent | Prohibit | - | moodle/course:configuredownloadcontent | Prohibit | - And I log out + And the following "role capability" exists: + | role | editingteacher | + | moodle/course:downloadcoursecontent | prohibit | + | moodle/course:configuredownloadcontent | prohibit | # Check teacher can no longer see download option, and that enable value is visible, but dropdown no longer available. When I log in as "teacher1" And I am on "Hockey 101" course homepage @@ -99,13 +92,10 @@ Feature: Access to downloading course content can be controlled And I log in as "student1" And I am on "Hockey 101" course homepage And "Download course content" "link" should exist in current page administration - And I log out - And I log in as "admin" # Remove student's capability for download course content. - When I set the following system permissions of "Student" role: - | capability | permission | - | moodle/course:downloadcoursecontent | Prohibit | - And I log out + When the following "role capability" exists: + | role | student | + | moodle/course:downloadcoursecontent | prohibit | # Check student can no longer see the download link. And I log in as "student1" And I am on "Hockey 101" course homepage diff --git a/course/tests/behat/coursetags.feature b/course/tests/behat/coursetags.feature index a681f0d5fc0..8a3f43959fe 100644 --- a/course/tests/behat/coursetags.feature +++ b/course/tests/behat/coursetags.feature @@ -69,8 +69,8 @@ Feature: Tagging courses Scenario: User can set course tags using separate form Given the following "role capability" exists: - | role | Non-editing teacher | - | moodle/course:tag | Allow | + | role | teacher | + | moodle/course:tag | allow | When I log in as "teacher2" And I am on "Course 1" course homepage And I navigate to "Course tags" in current page administration diff --git a/course/tests/behat/keyholder.feature b/course/tests/behat/keyholder.feature index 229cebfd82f..e7a7e958507 100644 --- a/course/tests/behat/keyholder.feature +++ b/course/tests/behat/keyholder.feature @@ -3,9 +3,12 @@ Feature: Keyholder role is listed as course contact As a student I need to know who the keyholder is to enrol in a course Background: - Given the following "roles" exist: - | shortname | name | archetype | context_coursecat | context_course | enrol/self:holdkey | - | keyholder | Keyholder | | 1 | 1 | allow | + Given the following "role" exists: + | shortname | keyholder | + | name | Keyholder | + | context_coursecat | 1 | + | context_course | 1 | + | enrol/self:holdkey | allow | And the following "categories" exist: | name | category | idnumber | | Cat 1 | 0 | CAT1 | @@ -16,18 +19,15 @@ Feature: Keyholder role is listed as course contact | student1 | Student | 1 | teacher1@example.com | And the following "courses" exist: | fullname | shortname | format | coursedisplay | numsections | category | - | Course 1 | C1 | topics | 0 | 5 | CAT1 | - And I add "Self enrolment" enrolment method in "Course 1" with: | Course 1 | C1 | topics | 0 | 5 | CAT1 | - When I log in as "admin" + And I log in as "admin" + And I add "Self enrolment" enrolment method in "Course 1" with: + | Custom instance name | Test student enrolment | + | Enrolment key | letmein | And I navigate to "Appearance > Courses" in site administration And I set the following fields to these values: | Keyholder | 1 | And I press "Save changes" - And I am on "Course 1" course homepage - And I add "Self enrolment" enrolment method with: - | Custom instance name | Test student enrolment | - | Enrolment key | letmein | And I log out Scenario: Keyholder assigned to a course diff --git a/course/tests/behat/restrict_available_activities.feature b/course/tests/behat/restrict_available_activities.feature index 17fd30f729f..74ef9e0d61b 100644 --- a/course/tests/behat/restrict_available_activities.feature +++ b/course/tests/behat/restrict_available_activities.feature @@ -30,12 +30,11 @@ Feature: Restrict activities availability @javascript @skip_chrome_zerosize Scenario: Activities can not be added when the admin restricts the permissions - Given I log in as "admin" - And the following "role capability" exists: + Given the following "role capability" exists: | role | editingteacher | | mod/chat:addinstance | prohibit | - And I am on "Course 1" course homepage - And I navigate to "Users > Permissions" in current page administration + And I log in as "admin" + And I am on the "Course 1" "permissions" page And I override the system permissions of "Teacher" role with: | mod/glossary:addinstance | Prohibit | And I log out diff --git a/course/tests/behat/role_renaming.feature b/course/tests/behat/role_renaming.feature index a19a7328023..7c11855b9e0 100644 --- a/course/tests/behat/role_renaming.feature +++ b/course/tests/behat/role_renaming.feature @@ -41,7 +41,7 @@ Feature: Rename roles in a course Scenario: Ability to rename roles can be prevented Given the following "role capability" exists: | role | editingteacher | - | moodle/course:renameroles | inherit | + | moodle/course:renameroles | inherit | When I log in as "teacher1" And I am on "Course 1" course homepage And I navigate to "Settings" in current page administration diff --git a/enrol/self/tests/behat/key_holder.feature b/enrol/self/tests/behat/key_holder.feature index 1186760b0de..00325386516 100644 --- a/enrol/self/tests/behat/key_holder.feature +++ b/enrol/self/tests/behat/key_holder.feature @@ -6,8 +6,8 @@ Feature: Users can be defined as key holders in courses where self enrolment is Background: Given the following "roles" exist: - | shortname | name | archetype | context_course | enrol/self:holdkey | - | keyholder | Key holder | | 1 | allow | + | shortname | name | context_course | enrol/self:holdkey | + | keyholder | Key holder | 1 | allow | And the following "users" exist: | username | firstname | lastname | email | | manager1 | Manager | 1 | manager1@example.com | @@ -32,13 +32,11 @@ Feature: Users can be defined as key holders in courses where self enrolment is | Custom instance name | Test student enrolment | | Enrolment key | moodle_rules | And I log out - - Scenario: The key holder name is displayed on site home page - Given I log in as "student1" + And I log in as "student1" And I am on "Course 1" course homepage And I should see "You should have received this enrolment key from:" And I should see "Manager 1" - When I set the following fields to these values: + And I set the following fields to these values: | Enrolment key | moodle_rules | And I press "Enrol me" Then I should see "Topic 1" diff --git a/grade/report/grader/tests/behat/switch_views.feature b/grade/report/grader/tests/behat/switch_views.feature index 319f6a7ef26..505fc268fdc 100644 --- a/grade/report/grader/tests/behat/switch_views.feature +++ b/grade/report/grader/tests/behat/switch_views.feature @@ -71,13 +71,13 @@ Feature: We can change what we are viewing on the grader report @javascript @skip_chrome_zerosize Scenario: Minimise the grader report containing hidden activities without the 'moodle/grade:viewhidden' capability - Given the following "role capability" exists: - | role | Teacher | - | moodle/grade:viewhidden | Prevent | - When I am on "Course 1" course homepage with editing mode on + Given 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 the following "role capability" exists: + | role | editingteacher | + | moodle/grade:viewhidden | prevent | + And I am on the "C1" "course" page logged in as "teacher1" And I navigate to "View > Grader report" in the course gradebook Then I should see "Test assignment name 1" in the "user-grades" "table" And I should see "Test assignment name 2" in the "user-grades" "table" diff --git a/grade/report/user/tests/behat/user_view.feature b/grade/report/user/tests/behat/user_view.feature index cc9e95aab4b..26ebb8c60de 100644 --- a/grade/report/user/tests/behat/user_view.feature +++ b/grade/report/user/tests/behat/user_view.feature @@ -181,7 +181,7 @@ Feature: View the user report as the student will see it Scenario: View the report as the student from both the teachers and students perspective when the student can view hidden Given the following "role capability" exists: | role | student | - | moodle/grade:viewhidden | Allow | + | moodle/grade:viewhidden | allow | And I am on the "C1" "Course" page logged in as "teacher1" And I navigate to "Setup > Course grade settings" in the course gradebook And I set the field with xpath "//select[@name='report_user_showtotalsifcontainhidden']" to "Show totals excluding hidden items" diff --git a/group/tests/behat/delete_groups.feature b/group/tests/behat/delete_groups.feature index 553b0972b4f..1ce1bc7489b 100644 --- a/group/tests/behat/delete_groups.feature +++ b/group/tests/behat/delete_groups.feature @@ -57,12 +57,9 @@ Feature: Automatic deletion of groups and groupings @javascript @skip_chrome_zerosize Scenario: Delete groups and groupings with and without ID numbers without the 'moodle/course:changeidnumber' capability - Given I log out - And the following "role capability" exists: - | role | Teacher | - | moodle/course:changeidnumber | Prevent | - And I log out - And I log in as "teacher1" + Given the following "role capability" exists: + | role | editingteacher | + | moodle/course:changeidnumber | prevent | And I am on the "Course 1" "groups" page When I set the field "groups" to "Group (with ID) (0)" Then the "Delete" "button" should be disabled diff --git a/group/tests/behat/update_groups.feature b/group/tests/behat/update_groups.feature index d59f912b875..28400c253f7 100644 --- a/group/tests/behat/update_groups.feature +++ b/group/tests/behat/update_groups.feature @@ -64,10 +64,9 @@ Feature: Automatic updating of groups and groupings @javascript @skip_chrome_zerosize Scenario: Update groups and groupings with ID numbers without the 'moodle/course:changeidnumber' capability - Given I log out - And the following "role capability" exists: - | role | Teacher | - | moodle/course:changeidnumber | Prevent | + Given the following "role capability" exists: + | role | editingteacher | + | moodle/course:changeidnumber | prevent | And I log in as "teacher1" And I am on the "Course 1" "groups" page And I set the field "groups" to "Group (with ID)" diff --git a/lib/testing/generator/data_generator.php b/lib/testing/generator/data_generator.php index 1f7a752547a..25e8dae53b0 100644 --- a/lib/testing/generator/data_generator.php +++ b/lib/testing/generator/data_generator.php @@ -871,9 +871,9 @@ EOD; /** * Set role capabilities for the specified role. * - * @param int $roleid The Role to set capabilities for - * @param array $rolecapabilities The list of capability =>permission to set for this role - * @param context $context The context to apply this capability to + * @param int $roleid The Role to set capabilities for + * @param array $rolecapabilities The list of capability =>permission to set for this role + * @param null|context $context The context to apply this capability to */ public function create_role_capability(int $roleid, array $rolecapabilities, context $context = null): void { // Map the capabilities into human-readable names. diff --git a/mod/assign/tests/behat/bulk_remove_submissions.feature b/mod/assign/tests/behat/bulk_remove_submissions.feature index 30ef6813b55..9db6cec3c31 100644 --- a/mod/assign/tests/behat/bulk_remove_submissions.feature +++ b/mod/assign/tests/behat/bulk_remove_submissions.feature @@ -36,8 +36,8 @@ Feature: Bulk remove submissions | Test assignment name | student1 | I'm the student1 submission | | Test assignment name | student2 | I'm the student2 submission | And the following "role capability" exists: - | role | Teacher | - | mod/assign:editothersubmission | Allow | + | role | editingteacher | + | mod/assign:editothersubmission | allow | And I am on the "Test assignment name" Activity page logged in as teacher1 And I follow "View all submissions" And I should see "I'm the student1 submission" @@ -94,29 +94,8 @@ Feature: Bulk remove submissions | Test assignment name | student1 | I'm the student1 submission | | Test assignment name | student2 | I'm the student2 submission | And the following "role capability" exists: - | role | Teacher | - | mod/assign:editothersubmission | Allow | - And I am on the "Test assignment name" Activity page logged in as teacher1 - And I follow "View all submissions" - - @javascript - Scenario: Notification should be displayed when non-group users are selected for submission bulk removal - in separate group mode - Given the following "activity" exists: - | activity | assign | - | course | C1 | - | name | Test assignment name | - | assignsubmission_onlinetext_enabled | 1 | - | assignsubmission_file_enabled | 0 | - | groupmode | 1 | - | submissiondrafts | 0 | - And the following "mod_assign > submissions" exist: - | assign | user | onlinetext | - | Test assignment name | student1 | I'm the student1 submission | - | Test assignment name | student2 | I'm the student2 submission | - Given the following "role capability" exists: - | role | Teacher | - | mod/assign:editothersubmission | Allow | + | role | editingteacher | + | mod/assign:editothersubmission | allow | And I am on the "Test assignment name" Activity page logged in as teacher1 And I follow "View all submissions" And I should see "I'm the student1 submission" @@ -150,9 +129,8 @@ Feature: Bulk remove submissions | Test assignment name | student1 | I'm the student1 submission | | Test assignment name | student2 | I'm the student2 submission | And the following "role capability" exists: - | role | Teacher | - | mod/assign:editothersubmission | Allow | - + | role | editingteacher | + | mod/assign:editothersubmission | allow | And I am on the "Test assignment name" Activity page logged in as teacher1 And I follow "View all submissions" And I should see "I'm the student1 submission" diff --git a/mod/assign/tests/behat/remove_submission.feature b/mod/assign/tests/behat/remove_submission.feature index 1e8ae35d148..d3fcf4b0cb5 100644 --- a/mod/assign/tests/behat/remove_submission.feature +++ b/mod/assign/tests/behat/remove_submission.feature @@ -5,11 +5,8 @@ Feature: Remove a submission I need to remove a student submission at any time Background: - Given the following "role capability" exists: - | role | Teacher | - | mod/assign:editothersubmission | Allow | - And I set the following administration settings values: - | Enable timed assignments | 1 | + Given the following config values are set as admin: + | enabletimelimit | 1 | assign | And the following "courses" exist: | fullname | shortname | category | groupmode | | Course 1 | C1 | 0 | 0 | @@ -23,6 +20,9 @@ Feature: Remove a submission | teacher1 | C1 | editingteacher | | student1 | C1 | student | | student2 | C1 | student | + And the following "role capability" exists: + | role | editingteacher | + | mod/assign:editothersubmission | allow | And the following "groups" exist: | name | course | idnumber | | Group 1 | C1 | G1 | diff --git a/mod/feedback/tests/behat/anonymous.feature b/mod/feedback/tests/behat/anonymous.feature index 5b1dae6ba51..3e928c4af8e 100644 --- a/mod/feedback/tests/behat/anonymous.feature +++ b/mod/feedback/tests/behat/anonymous.feature @@ -59,8 +59,8 @@ Feature: Anonymous feedback @javascript Scenario: Complete anonymous feedback and view analysis on the front page as an authenticated user Given the following "role capability" exists: - | role | Authenticated user on frontpage | - | mod/feedback:viewanalysepage | Allow | + | role | frontpage | + | mod/feedback:viewanalysepage | allow | And I log in as "user1" And I am on site homepage When I follow "Site feedback" @@ -117,8 +117,8 @@ Feature: Anonymous feedback Given the following config values are set as admin: | feedback_allowfullanonymous | 1 | And the following "role capability" exists: - | role | Guest | - | mod/feedback:viewanalysepage | Allow | + | role | guest | + | mod/feedback:viewanalysepage | allow | When I follow "Site feedback" And I should not see "Preview questions" And I follow "Answer the questions" diff --git a/mod/feedback/tests/behat/non_anonymous.feature b/mod/feedback/tests/behat/non_anonymous.feature index 30862a87b04..c5fecc45bd8 100644 --- a/mod/feedback/tests/behat/non_anonymous.feature +++ b/mod/feedback/tests/behat/non_anonymous.feature @@ -55,8 +55,8 @@ Feature: Non anonymous feedback @javascript Scenario: Complete non anonymous feedback and view analysis on the front page as an authenticated user Given the following "role capability" exists: - | role | Authenticated user on frontpage | - | mod/feedback:viewanalysepage | Allow | + | role | frontpage | + | mod/feedback:viewanalysepage | allow | When I am on the "Site feedback" "feedback activity" page logged in as user1 And I follow "Answer the questions" And I should see "Do you like our site?" diff --git a/mod/quiz/tests/behat/quiz_user_override.feature b/mod/quiz/tests/behat/quiz_user_override.feature index 25d702825b9..e9ff50c419e 100644 --- a/mod/quiz/tests/behat/quiz_user_override.feature +++ b/mod/quiz/tests/behat/quiz_user_override.feature @@ -208,11 +208,9 @@ Feature: Quiz user override And the following "activities" exist: | activity | name | course | idnumber | groupmode | | quiz | Test quiz | C1 | quiz1 | 1 | - And I log in as "admin" - And I set the following system permissions of "Manager" role: - | capability | permission | - | mod/quiz:attempt | Allow | - And I log out + And the following "role capability" exists: + | role | manager | + | mod/quiz:attempt | allow | When I am on the "Test quiz" "mod_quiz > User overrides" page logged in as "teacher" And I press "Add user override" And I click on "Override user" "field" diff --git a/question/bank/comment/tests/behat/question_comment.feature b/question/bank/comment/tests/behat/question_comment.feature index cbfa9528d4c..5bb522fe6c6 100644 --- a/question/bank/comment/tests/behat/question_comment.feature +++ b/question/bank/comment/tests/behat/question_comment.feature @@ -74,13 +74,11 @@ Feature: A Teacher can comment in a question @javascript Scenario: Teacher with comment permissions for their own questions but not others questions - Given I log in as "admin" - And I set the following system permissions of "Teacher" role: - | capability | permission | - | moodle/question:commentmine | Allow | - | moodle/question:commentall | Prevent | - And I log out - Given I am on the "Test quiz" "mod_quiz > question bank" page logged in as "teacher1" + Given the following "role capability" exists: + | role | editingteacher | + | moodle/question:commentmine | allow | + | moodle/question:commentall | prevent | + And I am on the "Test quiz" "mod_quiz > question bank" page logged in as "teacher1" And I set the field "Select a category" to "Test questions" And I choose "Preview" action for "First question" in the question bank Then I should not see "Save comment" diff --git a/question/bank/viewquestionname/tests/behat/question_in_place_editing.feature b/question/bank/viewquestionname/tests/behat/question_in_place_editing.feature index 279854ce37e..8cdbaa4e420 100644 --- a/question/bank/viewquestionname/tests/behat/question_in_place_editing.feature +++ b/question/bank/viewquestionname/tests/behat/question_in_place_editing.feature @@ -31,11 +31,9 @@ Feature: Use the qbank view page to edit question title using in place edit feat @javascript Scenario: Teacher without permission can not change the title from question bank view - Given I log in as "admin" - And I set the following system permissions of "Teacher" role: - | capability | permission | - | moodle/question:editall | Prevent | - And I log out + Given the following "role capability" exists: + | role | editingteacher | + | moodle/question:editall | prevent | And I am on the "Test quiz" "mod_quiz > question bank" page logged in as "teacher1" When I set the field "Select a category" to "Test questions" And I should see "First question" diff --git a/tag/tests/behat/edit_tag.feature b/tag/tests/behat/edit_tag.feature index f78876a6fec..c9408b22be5 100644 --- a/tag/tests/behat/edit_tag.feature +++ b/tag/tests/behat/edit_tag.feature @@ -24,11 +24,10 @@ Feature: Users can edit tags to add description or rename @javascript Scenario: User with tag editing capability can change tag description Given the following "role capability" exists: - | role | Tag editor | - | moodle/tag:edit | Allow | - | moodle/site:viewparticipants | Allow | - | moodle/user:viewdetails | Allow | - And I log out + | role | tageditor | + | moodle/tag:edit | allow | + | moodle/site:viewparticipants | allow | + | moodle/user:viewdetails | allow | When I log in as "editor1" And I turn editing mode on And the following config values are set as admin: diff --git a/tag/tests/behat/flag_tags.feature b/tag/tests/behat/flag_tags.feature index 2f2c5859d2e..bc8348fcf5a 100644 --- a/tag/tests/behat/flag_tags.feature +++ b/tag/tests/behat/flag_tags.feature @@ -18,9 +18,9 @@ Feature: Users can flag tags and manager can reset flags | name | isstandard | | Neverusedtag | 1 | And the following "role capability" exists: - | role | Authenticated user | - | moodle/site:viewparticipants | Allow | - | moodle/user:viewdetails | Allow | + | role | user | + | moodle/site:viewparticipants | allow | + | moodle/user:viewdetails | allow | And I log in as "user2" And I turn editing mode on And the following config values are set as admin: diff --git a/user/tests/behat/enrol_cohort_list.feature b/user/tests/behat/enrol_cohort_list.feature index 46e02159ea3..3f09a38415e 100644 --- a/user/tests/behat/enrol_cohort_list.feature +++ b/user/tests/behat/enrol_cohort_list.feature @@ -22,9 +22,9 @@ Feature: Viewing the list of cohorts to enrol in a course | idnumber | 1337 | | description | Test cohort description | And the following "role capability" exists: - | role | Teacher | - | moodle/cohort:manage | Prohibit | - | moodle/cohort:view | Prohibit | + | role | editingteacher | + | moodle/cohort:manage | prohibit | + | moodle/cohort:view | prohibit | And I log out And I am on the "Course 1" course page logged in as teacher1 And I navigate to course participants diff --git a/user/tests/behat/filter_participants.feature b/user/tests/behat/filter_participants.feature index 5c253946473..4beee4578bf 100644 --- a/user/tests/behat/filter_participants.feature +++ b/user/tests/behat/filter_participants.feature @@ -733,8 +733,8 @@ Feature: Course participants can be filtered @javascript @skip_chrome_zerosize Scenario: Filter by user identity fields when cannot see the field data Given the following "role capability" exists: - | role | Teacher | - | moodle/site:viewuseridentity | Prevent | + | role | editingteacher | + | moodle/site:viewuseridentity | prevent | And I log in as "admin" And the following config values are set as admin: | showuseridentity | idnumber,email,city,country | diff --git a/user/tests/behat/user_grade_navigation.feature b/user/tests/behat/user_grade_navigation.feature index dda9119b3e0..02a1e11d21f 100644 --- a/user/tests/behat/user_grade_navigation.feature +++ b/user/tests/behat/user_grade_navigation.feature @@ -59,9 +59,14 @@ Feature: The student can navigate to their grades page and user grade report. Then I should see "My badges from Acceptance test site web site" Scenario: Log in as a parent and view a childs grades. - Given the following "roles" exist: - | shortname | name | archetype | context_user | moodle/user:editprofile | moodle/user:viewalldetails | moodle/user:viewuseractivitiesreport | moodle/user:viewdetails | - | Parent | Parent | | 1 | allow | allow | allow | allow | + Given the following "role" exists: + | shortname | Parent | + | name | Parent | + | context_user | 1 | + | moodle/user:editprofile | allow | + | moodle/user:viewalldetails | allow | + | moodle/user:viewuseractivitiesreport | allow | + | moodle/user:viewdetails | allow | When I log in as "admin" And I am on site homepage And I turn editing mode on diff --git a/user/tests/behat/view_preferences_page.feature b/user/tests/behat/view_preferences_page.feature index 64489442ee2..35bac5f7048 100644 --- a/user/tests/behat/view_preferences_page.feature +++ b/user/tests/behat/view_preferences_page.feature @@ -52,9 +52,14 @@ Feature: Access to preferences page Then I should see "Preferences" in the "region-main" "region" Scenario: A user with the appropriate permissions can view another user's permissions page. - Given the following "roles" exist: - | shortname | name | archetype | context_user | moodle/user:editprofile | moodle/user:viewalldetails | moodle/user:viewuseractivitiesreport | moodle/user:viewdetails | - | Parent | Parent | | 1 | allow | allow | allow | allow | + Given the following "role" exists: + | shortname | Parent | + | name | Parent | + | context_user | 1 | + | moodle/user:editprofile | allow | + | moodle/user:viewalldetails | allow | + | moodle/user:viewuseractivitiesreport | allow | + | moodle/user:viewdetails | allow | When I log in as "admin" And I am on site homepage And I turn editing mode on