Exemple #1
0
 /**
  * Returns description of method result value
  *
  * @return null
  * @since Moodle 2.0
  * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
  * @todo MDL-31194 This will be deleted in Moodle 2.5.
  * @see core_role_external::unassign_roles_returns()
  */
 public static function role_unassign_returns()
 {
     return core_role_external::unassign_roles_returns();
 }
Exemple #2
0
 /**
  * Test unassign_roles
  */
 public function test_unassign_roles()
 {
     global $USER;
     $this->resetAfterTest(true);
     $course = self::getDataGenerator()->create_course();
     // Set the required capabilities by the external function.
     $context = context_course::instance($course->id);
     $roleid = $this->assignUserCapability('moodle/role:assign', $context->id);
     $this->assignUserCapability('moodle/course:view', $context->id, $roleid);
     // Add manager role to $USER.
     // So $USER is allowed to assign 'manager', 'editingteacher', 'teacher' and 'student'.
     role_assign(1, $USER->id, context_system::instance()->id);
     // Add teacher role to $USER on course context.
     role_assign(3, $USER->id, $context->id);
     // Check the teacher role has been assigned to $USER on course context.
     $users = get_role_users(3, $context);
     $this->assertEquals(count($users), 1);
     // Call the external function. Assign teacher role to $USER.
     core_role_external::unassign_roles(array(array('roleid' => 3, 'userid' => $USER->id, 'contextid' => $context->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');
     $categories = core_role_external::unassign_roles(array('roleid' => 3, 'userid' => $USER->id, 'contextid' => $context->id));
 }