Merge branch 'MDL-42326_25' of git://github.com/dmonllao/moodle into MOODLE_25_STABLE
This commit is contained in:
@@ -65,6 +65,37 @@ Feature: Set up contextual data for tests
|
||||
And I should see "Grouping 1"
|
||||
And I should see "Grouping 2"
|
||||
|
||||
@javascript
|
||||
Scenario: Role overrides
|
||||
Given the following "users" exists:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@asd.com |
|
||||
| student1 | Student | 1 | student1@asd.com |
|
||||
And the following "categories" exists:
|
||||
| name | category | idnumber |
|
||||
| Cat 1 | 0 | CAT1 |
|
||||
And the following "courses" exists:
|
||||
| fullname | shortname |
|
||||
| Course 1 | C1 |
|
||||
And the following "course enrolments" exists:
|
||||
| user | course | role |
|
||||
| student1 | C1 | student |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
And the following "permission overrides" exists:
|
||||
| capability | permission | role | contextlevel | reference |
|
||||
| mod/forum:editanypost | Allow | student | Course | C1 |
|
||||
| mod/forum:replynews | Prevent | editingteacher | Course | C1 |
|
||||
When I log in as "admin"
|
||||
And I follow "Course 1"
|
||||
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
|
||||
And I press "Cancel"
|
||||
And I select "Teacher (1)" from "Advanced role override"
|
||||
And the "mod/forum:replynews" field should match "-1" value
|
||||
And I press "Cancel"
|
||||
|
||||
Scenario: Add course enrolments
|
||||
Given the following "users" exists:
|
||||
| username | firstname | lastname | email |
|
||||
|
||||
@@ -50,6 +50,10 @@ use Behat\Behat\Exception\PendingException as PendingException;
|
||||
*/
|
||||
class behat_data_generators extends behat_base {
|
||||
|
||||
const cap_allow = 'Allow';
|
||||
const cap_prevent = 'Prevent';
|
||||
const cap_prohibit = 'Prohibit';
|
||||
|
||||
/**
|
||||
* @var testing_data_generator
|
||||
*/
|
||||
@@ -93,6 +97,11 @@ class behat_data_generators extends behat_base {
|
||||
'switchids' => array('user' => 'userid', 'course' => 'courseid', 'role' => 'roleid')
|
||||
|
||||
),
|
||||
'permission overrides' => array(
|
||||
'datagenerator' => 'permission_override',
|
||||
'required' => array('capability', 'permission', 'role', 'contextlevel', 'reference'),
|
||||
'switchids' => array('role' => 'roleid')
|
||||
),
|
||||
'system role assigns' => array(
|
||||
'datagenerator' => 'system_role_assign',
|
||||
'required' => array('user', 'role'),
|
||||
@@ -277,6 +286,40 @@ class behat_data_generators extends behat_base {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows/denies a capability at the specified context
|
||||
*
|
||||
* @throws Exception
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
protected function process_permission_override($data) {
|
||||
|
||||
// Will throw an exception if it does not exist.
|
||||
$context = $this->get_context($data['contextlevel'], $data['reference']);
|
||||
|
||||
switch ($data['permission']) {
|
||||
case self::cap_allow:
|
||||
$permission = CAP_ALLOW;
|
||||
break;
|
||||
case self::cap_prevent:
|
||||
$permission = CAP_PREVENT;
|
||||
break;
|
||||
case self::cap_prohibit:
|
||||
$permission = CAP_PROHIBIT;
|
||||
break;
|
||||
default:
|
||||
throw new Exception('The \'' . $data['permission'] . '\' permission does not exist');
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_null(get_capability_info($data['capability']))) {
|
||||
throw new Exception('The \'' . $data['capability'] . '\' capability does not exist');
|
||||
}
|
||||
|
||||
role_change_permission($data['roleid'], $context, $data['capability'], $permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns a role to a user at system context
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user