Skip to content

Commit

Permalink
MDL-82503 badges: Fix behat and PHPUnit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Sep 3, 2024
1 parent 9b58ab3 commit 2f4efdb
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 162 deletions.
2 changes: 1 addition & 1 deletion backup/util/ui/tests/behat/import_course.feature
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Feature: Import course's contents into another course
| Unpublished course badge | editingteacher |
When I import "Course 1" course into "Course 2" course using this options:
| Settings | Include badges | 1 |
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
Then I should see "Published course badge"
And I should see "Unpublished course badge"
And I should see "Unpublished without criteria course badge"
Expand Down
2 changes: 1 addition & 1 deletion backup/util/ui/tests/behat/restore_moodle2_courses.feature
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ Feature: Restore Moodle 2 course backups
| Confirmation | Filename | test_backup.mbz |
When I restore "test_backup.mbz" backup into a new course using this options:
| Settings | Include badges | 1 |
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
Then I should see "Published course badge"
And I should see "Unpublished course badge"
And I should see "Unpublished without criteria course badge"
Expand Down
59 changes: 10 additions & 49 deletions badges/tests/behat/add_badge.feature
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ Feature: Add badges to the system
| Image caption | Test caption image |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I navigate to "Badges > Manage badges" in site administration
And I press "Add a new badge"
And I wait until the page is ready
And I navigate to "Badges > Add a new badge" in site administration
And I set the following fields to these values:
| Name | Test Badge 2 |
| Version | v2 |
Expand All @@ -82,6 +82,7 @@ Feature: Add badges to the system
And I should see "This badge does not have any related badges."
And I press "Add related badge"
And I follow "Related badges"
And I wait until the page is ready
And I follow "Related badges"
And I set the field "relatedbadgeids[]" to "Test Badge 1 (version: v1, language: French, Site badges)"
When I press "Save changes"
Expand Down Expand Up @@ -168,13 +169,12 @@ Feature: Add badges to the system
And I am on homepage
When I click on "Site pages" "list_item" in the "Navigation" "block"
And I click on "Site badges" "link" in the "Navigation" "block"
Then I should see "Manage badges"
And I should see "Add a new badge"
Then I should see "Add a new badge"

@javascript @_file_upload
Scenario: Edit a site badge
Given the following "core_badges > Badge" exists:
| name | Site badge |
| name | Testing site badge |
| status | inactive |
| version | 1 |
| language | ca |
Expand All @@ -184,11 +184,11 @@ Feature: Add badges to the system
| imagecaption | My caption image |
| issuercontact | testuser@example.com |
And the following "core_badges > Criterias" exist:
| badge | role |
| Site badge | editingteacher |
| badge | role |
| Testing site badge | editingteacher |
And I navigate to "Badges > Manage badges" in site administration
When I press "Edit" action in the "Site badge" report row
And I should see "Site badge"
When I press "Edit" action in the "Testing site badge" report row
And I should see "Testing site badge"
And the field "Issuer contact" matches value "[email protected]"
And I set the following fields to these values:
| Name | Test badge with 'apostrophe' and other friends (<>&@#) |
Expand All @@ -203,7 +203,7 @@ Feature: Add badges to the system
And I select "Overview" from the "jump" singleselect
And I expand all fieldsets
Then I should see "Test badge with 'apostrophe' and other friends (&@#)"
And I should not see "Site badge"
And I should not see "Testing site badge"
And I should see "secondversion"
And I should not see "firstversion"
And I should see "Math"
Expand All @@ -218,42 +218,3 @@ Feature: Add badges to the system
| badges_defaultissuername | Test Badge Site |
And I navigate to "Badges > Add a new badge" in site administration
And the field "Issuer name" matches value "Test Badge Site"

Scenario: Cancel button behaviour when creating badges
Given the following "course" exists:
| fullname | Course 1 |
| shortname | C1 |
And the following "core_badges > Badge" exists:
| name | Site Badge 1 |
| description | Site badge 1 description |
| image | badges/tests/behat/badge.png |
| status | 0 |
| type | 1 |
And the following "core_badges > Badge" exists:
| name | Course Badge 1 |
| course | C1 |
| description | Course badge 1 description |
| image | badges/tests/behat/badge.png |
| status | 0 |
| type | 2 |
# Site badge: cancel when creating.
When I navigate to "Badges > Add a new badge" in site administration
And I click on "Cancel" "button"
Then I should see "Manage badges"
And I should see "Add a new badge"
# Site badge: cancel when editing.
And I press "Edit" action in the "Site Badge 1" report row
And I click on "Cancel" "button"
And I should see "Site badge 1"
And I should not see "Save changes"
# Course badge: cancel when creating.
And I am on the "Course 1" "course" page
And I navigate to "Badges > Manage badges > Add a new badge" in current page administration
And I click on "Cancel" "button"
Then I should see "Manage badges"
And I should see "Add a new badge"
# Course badge: cancel when editing.
And I press "Edit" action in the "Course Badge 1" report row
And I click on "Cancel" "button"
And I should see "Course badge 1"
And I should not see "Save changes"
46 changes: 28 additions & 18 deletions badges/tests/behat/award_badge.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Feature: Award badges
| badge | Course Badge 1 |
| role | editingteacher |
And I am on the "Course 1" "course" page logged in as "teacher1"
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge 2"
And I select "Criteria" from the "jump" singleselect
# Set "course badge 1" as criteria for Badge 2.
Expand All @@ -47,15 +47,15 @@ Feature: Award badges
And I press "Enable access"
And I click on "Enable" "button" in the "Confirm" "dialogue"
And I am on "Course 1" course homepage
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge 1"
And I select "Recipients (0)" from the "jump" singleselect
And I press "Award badge"
# Award course badge 1 to student 1.
And I set the field "potentialrecipients[]" to "Student 1 ([email protected])"
When I press "Award badge"
And I am on "Course 1" course homepage
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge 1"
And I select "Recipients (1)" from the "jump" singleselect
Then I should see "Recipients (1)"
Expand All @@ -70,16 +70,26 @@ Feature: Award badges
When I follow "Badges"
Then I should see "Course Badge 1"
And I should see "Course Badge 2"
And I should not see "Manage badges"
And I should not see "Add a new badge"
# Student 1 should have both badges in the course too.
And I am on "Course 1" course homepage
And I navigate to "Badges" in current page administration
And I should see "Course Badge 1"
And I should see "Course Badge 2"
And I should not see "Course badge 1 description"
And I should not see "Course badge 2 description"
And I should not see "Recipients"
And I should not see "Badge status"
And I follow "Course Badge 1"
And I should see "Course badge 1 description"
And I should not see "Course badge 2 description"
And I log out
# Teacher 1 should have access to manage/create badges in the Badges navigation section.
When I log in as "teacher1"
And I am on "Course 1" course homepage
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
Then I should see "Course Badge 1"
And I should see "Course Badge 2"
And I should see "Manage badges"
And I should see "Add a new badge"
# Teacher 1 should NOT have access to manage/create site badges in the Site badges section.
When I am on homepage
Expand All @@ -91,7 +101,6 @@ Feature: Award badges
And I click on "Site pages" "list_item" in the "Navigation" "block"
And I click on "Site badges" "link" in the "Navigation" "block"
Then I should see "There are no matching badges available for users to earn"
And I should not see "Manage badges"
And I should not see "Add a new badge"

@javascript
Expand Down Expand Up @@ -127,6 +136,7 @@ Feature: Award badges
And I press "Update profile"
And I follow "Profile" in the user menu
Then I should see "Profile Badge"
And I should not see "There are no matching badges available for users to earn"

@javascript
Scenario: Award site badge
Expand Down Expand Up @@ -169,7 +179,7 @@ Feature: Award badges
| badge | Course Badge |
| role | editingteacher |
And I am on the "Course 1" "course" page logged in as "teacher1"
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge"
And I select "Recipients (0)" from the "jump" singleselect
And I press "Award badge"
Expand All @@ -178,7 +188,7 @@ Feature: Award badges
And I set the field "potentialrecipients[]" to "Student 1 ([email protected])"
When I press "Award badge"
And I am on "Course 1" course homepage
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge"
Then I should see "Recipients (2)"
And I log out
Expand All @@ -198,7 +208,7 @@ Feature: Award badges
| status | 0 |
| type | 2 |
And I am on the "Course 1" "course" page logged in as "teacher1"
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge"
And I select "Criteria" from the "jump" singleselect
And I set the field "type" to "Activity completion"
Expand Down Expand Up @@ -240,7 +250,7 @@ Feature: Award badges
And I set the field "Assignment - Music history" to "1"
And I press "Save changes"
And I am on "Course 1" course homepage
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge"
And I select "Criteria" from the "jump" singleselect
And I set the field "type" to "Course completion"
Expand Down Expand Up @@ -280,15 +290,15 @@ Feature: Award badges
| badge | Course Badge 1 |
| role | editingteacher |
And I am on the "Course 1" "course" page logged in as "teacher1"
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge 1"
And I select "Recipients (0)" from the "jump" singleselect
And I press "Award badge"
# Award course badge 1 to student 1.
And I set the field "potentialrecipients[]" to "Student 1 ([email protected])"
When I press "Award badge"
And I am on "Course 1" course homepage
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge 1"
And I select "Recipients (1)" from the "jump" singleselect
Then I should see "Recipients (1)"
Expand All @@ -300,7 +310,7 @@ Feature: Award badges
| image | badges/tests/behat/badge.png |
| status | 0 |
| type | 2 |
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge 2"
And I select "Criteria" from the "jump" singleselect
And I set the field "type" to "Manual issue by role"
Expand All @@ -317,7 +327,7 @@ Feature: Award badges
And I set the field "potentialrecipients[]" to "Student 2 ([email protected])"
When I press "Award badge"
And I am on "Course 1" course homepage
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge 2"
And I select "Recipients (1)" from the "jump" singleselect
Then I should see "Recipients (1)"
Expand Down Expand Up @@ -350,7 +360,7 @@ Feature: Award badges
| badge | Course Badge |
| role | editingteacher |
And I am on the "Course 1" "course" page logged in as "teacher1"
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge"
And I select "Recipients (0)" from the "jump" singleselect
And I press "Award badge"
Expand All @@ -359,7 +369,7 @@ Feature: Award badges
And I set the field "potentialrecipients[]" to "Student 1 ([email protected])"
When I press "Award badge"
And I am on "Course 1" course homepage
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge"
Then I should see "Recipients (2)"
And I select "Recipients (2)" from the "jump" singleselect
Expand All @@ -369,6 +379,6 @@ Feature: Award badges
And I set the field "existingrecipients[]" to "Student 1 ([email protected])"
When I press "Revoke badge"
And I am on "Course 1" course homepage
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge"
Then I should see "Recipients (0)"
16 changes: 8 additions & 8 deletions badges/tests/behat/award_badge_groups.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Feature: Award badges with separate groups
| status | 0 |
| type | 2 |
And I am on the "Course 1" "course" page logged in as "teacher1"
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge"
And I select "Criteria" from the "jump" singleselect
And I set the field "type" to "Manual issue by role"
Expand All @@ -55,7 +55,7 @@ Feature: Award badges with separate groups
Scenario: Award course badge as non-editing teacher with only one group
When I log in as "teacher2"
And I am on "Course 1" course homepage
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge"
And I press "Award badge"
And I set the field "role" to "Non-editing teacher"
Expand All @@ -68,7 +68,7 @@ Feature: Award badges with separate groups
And I set the field "potentialrecipients[]" to "Student 2 ([email protected])"
And I press "Award badge"
And I am on "Course 1" course homepage
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge"
And I should see "Recipients (1)"
And I log out
Expand All @@ -89,7 +89,7 @@ Feature: Award badges with separate groups
And I log out
When I log in as "teacher2"
And I am on "Course 1" course homepage
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge"
And I press "Award badge"
And I set the field "role" to "Non-editing teacher"
Expand All @@ -114,7 +114,7 @@ Feature: Award badges with separate groups
And I log out
When I log in as "teacher2"
And I am on "Course 1" course homepage
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge"
And I press "Award badge"
# Teacher 2 shouldn't be able to go further
Expand All @@ -123,7 +123,7 @@ Feature: Award badges with separate groups
@javascript
Scenario: Editing teacher can award badge to members of separate groups
Given I am on the "Course 1" course page logged in as teacher1
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge"
And I press "Award badge"
When I set the field "role" to "Teacher"
Expand Down Expand Up @@ -155,7 +155,7 @@ Feature: Award badges with separate groups
And I set the field "Group mode" to "Visible groups"
And I press "Save and display"
When I am on the "Course 1" course page logged in as <loggedinuser>
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge"
And I press "Award badge"
And I set the field "role" to "<awarder>"
Expand Down Expand Up @@ -196,7 +196,7 @@ Feature: Award badges with separate groups
And I set the field "Group mode" to "No groups"
And I press "Save and display"
When I am on the "Course 1" course page logged in as <loggedinuser>
And I navigate to "Badges > Manage badges" in current page administration
And I navigate to "Badges" in current page administration
And I follow "Course Badge"
And I press "Award badge"
And I set the field "role" to "<awarder>"
Expand Down
Loading

0 comments on commit 2f4efdb

Please sign in to comment.