diff --git a/admin/tool/behat/tests/behat/data_generators.feature b/admin/tool/behat/tests/behat/data_generators.feature index 558c848b264..1480ff990f9 100644 --- a/admin/tool/behat/tests/behat/data_generators.feature +++ b/admin/tool/behat/tests/behat/data_generators.feature @@ -90,10 +90,10 @@ Feature: Set up contextual data for tests And I expand "Users" node And I follow "Permissions" And I select "Student (1)" from "Advanced role override" - Then the "mod/forum:editanypost" field should match "1" value + Then "mod/forum:editanypost" capability has "Allow" permission And I press "Cancel" And I select "Teacher (1)" from "Advanced role override" - And the "mod/forum:replynews" field should match "-1" value + And "mod/forum:replynews" capability has "Prevent" permission And I press "Cancel" Scenario: Add course enrolments diff --git a/admin/tool/behat/tests/behat/edit_permissions.feature b/admin/tool/behat/tests/behat/edit_permissions.feature index b16b0e0c8a0..a7935b9cbae 100644 --- a/admin/tool/behat/tests/behat/edit_permissions.feature +++ b/admin/tool/behat/tests/behat/edit_permissions.feature @@ -25,10 +25,10 @@ Feature: Edit capabilities | moodle/grade:managesharedforms | Prevent | | moodle/course:request | Prohibit | When I follow "Edit Teacher role" - Then the "block/mnet_hosts:myaddinstance" field should match "1" value - And the "moodle/community:add" field should match "0" value - And the "moodle/grade:managesharedforms" field should match "-1" value - And the "moodle/course:request" field should match "-1000" value + Then "block/mnet_hosts:myaddinstance" capability has "Allow" permission + And "moodle/community:add" capability has "Not set" permission + And "moodle/grade:managesharedforms" capability has "Prevent" permission + And "moodle/course:request" capability has "Prohibit" permission @javascript Scenario: Course capabilities overrides @@ -41,9 +41,9 @@ Feature: Edit capabilities | mod/forum:editanypost | Prevent | | mod/forum:addquestion | Allow | When I select "Student (3)" from "Advanced role override" - Then the "mod/forum:deleteanypost" field should match "-1000" value - And the "mod/forum:editanypost" field should match "-1" value - And the "mod/forum:addquestion" field should match "1" value + Then "mod/forum:deleteanypost" capability has "Prohibit" permission + And "mod/forum:editanypost" capability has "Prevent" permission + And "mod/forum:addquestion" capability has "Allow" permission @javascript Scenario: Module capabilities overrides @@ -60,6 +60,6 @@ Feature: Edit capabilities | mod/forum:editanypost | Prevent | | mod/forum:addquestion | Allow | When I select "Student (3)" from "Advanced role override" - Then the "mod/forum:deleteanypost" field should match "-1000" value - And the "mod/forum:editanypost" field should match "-1" value - And the "mod/forum:addquestion" field should match "1" value + Then "mod/forum:deleteanypost" capability has "Prohibit" permission + And "mod/forum:editanypost" capability has "Prevent" permission + And "mod/forum:addquestion" capability has "Allow" permission diff --git a/lib/tests/behat/behat_data_generators.php b/lib/tests/behat/behat_data_generators.php index 0a5b39007a7..18dfb22bf57 100644 --- a/lib/tests/behat/behat_data_generators.php +++ b/lib/tests/behat/behat_data_generators.php @@ -299,13 +299,13 @@ class behat_data_generators extends behat_base { $context = $this->get_context($data['contextlevel'], $data['reference']); switch ($data['permission']) { - case self::cap_allow: + case get_string('allow', 'role'): $permission = CAP_ALLOW; break; - case self::cap_prevent: + case get_string('prevent', 'role'): $permission = CAP_PREVENT; break; - case self::cap_prohibit: + case get_string('prohibit', 'role'): $permission = CAP_PROHIBIT; break; default: diff --git a/lib/tests/behat/behat_permissions.php b/lib/tests/behat/behat_permissions.php index 562be1a709f..ec265f9ce5e 100644 --- a/lib/tests/behat/behat_permissions.php +++ b/lib/tests/behat/behat_permissions.php @@ -142,4 +142,44 @@ class behat_permissions extends behat_base { } } + /** + * Checks if the capability has the specified permission. Works in the role definition advanced page. + * + * @Then /^"(?P(?:[^"]|\\")*)" capability has "(?PNot set|Allow|Prevent|Prohibit)" permission$/ + * @throws ExpectationException + * @param string $capabilityname + * @param string $permission + * @return void + */ + public function capability_has_permission($capabilityname, $permission) { + + // We already know the name, so we just need the value. + $radioxpath = "//table[@class='rolecap']/descendant::input[@type='radio']" . + "[@name='" . $capabilityname . "'][@checked]"; + + $checkedradio = $this->find('xpath', $radioxpath); + + switch ($permission) { + case get_string('notset', 'role'): + $perm = CAP_INHERIT; + break; + case get_string('allow', 'role'): + $perm = CAP_ALLOW; + break; + case get_string('prevent', 'role'): + $perm = CAP_PREVENT; + break; + case get_string('prohibit', 'role'): + $perm = CAP_PROHIBIT; + break; + default: + throw new ExpectationException('"' . $permission . '" permission does not exist', $this->getSession()); + break; + } + + if ($checkedradio->getAttribute('value') != $perm) { + throw new ExpectationException('"' . $capabilityname . '" permission is not "' . $permission . '"', $this->getSession()); + } + } + }