mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-39152 phpunit: improve tests for assign_roles()
core_role_external::assign_roles() now support alternative paramaters instead of contextid. Test working of those. Also test the parameters validation a bit, since these are no longer automatically tested being optional now
This commit is contained in:
parent
3a68f79809
commit
95a3bb4dc8
1 changed files with 47 additions and 1 deletions
|
@ -199,7 +199,7 @@ class core_role_external_testcase extends externallib_advanced_testcase {
|
|||
$users = get_role_users(3, $context);
|
||||
$this->assertEquals(count($users), 0);
|
||||
|
||||
// Call the external function. Assign teacher role to $USER.
|
||||
// Call the external function. Assign teacher role to $USER with contextid.
|
||||
core_role_external::assign_roles(array(
|
||||
array('roleid' => 3, 'userid' => $USER->id, 'contextid' => $context->id)));
|
||||
|
||||
|
@ -207,6 +207,17 @@ class core_role_external_testcase extends externallib_advanced_testcase {
|
|||
$users = get_role_users(3, $context);
|
||||
$this->assertEquals(count($users), 1);
|
||||
|
||||
// Unassign role.
|
||||
role_unassign(3, $USER->id, $context->id);
|
||||
$users = get_role_users(3, $context);
|
||||
$this->assertEquals(count($users), 0);
|
||||
|
||||
// Call the external function. Assign teacher role to $USER.
|
||||
core_role_external::assign_roles(array(
|
||||
array('roleid' => 3, 'userid' => $USER->id, 'contextlevel' => "course", 'instanceid' => $course->id)));
|
||||
$users = get_role_users(3, $context);
|
||||
$this->assertEquals(count($users), 1);
|
||||
|
||||
// Call without required capability.
|
||||
$this->unassignUserCapability('moodle/role:assign', $context->id, $roleid);
|
||||
$this->setExpectedException('moodle_exception');
|
||||
|
@ -214,6 +225,41 @@ class core_role_external_testcase extends externallib_advanced_testcase {
|
|||
array('roleid' => 3, 'userid' => $USER->id, 'contextid' => $context->id));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test assign_roles() parameter validation
|
||||
*/
|
||||
public function test_assign_roles_params() {
|
||||
global $USER;
|
||||
|
||||
// Call without correct context details.
|
||||
$this->setExpectedException('invalid_parameter_exception');
|
||||
core_role_external::assign_roles(array('roleid' => 3, 'userid' => $USER->id));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test assign_roles() parameter validation
|
||||
*/
|
||||
public function test_assign_roles_params2() {
|
||||
global $USER;
|
||||
|
||||
// Call without correct context details.
|
||||
$this->setExpectedException('invalid_parameter_exception');
|
||||
core_role_external::assign_roles(array('roleid' => 3, 'userid' => $USER->id, 'contextlevel' => "course"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test assign_roles() parameter validation
|
||||
*/
|
||||
public function test_assign_roles_params3() {
|
||||
global $USER;
|
||||
|
||||
// Call without correct context details.
|
||||
$this->resetAfterTest(true);
|
||||
$course = self::getDataGenerator()->create_course();
|
||||
$this->setExpectedException('invalid_parameter_exception');
|
||||
core_role_external::assign_roles(array('roleid' => 3, 'userid' => $USER->id, 'instanceid' => $course->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test unassign_roles
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue