Skip to content

Commit

Permalink
MDL-69231 behat: remaining work for role capability generator
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lameze committed Jun 2, 2023
1 parent aa2fc40 commit 2367bc9
Show file tree
Hide file tree
Showing 32 changed files with 127 additions and 171 deletions.
2 changes: 1 addition & 1 deletion admin/tool/behat/tests/behat/edit_permissions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
21 changes: 10 additions & 11 deletions admin/tool/lp/tests/behat/plan_workflow.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/monitor/tests/behat/subscription.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/policy/tests/behat/acceptances.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
8 changes: 3 additions & 5 deletions blocks/navigation/tests/behat/participants_link.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 2 additions & 3 deletions blocks/tests/behat/restrict_available_blocks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion course/tests/behat/course_browsing.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
12 changes: 4 additions & 8 deletions course/tests/behat/course_download_content_cm.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 11 additions & 21 deletions course/tests/behat/course_download_content_permissions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions course/tests/behat/coursetags.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions course/tests/behat/keyholder.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions course/tests/behat/restrict_available_activities.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion course/tests/behat/role_renaming.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions enrol/self/tests/behat/key_holder.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions grade/report/grader/tests/behat/switch_views.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion grade/report/user/tests/behat/user_view.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 3 additions & 6 deletions group/tests/behat/delete_groups.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions group/tests/behat/update_groups.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
6 changes: 3 additions & 3 deletions lib/testing/generator/data_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -871,9 +871,9 @@ public function create_role($record=null) {
/**
* 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.
Expand Down
Loading

0 comments on commit 2367bc9

Please sign in to comment.