Skip to content

Commit

Permalink
MDL-82500 my: Fix and improve behat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Aug 2, 2024
1 parent bf08c51 commit 1d99a31
Showing 1 changed file with 152 additions and 42 deletions.
194 changes: 152 additions & 42 deletions my/tests/behat/my_courses.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,110 @@ Feature: Run tests over my courses.

Scenario: Admin can add new courses or manage them from my courses
Given I am on the "My courses" page logged in as "admin"
And I click on "Course management options" "link"
And I click on "New course" "link"
And I wait to be redirected
And "Create course" "button" should not exist in the "page-header" "region"
And "Manage courses" "button" should not exist in the "page-header" "region"
When I click on "Create course" "button" in the "page-content" "region"
Then I should see "Add a new course"
And I am on the "My courses" page
And I click on "Course management options" "link"
And I click on "Manage courses" "link"
And I click on "Manage courses" "button" in the "page-content" "region"
And I should see "Manage course categories and courses"
# Check that the same buttons are displayed in the header when the user is enrolled in a course.
But the following "course" exists:
| fullname | Course 1 |
| shortname | C1 |
| format | topics |
And the following "course enrolment" exists:
| user | admin |
| course | C1 |
| role | student |
And I am on the "My courses" page
And "Create course" "button" should exist in the "page-header" "region"
And "Manage courses" "button" should exist in the "page-header" "region"
And "Create course" "button" should not exist in the "page-content" "region"
And "Manage courses" "button" should not exist in the "page-content" "region"

@javascript
Scenario: User without creating a course and managing category permissions cannot see any link
Given I am on the "My courses" page logged in as "user1"
Then "Course management options" "link" should not exist
Then "Create course" "button" should not exist
And "Manage courses" "button" should not exist
# Check that the same buttons are displayed in the header when the user is enrolled in a course.
But the following "course" exists:
| fullname | Course 1 |
| shortname | C1 |
| format | topics |
And the following "course enrolment" exists:
| user | user1 |
| course | C1 |
| role | student |
And I am on the "My courses" page
And "Create course" "button" should not exist
And "Manage courses" "button" should not exist

Scenario: User without capability to browse courses cannot see any link
Given the following "permission overrides" exist:
| capability | permission | role | contextlevel | reference |
| moodle/category:viewcourselist | Prevent | user | System | |
Given I am on the "My courses" page logged in as "user1"
Then "Course management options" "link" should not exist
When I am on the "My courses" page logged in as "user1"
Then "Create course" "button" should not exist
And "Manage courses" "button" should not exist
# Check that the same buttons are displayed in the header when the user is enrolled in a course.
But the following "course" exists:
| fullname | Course 1 |
| shortname | C1 |
| format | topics |
And the following "course enrolment" exists:
| user | user1 |
| course | C1 |
| role | student |
And I am on the "My courses" page
And "Create course" "button" should not exist
And "Manage courses" "button" should not exist

@javascript
Scenario: User with creating a course permission can see the Create course link only
Given the following "permission overrides" exist:
| capability | permission | role | contextlevel | reference |
| moodle/course:create | Allow | role1 | Category | cata |
When I am on the "My courses" page logged in as "user1"
Then "Course management options" "link" should exist
And I click on "Course management options" "link"
And I should see "New course"
And I should not see "Manage courses"
And I click on "New course" "link"
And I wait to be redirected
Then "Create course" "button" should exist in the "page-content" "region"
But "Manage courses" "button" should not exist
And "Create course" "button" should not exist in the "page-header" "region"
And I click on "Create course" "button"
And I should see "Add a new course"
And "CatA" "autocomplete_selection" should exist
# Check that the same buttons are displayed in the header when the user is enrolled in a course.
But the following "course" exists:
| fullname | Course 1 |
| shortname | C1 |
| format | topics |
And the following "course enrolment" exists:
| user | user1 |
| course | C1 |
| role | student |
And I am on the "My courses" page
And "Create course" "button" should exist in the "page-header" "region"
And "Manage courses" "button" should not exist
And "Create course" "button" should not exist in the "page-content" "region"

@javascript
Scenario: User with managing a category permission can see the Manage course link only
Given the following "permission overrides" exist:
| capability | permission | role | contextlevel | reference |
| moodle/category:manage | Allow | role1 | Category | cata |
# TODO: Once MDL-xxxx is fixed, add a test to check that manage course button is displayed in the course_overview block
# when the user is not enrolled in any courses.
And the following "course" exists:
| fullname | Course 1 |
| shortname | C1 |
| format | topics |
And the following "course enrolment" exists:
| user | user1 |
| course | C1 |
| role | student |
When I am on the "My courses" page logged in as "user1"
Then "Course management options" "link" should exist
And I click on "Course management options" "link"
And I should not see "New course"
And I should see "Manage courses"
And I click on "Manage courses" "link"
And I wait to be redirected
Then "Manage courses" "button" should exist in the "page-header" "region"
But "Create course" "button" should not exist in the "page-header" "region"
And I click on "Manage courses" "button"
And I should see "Manage course categories and courses"

@javascript
Expand All @@ -73,19 +130,30 @@ Feature: Run tests over my courses.
| moodle/course:create | Allow | role1 | Category | cata |
| moodle/category:manage | Allow | role1 | Category | cata |
When I am on the "My courses" page logged in as "user1"
Then "Course management options" "link" should exist
And I click on "Course management options" "link"
And I should see "New course"
And I should see "Manage courses"
And I click on "New course" "link"
And I wait to be redirected
Then "Create course" "button" should exist in the "page-content" "region"
And "Manage courses" "button" should exist in the "page-content" "region"
And "Create course" "button" should not exist in the "page-header" "region"
And "Manage courses" "button" should not exist in the "page-header" "region"
And I click on "Create course" "button"
And I should see "Add a new course"
And "CatA" "autocomplete_selection" should exist
And I am on the "My courses" page
And I click on "Course management options" "link"
And I click on "Manage courses" "link"
And I wait to be redirected
And I click on "Manage courses" "button"
And I should see "Manage course categories and courses"
# Check that the same buttons are displayed in the header when the user is enrolled in a course.
But the following "course" exists:
| fullname | Course 1 |
| shortname | C1 |
| format | topics |
And the following "course enrolment" exists:
| user | user1 |
| course | C1 |
| role | student |
And I am on the "My courses" page
And "Create course" "button" should exist in the "page-header" "region"
And "Manage courses" "button" should exist in the "page-header" "region"
And "Create course" "button" should not exist in the "page-content" "region"
And "Manage courses" "button" should not exist in the "page-content" "region"

@javascript
Scenario: Admin can see relevant blocks but not add or move them
Expand All @@ -109,33 +177,75 @@ Feature: Run tests over my courses.
And I should see "This is visible on all pages"
And "Move Text on all pages block" "menuitem" should not exist in the "Text on all pages" "block"
And "Move Course overview block" "menuitem" should not exist in the "Course overview" "block"
And I click on "Actions menu" "icon" in the "Course overview" "block"
And I should not see "Delete Course overview block"
And "Actions menu" "icon" in the "Course overview" "block" should not be visible

@javascript
Scenario: User with creating a course permission can't see the Request course link
Given the following "permission overrides" exist:
| capability | permission | role | contextlevel | reference |
| moodle/course:request | Allow | user | System | |
When I am on the "My courses" page logged in as "admin"
And I click on "Course management options" "link"
And I should see "New course"
Then I should not see "Request a course"
Then "Create course" "button" should exist in the "page-content" "region"
And "Request a course" "button" should not exist
And "Create course" "button" should not exist in the "page-header" "region"
# Check that the same buttons are displayed in the header when the user is enrolled in a course.
But the following "course" exists:
| fullname | Course 1 |
| shortname | C1 |
| format | topics |
And the following "course enrolment" exists:
| user | admin |
| course | C1 |
| role | student |
And I am on the "My courses" page
And "Create course" "button" should exist in the "page-header" "region"
And "Request a course" "button" should not exist
And "Create course" "button" should not exist in the "page-content" "region"

@javascript
Scenario: User without creating a course but with course request permission could see the Request course link
Given the following "permission overrides" exist:
| capability | permission | role | contextlevel | reference |
| moodle/course:request | Allow | user | System | |
When I am on the "My courses" page logged in as "user1"
And I click on "Course management options" "link"
And I should not see "New course"
Then I should see "Request a course"
Then "Request a course" "button" should exist in the "page-content" "region"
And "Create course" "button" should not exist in the "page-content" "region"
And "Create course" "button" should not exist in the "page-header" "region"
And "Request a course" "button" should not exist in the "page-header" "region"
# Check the request a course button is not displayed when this feature is disabled.
And the following config values are set as admin:
| enablecourserequests | 0 |
And I am on the "My courses" page logged in as "user1"
And "Course management options" "link" should not exist
And "Request a course" "button" should not exist
# Check that the same buttons are displayed in the header when the user is enrolled in a course.
But the following "course" exists:
| fullname | Course 1 |
| shortname | C1 |
| format | topics |
And the following "course enrolment" exists:
| user | user1 |
| course | C1 |
| role | student |
And the following config values are set as admin:
| enablecourserequests | 1 |
And I am on the "My courses" page
And "Request a course" "button" should exist in the "page-header" "region"
And "Create course" "button" should not exist
And "Request a course" "button" should not exist in the "page-content" "region"

Scenario: User without creating nor course request permission shouldn't see any Request course link
Given I am on the "My courses" page logged in as "user1"
Then "Course management options" "link" should not exist
Then "Request a course" "button" should not exist in the "page-content" "region"
And "Create course" "button" should not exist in the "page-content" "region"
And "Manage courses" "button" should not exist in the "page-content" "region"
# Check that the same buttons are displayed in the header when the user is enrolled in a course.
But the following "course" exists:
| fullname | Course 1 |
| shortname | C1 |
| format | topics |
And the following "course enrolment" exists:
| user | user1 |
| course | C1 |
| role | student |
And I am on the "My courses" page
And "Create course" "button" should not exist
And "Request a course" "button" should not exist
And "Manage courses" "button" should not exist

0 comments on commit 1d99a31

Please sign in to comment.