From c7cc3271c0d52cadb22d96a65de27993bc854a72 Mon Sep 17 00:00:00 2001 From: Jerome Mouneyrac Date: Thu, 24 Oct 2013 11:43:04 +0800 Subject: [PATCH] MDL-42332 Automate MDLQA-5260 and MDLQA-5261 - A badge can be awarded based on activity and course completion + add i_trigger_cron behat step --- badges/tests/behat/award_badge.feature | 129 +++++++++++++++++++++++++ lib/tests/behat/behat_general.php | 9 ++ 2 files changed, 138 insertions(+) diff --git a/badges/tests/behat/award_badge.feature b/badges/tests/behat/award_badge.feature index 032fc5ec2e7..7cdd2dd090f 100644 --- a/badges/tests/behat/award_badge.feature +++ b/badges/tests/behat/award_badge.feature @@ -118,4 +118,133 @@ Feature: Award badges And I follow "Course 1" And I expand "My profile" node And I follow "My badges" + Then I should see "Course Badge" + + @javascript + Scenario: Award badge on activity completion + Given the following "courses" exists: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "users" exists: + | username | firstname | lastname | email | + | teacher1 | Teacher | Frist | teacher1@asd.com | + | student1 | Student | First | student1@asd.com | + And the following "course enrolments" exists: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And I log out + 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 fill the moodle form with: + | 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 click on "//span[text()='Badges']" "xpath_element" in the "Administration" "block" + And I follow "Add a new badge" + And I fill the moodle form with: + | Name | Course Badge | + | Description | Course badge description | + | issuername | Tester of course badge | + And I upload "badges/tests/behat/badge.png" file to "Image" filepicker + And I press "Create badge" + And I select "Activity completion" from "type" + And I check "Test assignment name" + 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 expand "My profile" node + And I follow "My badges" + 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 expand "My profile" node + And I follow "My badges" + Then I should see "Course Badge" + + @javascript + Scenario: Award badge on course completion + Given the following "courses" exists: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "users" exists: + | username | firstname | lastname | email | + | teacher1 | Teacher | Frist | teacher1@asd.com | + | student1 | Student | First | student1@asd.com | + And the following "course enrolments" exists: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And I log out + 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 fill the moodle form with: + | 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 select "2" from "id_overall_aggregation" + And I click on "Condition: Activity completion" "link" + And I check "Assign - Test assignment name" + And I press "Save changes" + And I log out + And I log in as "teacher1" + And I follow "Course 1" + And I click on "//span[text()='Badges']" "xpath_element" in the "Administration" "block" + And I follow "Add a new badge" + And I fill the moodle form with: + | Name | Course Badge | + | Description | Course badge description | + | issuername | Tester of course badge | + And I upload "badges/tests/behat/badge.png" file to "Image" filepicker + And I press "Create badge" + And I select "Course completion" from "type" + And I fill the moodle form with: + | grade_2 | 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 expand "My profile" node + And I follow "My badges" + 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. + 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 expand "My profile" node + And I follow "My badges" Then I should see "Course Badge" \ No newline at end of file diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index c95940bf4e9..d0122352c36 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -529,4 +529,13 @@ class behat_general extends behat_base { } } + /** + * This step triggers cron like a user would do going to admin/cron.php. + * + * @Given /^I trigger cron$/ + */ + public function i_trigger_cron() { + $this->getSession()->visit($this->locate_path('/admin/cron.php')); + } + }