web service MDL-12886 if the groupid doesn't exist, groups_remove_member and groups_add_member return now exception (not a boolean as before)

This commit is contained in:
jerome 2009-03-09 04:49:50 +00:00
parent 15b60b640f
commit 9c000a991f
3 changed files with 10 additions and 8 deletions

View File

@ -686,9 +686,11 @@ if ($formdata = $mform->is_cancelled()) {
$gid = $ccache[$shortname]->groups[$addgroup]->id;
$gname = $ccache[$shortname]->groups[$addgroup]->name;
if (groups_add_member($gid, $user->id)) {
$upt->track('enrolments', get_string('addedtogroup', '', $gname));
} else {
try {
if (groups_add_member($gid, $user->id)) {
$upt->track('enrolments', get_string('addedtogroup', '', $gname));
}
} catch (moodle_exception $e) {
$upt->track('enrolments', get_string('addedtogroupnot', '', $gname), 'error');
continue;
}

View File

@ -28,7 +28,7 @@ function groups_add_member($groupid, $userid) {
}
if (!groups_group_exists($groupid)) {
return false;
throw new moodle_exception('cannotaddmembergroupiddoesntexist');
}
if (groups_is_member($groupid, $userid)) {
@ -68,7 +68,7 @@ function groups_remove_member($groupid, $userid) {
}
if (!groups_group_exists($groupid)) {
return false;
throw new moodle_exception('cannotaddmembergroupiddoesntexist');
}
if (!groups_is_member($groupid, $userid)) {

View File

@ -40,7 +40,7 @@ require_once($CFG->dirroot . '/group/external.php');
require_once(dirname(dirname(dirname(__FILE__))) . '/user/lib.php');
class group_external_test extends UnitTestCase {
/*
/*
var $realDB;
var $group;
var $group2;
@ -201,8 +201,8 @@ class group_external_test extends UnitTestCase {
function testTmp_add_group_members2() {
//the group id doesn't exist
$params = array(array("groupid" => 6465465, "userid" => $this->userid3), array("groupid" => $this->group->id, "userid" => $this->userid4));
$this->expectException(new moodle_exception('cannotaddmembergroupiddoesntexist'));
$result = group_external::tmp_add_groupmembers($params);
$this->assertEqual($result, false);
}
function testTmp_delete_group_members() {
@ -215,8 +215,8 @@ class group_external_test extends UnitTestCase {
function testTmp_delete_group_members2() {
//the group id doesn't exist
$params = array(array("groupid" => 6465465, "userid" => $this->userid1), array("groupid" => $this->group->id, "userid" => $this->userid2));
$this->expectException(new moodle_exception('cannotaddmembergroupiddoesntexist'));
$result = group_external::tmp_delete_groupmembers($params);
$this->assertEqual($result, false);
}
function testTmp_delete_group_members3() {