mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-39153 webservices: Provide alternative to passing contextids
As per our policy webservices should never have a required contextid, thuse providing a support for passing contextlevel and instanceid as parameters to the api
This commit is contained in:
parent
c0fb582c58
commit
1e63179285
2 changed files with 20 additions and 4 deletions
|
@ -115,7 +115,7 @@ class core_role_external_testcase extends externallib_advanced_testcase {
|
|||
$users = get_role_users(3, $context);
|
||||
$this->assertEquals(count($users), 1);
|
||||
|
||||
// Call the external function. Assign teacher role to $USER.
|
||||
// Call the external function. Unassign teacher role using contextid.
|
||||
core_role_external::unassign_roles(array(
|
||||
array('roleid' => 3, 'userid' => $USER->id, 'contextid' => $context->id)));
|
||||
|
||||
|
@ -123,6 +123,19 @@ class core_role_external_testcase extends externallib_advanced_testcase {
|
|||
$users = get_role_users(3, $context);
|
||||
$this->assertEquals(count($users), 0);
|
||||
|
||||
// Add teacher role to $USER on course context.
|
||||
role_assign(3, $USER->id, $context->id);
|
||||
$users = get_role_users(3, $context);
|
||||
$this->assertEquals(count($users), 1);
|
||||
|
||||
// Call the external function. Unassign teacher role using context level and instanceid.
|
||||
core_role_external::unassign_roles(array(
|
||||
array('roleid' => 3, 'userid' => $USER->id, 'contextlevel' => "course", 'instanceid' => $course->id)));
|
||||
|
||||
// Check the role has been unassigned on course context.
|
||||
$users = get_role_users(3, $context);
|
||||
$this->assertEquals(count($users), 0);
|
||||
|
||||
// Call without required capability.
|
||||
$this->unassignUserCapability('moodle/role:assign', $context->id, $roleid);
|
||||
$this->setExpectedException('moodle_exception');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue