Skip to content

Commit

Permalink
Merge branch 'MDL-23839-28' of git://github.com/andrewnicols/moodle i…
Browse files Browse the repository at this point in the history
…nto MOODLE_28_STABLE
  • Loading branch information
Sam Hemelryk committed Nov 25, 2014
2 parents e8ffea7 + 5c86569 commit b3351c0
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
42 changes: 42 additions & 0 deletions course/tests/behat/category_role_assignment.feature
@@ -0,0 +1,42 @@
@core @core_course
Feature: Role assignments can be made at the category level
In order to grant a user different capabilities
As a user
I can assign roles in categories

Background:
Given the following "users" exist:
| username | firstname | lastname |
| manager | Manager | Manager |
And the following "categories" exist:
| name | category | idnumber |
| Cat 1 | 0 | CAT1 |
And the following "role assigns" exist:
| user | role | contextlevel | reference |
| manager | manager | Category | CAT1 |
And I log in as "admin"


@javascript
Scenario: A user with a category role can assign roles
Given I define the allowed role assignments for the "Manager" role as:
| Teacher | Assignable |
And I log out
And I log in as "manager"
And I follow "Courses"
When I follow "Cat 1"
Then I should see "Assign roles"

@javascript
Scenario: A user with a category role cannot assign roles if there are no roles to assign
Given I define the allowed role assignments for the "Manager" role as:
| Manager | Not assignable |
| Course creator | Not assignable |
| Teacher | Not assignable |
| Non-editing teacher | Not assignable |
| Student | Not assignable |
And I log out
And I log in as "manager"
And I follow "Courses"
When I follow "Cat 1"
Then I should not see "Assign roles"
2 changes: 1 addition & 1 deletion lib/navigationlib.php
Expand Up @@ -4415,7 +4415,7 @@ protected function load_category_settings() {
}

// Assign local roles
if (has_capability('moodle/role:assign', $catcontext)) {
if (!empty(get_assignable_roles($catcontext))) {
$assignurl = new moodle_url('/'.$CFG->admin.'/roles/assign.php', array('contextid' => $catcontext->id));
$categorynode->add(get_string('assignroles', 'role'), $assignurl, self::TYPE_SETTING, null, 'roles', new pix_icon('i/assignroles', ''));
}
Expand Down
57 changes: 57 additions & 0 deletions lib/tests/behat/behat_permissions.php
Expand Up @@ -176,4 +176,61 @@ public function capability_has_permission($capabilityname, $permission) {
}
}

/**
* Set the allowed role assignments for the specified role.
*
* @Given /^I define the allowed role assignments for the "(?P<rolefullname_string>(?:[^"]|\\")*)" role as:$/
* @param string $rolename
* @param TableNode $table
* @return void Executes other steps
*/
public function i_define_the_allowed_role_assignments_for_a_role_as($rolename, $table) {
$parentnodes = get_string('administrationsite') . ' > ' .
get_string('users', 'admin') . ' > ' .
get_string('permissions', 'role');
return array(
new Given('I am on homepage'),
new Given('I navigate to "' . get_string('defineroles', 'role') . '" node in "' . $parentnodes . '"'),
new Given('I follow "Allow role assignments"'),
new Given('I fill in the allowed role assignments form for the "' . $rolename . '" role with:', $table),
new Given('I press "' . get_string('savechanges') . '"')
);
}

/**
* Fill in the allowed role assignments form for the specied role.
*
* Takes a table with two columns. Each row should contain the target
* role, and either "Assignable" or "Not assignable".
*
* @Given /^I fill in the allowed role assignments form for the "(?P<rolefullname_string>(?:[^"]|\\")*)" role with:$/
* @param String $sourcerole
* @param TableNode $table
* @return void
*/
public function i_fill_in_the_allowed_role_assignments_form_for_a_role_with($sourcerole, $table) {
foreach ($table->getRows() as $key => $row) {
list($targetrole, $allowed) = $row;

$node = $this->find('xpath', '//input[@title="Allow users with role ' .
$sourcerole .
' to assign the role ' .
$targetrole . '"]');

if ($allowed == 'Assignable') {
if (!$node->isChecked()) {
$node->click();
}
} else if ($allowed == 'Not assignable') {
if ($node->isChecked()) {
$node->click();
}
} else {
throw new ExpectationException(
'The provided permission value "' . $allowed . '" is not valid. Use Assignable, or Not assignable',
$this->getSession()
);
}
}
}
}

0 comments on commit b3351c0

Please sign in to comment.