From 8dcf12afdc6ba8b35153f9db97a5ff96df7bffb1 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Wed, 31 Aug 2016 14:07:38 +0800 Subject: [PATCH 1/2] MDL-53893 core_badges: Add strictness to manual badge criteria --- badges/criteria/award_criteria_manual.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/badges/criteria/award_criteria_manual.php b/badges/criteria/award_criteria_manual.php index fd0ad2ead5d..51a7959d0ad 100644 --- a/badges/criteria/award_criteria_manual.php +++ b/badges/criteria/award_criteria_manual.php @@ -207,12 +207,15 @@ class award_criteria_manual extends award_criteria { return array($join, $where, $params); } else { foreach ($this->params as $param) { - $join .= " LEFT JOIN {badge_manual_award} bma{$param['role']} ON - bma{$param['role']}.recipientid = u.id AND - bma{$param['role']}.issuerrole = :issuerrole{$param['role']} "; - $where .= " AND bma{$param['role']}.issuerrole IS NOT NULL "; + $roledata[] = " bma.issuerrole = :issuerrole{$param['role']} "; $params["issuerrole{$param['role']}"] = $param['role']; } + if (!empty($roledata)) { + $extraon = implode(' AND ', $roledata); + $join = " JOIN {badge_manual_award} bma ON bma.recipientid = u.id + AND bma.badgeid = :badgeid{$this->badgeid} AND ({$extraon})"; + $params["badgeid{$this->badgeid}"] = $this->badgeid; + } return array($join, $where, $params); } } From 95c919d651d294133f860a601fe5fa02944b45b1 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Thu, 1 Sep 2016 10:49:38 +0800 Subject: [PATCH 2/2] MDL-53893 core_badges: Behat for all selected roles award badges --- badges/tests/behat/award_badge.feature | 83 ++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/badges/tests/behat/award_badge.feature b/badges/tests/behat/award_badge.feature index efbab25bd9a..f93cceaad7f 100644 --- a/badges/tests/behat/award_badge.feature +++ b/badges/tests/behat/award_badge.feature @@ -231,3 +231,86 @@ Feature: Award badges And I log in as "student1" And I follow "Profile" in the user menu Then I should see "Course Badge" + + @javascript + Scenario: All of the selected roles can award badges + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + | student1 | Student | 1 | student1@example.com | + | student2 | Student | 2 | student2@example.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" + # Create course badge 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 1 | + | 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 expand all fieldsets + # Set to ANY of the roles awards badge. + And I set the field "Teacher" to "1" + And I set the field "Any of the selected roles awards the badge" 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" + # Award course badge 1 to student 1. + And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)" + When I press "Award badge" + And I follow "Course Badge 1" + And I follow "Recipients (1)" + Then I should see "Recipients (1)" + # Add course badge 2. + 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 2 | + | 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 expand all fieldsets + # Set to ALL of the selected roles award badge. + And I set the field "Teacher" to "1" + And I set the field "All of the selected roles award the badge" 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" + # Award course badge 2 to student 2. + And I set the field "potentialrecipients[]" to "Student 2 (student2@example.com)" + When I press "Award badge" + And I follow "Course Badge 2" + And I follow "Recipients (1)" + Then I should see "Recipients (1)" + And I log out + And I trigger cron + # Student 1 should have just course badge 1. + And I log in as "student1" + And I follow "Profile" in the user menu + When I follow "Course 1" + Then I should see "Course Badge 1" + And I should not see "Course Badge 2" + And I log out + # Student 2 should have just course badge 2. + And I log in as "student2" + And I follow "Profile" in the user menu + When I follow "Course 1" + Then I should see "Course Badge 2" + Then I should not see "Course Badge 1"