@core @core_badges @_file_upload Feature: Award badges In order to award badges to users for their achievements As an admin I need to add criteria to badges in the system @javascript Scenario: Award profile badge Given I log in as "admin" And I navigate to "Add a new badge" node in "Site administration > Badges" And I set the following fields to these values: | Name | Profile Badge | | Description | Test badge description | | issuername | Test Badge Site | | issuercontact | testuser@test-badge-site.com | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Profile completion" And I set the field "First name" to "1" And I set the field "Email address" to "1" And I set the field "Phone" to "1" When I press "Save" Then I should see "Profile completion" And I should see "First name" And I should see "Email address" And I should not see "Criteria for this badge have not been set up yet." And I press "Enable access" And I press "Continue" And I expand "My profile settings" node And I follow "Edit profile" And I expand all fieldsets And I set the field "Phone" to "123456789" And I press "Update profile" And I navigate to "My badges" node in "My profile" Then I should see "Profile Badge" And I should not see "There are no badges available." @javascript Scenario: Award site badge Given the following "users" exist: | username | firstname | lastname | email | | teacher | teacher | 1 | teacher1@asd.com | | student | student | 1 | student1@asd.com | And I log in as "admin" And I navigate to "Add a new badge" node in "Site administration > Badges" And I set the following fields to these values: | Name | Site Badge | | Description | Site badge description | | issuername | Tester of site badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Manual issue by role" And I set the field "Teacher" to "1" And I press "Save" And I press "Enable access" And I press "Continue" And I follow "Recipients (0)" And I press "Award badge" And I set the field "potentialrecipients[]" to "teacher 1 (teacher1@asd.com)" And I press "Award badge" And I set the field "potentialrecipients[]" to "student 1 (student1@asd.com)" And I press "Award badge" When I follow "Site Badge" Then I should see "Recipients (2)" And I log out And I log in as "student" And I navigate to "My badges" node in "My profile" Then I should see "Site Badge" @javascript Scenario: Award course badge Given the following "users" exist: | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@asd.com | | student1 | Student | 1 | student1@asd.com | | student2 | Student | 2 | student2@asd.com | And the following "courses" exist: | fullname | shortname | category | groupmode | | Course 1 | C1 | 0 | 1 | And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | | student1 | C1 | student | | student2 | C1 | student | And I log in as "teacher1" And I follow "Course 1" And I navigate to "Add a new badge" node in "Course administration > Badges" And I follow "Add a new badge" And I set the following fields to these values: | Name | Course Badge | | Description | Course badge description | | issuername | Tester of course badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Manual issue by role" And I set the field "Teacher" to "1" And I press "Save" And I press "Enable access" And I press "Continue" And I follow "Recipients (0)" And I press "Award badge" And I set the field "potentialrecipients[]" to "Student 2 (student2@asd.com)" And I press "Award badge" And I set the field "potentialrecipients[]" to "Student 1 (student1@asd.com)" When I press "Award badge" And I follow "Course Badge" Then I should see "Recipients (2)" And I log out And I log in as "student1" And I follow "Course 1" And I navigate to "My badges" node in "My profile" Then I should see "Course Badge" @javascript Scenario: Award badge on activity completion Given the following "courses" exist: | fullname | shortname | category | | Course 1 | C1 | 0 | And the following "users" exist: | username | firstname | lastname | email | | teacher1 | Teacher | Frist | teacher1@asd.com | | student1 | Student | First | student1@asd.com | And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | | student1 | C1 | student | And I log in as "admin" And I set the following administration settings values: | Enable completion tracking | 1 | And I follow "Home" And I follow "Course 1" And I follow "Edit settings" And I set the following fields to these values: | Enable completion tracking | Yes | And I press "Save changes" And I turn editing mode on And I add a "Assignment" to section "1" and I fill the form with: | Assignment name | Test assignment name | | Description | Submit your online text | And I log out And I log in as "teacher1" And I follow "Course 1" And I navigate to "Add a new badge" node in "Course administration > Badges" And I follow "Add a new badge" And I set the following fields to these values: | Name | Course Badge | | Description | Course badge description | | issuername | Tester of course badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Activity completion" And I set the field "Test assignment name" to "1" And I press "Save" And I press "Enable access" When I press "Continue" And I log out And I log in as "student1" And I follow "Course 1" And I navigate to "My badges" node in "My profile" Then I should see "There are no badges available." And I follow "Home" And I follow "Course 1" And I press "Mark as complete: Test assignment name" And I navigate to "My badges" node in "My profile" Then I should see "Course Badge" @javascript Scenario: Award badge on course completion Given the following "courses" exist: | fullname | shortname | category | | Course 1 | C1 | 0 | And the following "users" exist: | username | firstname | lastname | email | | teacher1 | Teacher | Frist | teacher1@asd.com | | student1 | Student | First | student1@asd.com | And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | | student1 | C1 | student | And I log in as "admin" And I set the following administration settings values: | Enable completion tracking | 1 | And I follow "Home" And I follow "Course 1" And I follow "Edit settings" And I set the following fields to these values: | Enable completion tracking | Yes | And I press "Save changes" And I turn editing mode on And I add a "Assignment" to section "1" and I fill the form with: | Assignment name | Test assignment name | | Description | Submit your online text | | assignsubmission_onlinetext_enabled | 1 | And I follow "Course completion" And I set the field "id_overall_aggregation" to "2" And I click on "Condition: Activity completion" "link" And I set the field "Assign - Test assignment name" to "1" And I press "Save changes" And I log out And I log in as "teacher1" And I follow "Course 1" And I navigate to "Add a new badge" node in "Course administration > Badges" And I follow "Add a new badge" And I set the following fields to these values: | Name | Course Badge | | Description | Course badge description | | issuername | Tester of course badge | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Course completion" And I set the field with xpath "//fieldset/input[1]" to "0" And I press "Save" And I press "Enable access" When I press "Continue" And I log out And I log in as "student1" And I follow "Course 1" And I navigate to "My badges" node in "My profile" Then I should see "There are no badges available." And I follow "Home" And I follow "Course 1" And I press "Mark as complete: Test assignment name" And I log out And I log in as "admin" # We can't wait for cron to happen, so the admin manually triggers it. And I trigger cron # The admin needs to trigger cron twice to see the completion status as completed. # We wait more than 1 minute because of the next cron run scheduled time. And I wait "61" seconds And I trigger cron # Finally the admin goes back to homepage to continue the user story. And I am on homepage And I log out And I log in as "student1" And I navigate to "My badges" node in "My profile" Then I should see "Course Badge"