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.
This commit is contained in:
Simey Lameze
2023-06-02 12:47:27 +08:00
parent aa2fc4048e
commit 2367bc9ff6
32 changed files with 127 additions and 171 deletions
@@ -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 |
+10 -11
View File
@@ -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 | |
@@ -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"
@@ -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"
@@ -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"
@@ -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
+1 -1
View File
@@ -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 |
@@ -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
@@ -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
+2 -2
View File
@@ -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
+10 -10
View File
@@ -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
@@ -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
+1 -1
View File
@@ -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
+4 -6
View File
@@ -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"
@@ -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"
@@ -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"
+3 -6
View File
@@ -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
+3 -4
View File
@@ -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)"
+3 -3
View File
@@ -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.
@@ -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"
@@ -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 |
+4 -4
View File
@@ -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"
@@ -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?"
@@ -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"
@@ -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"
@@ -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"
+4 -5
View File
@@ -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:
+3 -3
View File
@@ -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:
+3 -3
View File
@@ -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
+2 -2
View File
@@ -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 |
@@ -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
@@ -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