mirror of
https://github.com/moodle/moodle.git
synced 2025-08-02 15:49:43 +02:00
web service MDL-12886 remove tmp prefix
This commit is contained in:
parent
8f732f2ec7
commit
d0977acf53
5 changed files with 65 additions and 67 deletions
|
@ -16,7 +16,6 @@ require_once(dirname(dirname(__FILE__)) . '/lib/grouplib.php');
|
||||||
/**
|
/**
|
||||||
* Group external api class
|
* Group external api class
|
||||||
*
|
*
|
||||||
* WORK IN PROGRESS, DO NOT USE IT
|
|
||||||
*/
|
*/
|
||||||
final class group_external {
|
final class group_external {
|
||||||
|
|
||||||
|
@ -28,7 +27,7 @@ final class group_external {
|
||||||
* @return array $return
|
* @return array $return
|
||||||
* @subparam integer $return:groupid
|
* @subparam integer $return:groupid
|
||||||
*/
|
*/
|
||||||
static function tmp_create_groups($params) {
|
static function create_groups($params) {
|
||||||
global $USER;
|
global $USER;
|
||||||
$groupids = array();
|
$groupids = array();
|
||||||
|
|
||||||
|
@ -58,7 +57,7 @@ final class group_external {
|
||||||
* @subreturn string $return:group->name
|
* @subreturn string $return:group->name
|
||||||
* @subreturn string $return:group->enrolmentkey
|
* @subreturn string $return:group->enrolmentkey
|
||||||
*/
|
*/
|
||||||
static function tmp_get_groups($params){
|
static function get_groups($params){
|
||||||
|
|
||||||
if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_SYSTEM))) {
|
if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_SYSTEM))) {
|
||||||
|
|
||||||
|
@ -87,7 +86,7 @@ final class group_external {
|
||||||
* @subparam integer $params:groupid
|
* @subparam integer $params:groupid
|
||||||
* @return boolean result
|
* @return boolean result
|
||||||
*/
|
*/
|
||||||
static function tmp_delete_groups($params){
|
static function delete_groups($params){
|
||||||
|
|
||||||
if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_SYSTEM))) {
|
if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_SYSTEM))) {
|
||||||
$deletionsuccessfull = true;
|
$deletionsuccessfull = true;
|
||||||
|
@ -110,13 +109,12 @@ final class group_external {
|
||||||
* @return array $return
|
* @return array $return
|
||||||
* $subparam string $return:username
|
* $subparam string $return:username
|
||||||
*/
|
*/
|
||||||
static function tmp_get_groupmembers($params){
|
static function get_groupmembers($params){
|
||||||
if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_SYSTEM))) {
|
if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_SYSTEM))) {
|
||||||
$members = array();
|
$members = array();
|
||||||
foreach ($params as $groupid) {
|
foreach ($params as $groupid) {
|
||||||
|
|
||||||
$groupmembers = groups_get_members($groupid);
|
$groupmembers = groups_get_members(clean_param($groupid, PARAM_INTEGER));
|
||||||
varlog($groupmembers);
|
|
||||||
$custommembers = array();
|
$custommembers = array();
|
||||||
foreach ($groupmembers as $member) {
|
foreach ($groupmembers as $member) {
|
||||||
$custommember = new stdClass();
|
$custommember = new stdClass();
|
||||||
|
@ -138,7 +136,6 @@ final class group_external {
|
||||||
|
|
||||||
$members[] = array("groupid" => $groupid, "members" => $custommembers);
|
$members[] = array("groupid" => $groupid, "members" => $custommembers);
|
||||||
}
|
}
|
||||||
varlog($members);
|
|
||||||
return $members;
|
return $members;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -153,7 +150,7 @@ final class group_external {
|
||||||
* @subparam integer $params:member->userid
|
* @subparam integer $params:member->userid
|
||||||
* @return boolean result
|
* @return boolean result
|
||||||
*/
|
*/
|
||||||
static function tmp_add_groupmembers($params){
|
static function add_groupmembers($params){
|
||||||
|
|
||||||
if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_SYSTEM))) {
|
if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_SYSTEM))) {
|
||||||
$addmembersuccessfull = true;
|
$addmembersuccessfull = true;
|
||||||
|
@ -179,7 +176,7 @@ final class group_external {
|
||||||
* @subparam integer $params:member->userid
|
* @subparam integer $params:member->userid
|
||||||
* @return boolean result
|
* @return boolean result
|
||||||
*/
|
*/
|
||||||
static function tmp_delete_groupmembers($params){
|
static function delete_groupmembers($params){
|
||||||
if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_SYSTEM))) {
|
if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_SYSTEM))) {
|
||||||
$addmembersuccessfull = true;
|
$addmembersuccessfull = true;
|
||||||
foreach($params as $member) {
|
foreach($params as $member) {
|
||||||
|
|
|
@ -82,13 +82,13 @@ class group_external_test extends UnitTestCase {
|
||||||
$user->lastname = 'mockuserfortestingX_lastname';
|
$user->lastname = 'mockuserfortestingX_lastname';
|
||||||
$user->email = 'mockuserfortestingX@moodle.com';
|
$user->email = 'mockuserfortestingX@moodle.com';
|
||||||
$user->password = 'mockuserfortestingX_password';
|
$user->password = 'mockuserfortestingX_password';
|
||||||
$this->userid1 = tmp_create_user($user);
|
$this->userid1 = create_user($user);
|
||||||
$user->username = 'mockuserfortestingXY';
|
$user->username = 'mockuserfortestingXY';
|
||||||
$user->firstname = 'mockuserfortestingY_firstname';
|
$user->firstname = 'mockuserfortestingY_firstname';
|
||||||
$user->lastname = 'mockuserfortestingY_lastname';
|
$user->lastname = 'mockuserfortestingY_lastname';
|
||||||
$user->email = 'mockuserfortestingY@moodle.com';
|
$user->email = 'mockuserfortestingY@moodle.com';
|
||||||
$user->password = 'mockuserfortestingY_password';
|
$user->password = 'mockuserfortestingY_password';
|
||||||
$this->userid2 = tmp_create_user($user);
|
$this->userid2 = create_user($user);
|
||||||
|
|
||||||
//create some more test users (not add yet to any group)
|
//create some more test users (not add yet to any group)
|
||||||
$user = new stdClass();
|
$user = new stdClass();
|
||||||
|
@ -97,14 +97,14 @@ class group_external_test extends UnitTestCase {
|
||||||
$user->lastname = 'mockuserfortestingZ_lastname';
|
$user->lastname = 'mockuserfortestingZ_lastname';
|
||||||
$user->email = 'mockuserfortestingZ@moodle.com';
|
$user->email = 'mockuserfortestingZ@moodle.com';
|
||||||
$user->password = 'mockuserfortestingZ_password';
|
$user->password = 'mockuserfortestingZ_password';
|
||||||
$this->userid3 = tmp_create_user($user);
|
$this->userid3 = create_user($user);
|
||||||
$user = new stdClass();
|
$user = new stdClass();
|
||||||
$user->username = 'mockuserfortestingZ2';
|
$user->username = 'mockuserfortestingZ2';
|
||||||
$user->firstname = 'mockuserfortestingZ2_firstname';
|
$user->firstname = 'mockuserfortestingZ2_firstname';
|
||||||
$user->lastname = 'mockuserfortestingZ2_lastname';
|
$user->lastname = 'mockuserfortestingZ2_lastname';
|
||||||
$user->email = 'mockuserfortestingZ2@moodle.com';
|
$user->email = 'mockuserfortestingZ2@moodle.com';
|
||||||
$user->password = 'mockuserfortestingZ2_password';
|
$user->password = 'mockuserfortestingZ2_password';
|
||||||
$this->userid4 = tmp_create_user($user);
|
$this->userid4 = create_user($user);
|
||||||
|
|
||||||
//create a user, don't add it to a role or group
|
//create a user, don't add it to a role or group
|
||||||
$user = new stdClass();
|
$user = new stdClass();
|
||||||
|
@ -113,7 +113,7 @@ class group_external_test extends UnitTestCase {
|
||||||
$user->lastname = 'mockuserfortestingZ23_lastname';
|
$user->lastname = 'mockuserfortestingZ23_lastname';
|
||||||
$user->email = 'mockuserfortestingZ23@moodle.com';
|
$user->email = 'mockuserfortestingZ23@moodle.com';
|
||||||
$user->password = 'mockuserfortestingZ23_password';
|
$user->password = 'mockuserfortestingZ23_password';
|
||||||
$this->userid5 = tmp_create_user($user);
|
$this->userid5 = create_user($user);
|
||||||
|
|
||||||
//we're creating a new test role with viewcourse capabilyt
|
//we're creating a new test role with viewcourse capabilyt
|
||||||
$this->context = $DB->get_record('context',array('contextlevel' => 50, 'instanceid' => $this->course->id));
|
$this->context = $DB->get_record('context',array('contextlevel' => 50, 'instanceid' => $this->course->id));
|
||||||
|
@ -175,14 +175,14 @@ class group_external_test extends UnitTestCase {
|
||||||
delete_role($this->roleid);
|
delete_role($this->roleid);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testTmp_create_groups() {
|
function test_create_groups() {
|
||||||
/// create two different groups
|
/// create two different groups
|
||||||
$params = array();
|
$params = array();
|
||||||
$group = array('groupname' => 'Create Unit Test Group 1', 'courseid' => $this->course->id);
|
$group = array('groupname' => 'Create Unit Test Group 1', 'courseid' => $this->course->id);
|
||||||
$params[] = $group;
|
$params[] = $group;
|
||||||
$group = array('groupname' => 'Create Unit Test Group 2', 'courseid' => $this->course->id);
|
$group = array('groupname' => 'Create Unit Test Group 2', 'courseid' => $this->course->id);
|
||||||
$params[] = $group;
|
$params[] = $group;
|
||||||
$groupids = group_external::tmp_create_groups($params);
|
$groupids = group_external::create_groups($params);
|
||||||
$this->assertEqual(sizeof($groupids), 2);
|
$this->assertEqual(sizeof($groupids), 2);
|
||||||
$this->assertIsA($groupids[key($groupids)], "integer");
|
$this->assertIsA($groupids[key($groupids)], "integer");
|
||||||
$this->assertNotNull($groupids[key($groupids)]);
|
$this->assertNotNull($groupids[key($groupids)]);
|
||||||
|
@ -192,13 +192,13 @@ class group_external_test extends UnitTestCase {
|
||||||
$group = array('groupname' => 'Create Unit Test Group 3', 'courseid' => 6544656);
|
$group = array('groupname' => 'Create Unit Test Group 3', 'courseid' => 6544656);
|
||||||
$params[] = $group;
|
$params[] = $group;
|
||||||
$this->expectException(new moodle_exception('coursedoesntexistcannotcreategroup'));
|
$this->expectException(new moodle_exception('coursedoesntexistcannotcreategroup'));
|
||||||
$groupids = group_external::tmp_create_groups($params);
|
$groupids = group_external::create_groups($params);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testTmp_get_groups() {
|
function test_get_groups() {
|
||||||
/// retrieve the two groups
|
/// retrieve the two groups
|
||||||
$params = array($this->group->id, $this->group2->id);
|
$params = array($this->group->id, $this->group2->id);
|
||||||
$groups = group_external::tmp_get_groups($params);
|
$groups = group_external::get_groups($params);
|
||||||
$this->assertEqual(sizeof($groups), 2);
|
$this->assertEqual(sizeof($groups), 2);
|
||||||
$group = $groups[key($groups)];
|
$group = $groups[key($groups)];
|
||||||
next($groups);
|
next($groups);
|
||||||
|
@ -211,76 +211,76 @@ class group_external_test extends UnitTestCase {
|
||||||
$this->assertEqual($group2->name, $this->group2->name);
|
$this->assertEqual($group2->name, $this->group2->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testTmp_add_group_members() {
|
function test_add_group_members() {
|
||||||
//add the two members without group
|
//add the two members without group
|
||||||
$params = array(array("groupid" => $this->group->id, "userid" => $this->userid3), array("groupid" => $this->group->id, "userid" => $this->userid4));
|
$params = array(array("groupid" => $this->group->id, "userid" => $this->userid3), array("groupid" => $this->group->id, "userid" => $this->userid4));
|
||||||
$result = group_external::tmp_add_groupmembers($params);
|
$result = group_external::add_groupmembers($params);
|
||||||
$this->assertEqual($result, true);
|
$this->assertEqual($result, true);
|
||||||
|
|
||||||
//add them a new time
|
//add them a new time
|
||||||
$params = array(array("groupid" => $this->group->id, "userid" => $this->userid3), array("groupid" => $this->group->id, "userid" => $this->userid4));
|
$params = array(array("groupid" => $this->group->id, "userid" => $this->userid3), array("groupid" => $this->group->id, "userid" => $this->userid4));
|
||||||
$result = group_external::tmp_add_groupmembers($params);
|
$result = group_external::add_groupmembers($params);
|
||||||
$this->assertEqual($result, true);
|
$this->assertEqual($result, true);
|
||||||
|
|
||||||
//One of the userid doesn't exist
|
//One of the userid doesn't exist
|
||||||
$params = array(array("groupid" => $this->group->id, "userid" => 654685), array("groupid" => $this->group->id, "userid" => $this->userid4));
|
$params = array(array("groupid" => $this->group->id, "userid" => 654685), array("groupid" => $this->group->id, "userid" => $this->userid4));
|
||||||
$this->expectException(new moodle_exception('useriddoesntexist'));
|
$this->expectException(new moodle_exception('useriddoesntexist'));
|
||||||
$result = group_external::tmp_add_groupmembers($params);
|
$result = group_external::add_groupmembers($params);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testTmp_add_group_members2() {
|
function test_add_group_members2() {
|
||||||
//the group id doesn't exist
|
//the group id doesn't exist
|
||||||
$params = array(array("groupid" => 6465465, "userid" => $this->userid3), array("groupid" => $this->group->id, "userid" => $this->userid4));
|
$params = array(array("groupid" => 6465465, "userid" => $this->userid3), array("groupid" => $this->group->id, "userid" => $this->userid4));
|
||||||
$this->expectException(new moodle_exception('cannotaddmembergroupiddoesntexist'));
|
$this->expectException(new moodle_exception('cannotaddmembergroupiddoesntexist'));
|
||||||
$result = group_external::tmp_add_groupmembers($params);
|
$result = group_external::add_groupmembers($params);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testTmp_add_group_members3() {
|
function test_add_group_members3() {
|
||||||
//the user is not a participant
|
//the user is not a participant
|
||||||
$params = array(array("groupid" => $this->group->id, "userid" => $this->userid5));
|
$params = array(array("groupid" => $this->group->id, "userid" => $this->userid5));
|
||||||
$this->expectException(new moodle_exception('userisnotaparticipant'));
|
$this->expectException(new moodle_exception('userisnotaparticipant'));
|
||||||
$result = group_external::tmp_add_groupmembers($params);
|
$result = group_external::add_groupmembers($params);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testTmp_get_groupmembers() {
|
function test_get_groupmembers() {
|
||||||
$params = array($this->group->id, $this->group2->id);
|
$params = array($this->group->id, $this->group2->id);
|
||||||
$groups = group_external::tmp_get_groupmembers($params);
|
$groups = group_external::get_groupmembers($params);
|
||||||
$this->assertEqual(sizeof($groups), 2);
|
$this->assertEqual(sizeof($groups), 2);
|
||||||
$this->assertEqual(sizeof($groups[0]['members']), 2);
|
$this->assertEqual(sizeof($groups[0]['members']), 2);
|
||||||
$this->assertEqual(sizeof($groups[1]['members']), 1);
|
$this->assertEqual(sizeof($groups[1]['members']), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testTmp_delete_group_members() {
|
function test_delete_group_members() {
|
||||||
//One of the userid doesn't exist
|
//One of the userid doesn't exist
|
||||||
$params = array(array("groupid" => $this->group->id, "userid" => 654685), array("groupid" => $this->group->id, "userid" => $this->userid2));
|
$params = array(array("groupid" => $this->group->id, "userid" => 654685), array("groupid" => $this->group->id, "userid" => $this->userid2));
|
||||||
$this->expectException(new moodle_exception('useriddoesntexist'));
|
$this->expectException(new moodle_exception('useriddoesntexist'));
|
||||||
$result = group_external::tmp_delete_groupmembers($params);
|
$result = group_external::delete_groupmembers($params);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testTmp_delete_group_members2() {
|
function test_delete_group_members2() {
|
||||||
//the group id doesn't exist
|
//the group id doesn't exist
|
||||||
$params = array(array("groupid" => 6465465, "userid" => $this->userid1), array("groupid" => $this->group->id, "userid" => $this->userid2));
|
$params = array(array("groupid" => 6465465, "userid" => $this->userid1), array("groupid" => $this->group->id, "userid" => $this->userid2));
|
||||||
$this->expectException(new moodle_exception('cannotaddmembergroupiddoesntexist'));
|
$this->expectException(new moodle_exception('cannotaddmembergroupiddoesntexist'));
|
||||||
$result = group_external::tmp_delete_groupmembers($params);
|
$result = group_external::delete_groupmembers($params);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testTmp_delete_group_members3() {
|
function test_delete_group_members3() {
|
||||||
//delete members from group
|
//delete members from group
|
||||||
$params = array(array("groupid" => $this->group->id, "userid" => $this->userid1), array("groupid" => $this->group->id, "userid" => $this->userid2));
|
$params = array(array("groupid" => $this->group->id, "userid" => $this->userid1), array("groupid" => $this->group->id, "userid" => $this->userid2));
|
||||||
$result = group_external::tmp_delete_groupmembers($params);
|
$result = group_external::delete_groupmembers($params);
|
||||||
$this->assertEqual($result, true);
|
$this->assertEqual($result, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testTmp_delete_groups() {
|
function test_delete_groups() {
|
||||||
$params = array($this->group->id, $this->group2->id);
|
$params = array($this->group->id, $this->group2->id);
|
||||||
$result = group_external::tmp_delete_groups($params);
|
$result = group_external::delete_groups($params);
|
||||||
$this->assertEqual($result, true);
|
$this->assertEqual($result, true);
|
||||||
|
|
||||||
//Exception: delete same groups
|
//Exception: delete same groups
|
||||||
$params = array($this->group->id, $this->group2->id);
|
$params = array($this->group->id, $this->group2->id);
|
||||||
$this->expectException(new moodle_exception('groupiddoesntexistcannotdelete'));
|
$this->expectException(new moodle_exception('groupiddoesntexistcannotdelete'));
|
||||||
$result = group_external::tmp_delete_groups($params);
|
$result = group_external::delete_groups($params);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
require_once(dirname(dirname(__FILE__)) . '/user/lib.php');
|
require_once(dirname(dirname(__FILE__)) . '/user/lib.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WORK IN PROGRESS, DO NOT USE IT
|
|
||||||
* users webservice api
|
* users webservice api
|
||||||
*
|
*
|
||||||
* @author Jerome Mouneyrac
|
* @author Jerome Mouneyrac
|
||||||
|
@ -51,7 +50,7 @@ final class user_external {
|
||||||
* @subreturn string $return:user->timezone
|
* @subreturn string $return:user->timezone
|
||||||
* @subreturn string $return:user->mailformat
|
* @subreturn string $return:user->mailformat
|
||||||
*/
|
*/
|
||||||
static function tmp_get_users($params) {
|
static function get_users($params) {
|
||||||
global $USER;
|
global $USER;
|
||||||
|
|
||||||
$params['search'] = clean_param($params['search'], PARAM_ALPHANUM);
|
$params['search'] = clean_param($params['search'], PARAM_ALPHANUM);
|
||||||
|
@ -75,7 +74,7 @@ final class user_external {
|
||||||
* @return array $return ids of new user
|
* @return array $return ids of new user
|
||||||
* @subreturn integer $return:id user id
|
* @subreturn integer $return:id user id
|
||||||
*/
|
*/
|
||||||
static function tmp_create_users($params) {
|
static function create_users($params) {
|
||||||
global $USER;
|
global $USER;
|
||||||
if (has_capability('moodle/user:create', get_context_instance(CONTEXT_SYSTEM))) {
|
if (has_capability('moodle/user:create', get_context_instance(CONTEXT_SYSTEM))) {
|
||||||
$userids = array();
|
$userids = array();
|
||||||
|
@ -147,7 +146,7 @@ final class user_external {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$userids[$userparams['username']] = tmp_create_user($user);
|
$userids[$userparams['username']] = create_user($user);
|
||||||
}
|
}
|
||||||
catch (dml_write_exception $e) {
|
catch (dml_write_exception $e) {
|
||||||
throw new moodle_exception('wscouldnotcreateeuserindb');
|
throw new moodle_exception('wscouldnotcreateeuserindb');
|
||||||
|
@ -167,7 +166,7 @@ final class user_external {
|
||||||
* @subparam string $params:user->username
|
* @subparam string $params:user->username
|
||||||
* @return boolean result true if success
|
* @return boolean result true if success
|
||||||
*/
|
*/
|
||||||
static function tmp_delete_users($params) {
|
static function delete_users($params) {
|
||||||
global $DB,$USER;
|
global $DB,$USER;
|
||||||
$deletionsuccessfull = true;
|
$deletionsuccessfull = true;
|
||||||
if (has_capability('moodle/user:delete', get_context_instance(CONTEXT_SYSTEM))) {
|
if (has_capability('moodle/user:delete', get_context_instance(CONTEXT_SYSTEM))) {
|
||||||
|
@ -201,7 +200,7 @@ final class user_external {
|
||||||
* @subparam string $params:user->firstname
|
* @subparam string $params:user->firstname
|
||||||
* @return boolean result true if success
|
* @return boolean result true if success
|
||||||
*/
|
*/
|
||||||
static function tmp_update_users($params) {
|
static function update_users($params) {
|
||||||
global $DB,$USER;
|
global $DB,$USER;
|
||||||
if (has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
|
if (has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
|
||||||
$updatesuccessfull = true;
|
$updatesuccessfull = true;
|
||||||
|
@ -274,7 +273,7 @@ final class user_external {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if( !tmp_update_user($user)) {
|
if( !update_user($user)) {
|
||||||
$updatesuccessfull = false;
|
$updatesuccessfull = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DO NOT USE ANYTHING FROM THIS FILE - WORK IN PROGRESS
|
* User library
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
* ->lastinitial string ?
|
* ->lastinitial string ?
|
||||||
* @return array|false Array of {@link $USER} objects. False is returned if an error is encountered.
|
* @return array|false Array of {@link $USER} objects. False is returned if an error is encountered.
|
||||||
*/
|
*/
|
||||||
function tmp_get_users($sort='firstname ASC', $recordsperpage=999999, $page=0, $fields='*', $selectioncriteria=NULL) {
|
function get_users_2($sort='firstname ASC', $recordsperpage=999999, $page=0, $fields='*', $selectioncriteria=NULL) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
///WS: convert array into an object
|
///WS: convert array into an object
|
||||||
|
@ -101,7 +101,7 @@ function tmp_get_users($sort='firstname ASC', $recordsperpage=999999, $page=0, $
|
||||||
*
|
*
|
||||||
* @return string or thrown exceptions
|
* @return string or thrown exceptions
|
||||||
*/
|
*/
|
||||||
function tmp_create_user($user) {
|
function create_user($user) {
|
||||||
global $CFG, $DB;
|
global $CFG, $DB;
|
||||||
/// WS: convert user array into an user object
|
/// WS: convert user array into an user object
|
||||||
if (is_array($user)) {
|
if (is_array($user)) {
|
||||||
|
@ -148,7 +148,7 @@ function tmp_create_user($user) {
|
||||||
* @param object $user
|
* @param object $user
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function tmp_update_user($user) {
|
function update_user($user) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
//check that the user exist
|
//check that the user exist
|
||||||
|
|
|
@ -49,7 +49,7 @@ class user_external_test extends UnitTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
function testTmp_create_users() {
|
function test_create_users() {
|
||||||
/// test that we create multiple users
|
/// test that we create multiple users
|
||||||
$params = array();
|
$params = array();
|
||||||
for ($i=0;$i<2;$i=$i+1) {
|
for ($i=0;$i<2;$i=$i+1) {
|
||||||
|
@ -61,7 +61,7 @@ class user_external_test extends UnitTestCase {
|
||||||
$user['password'] = 'mockuserfortesting'.$i.'_password';
|
$user['password'] = 'mockuserfortesting'.$i.'_password';
|
||||||
$params[] = $user;
|
$params[] = $user;
|
||||||
}
|
}
|
||||||
$result = user_external::tmp_create_users($params);
|
$result = user_external::create_users($params);
|
||||||
$this->assertEqual(sizeof($result), 2);
|
$this->assertEqual(sizeof($result), 2);
|
||||||
//just test that value are integer and not null
|
//just test that value are integer and not null
|
||||||
$this->assertIsA($result[key($result)], "integer");
|
$this->assertIsA($result[key($result)], "integer");
|
||||||
|
@ -81,7 +81,7 @@ class user_external_test extends UnitTestCase {
|
||||||
$user['lang']='en_utf8';
|
$user['lang']='en_utf8';
|
||||||
$user['auth']='manual';
|
$user['auth']='manual';
|
||||||
$params[] = $user;
|
$params[] = $user;
|
||||||
$result = user_external::tmp_create_users($params);
|
$result = user_external::create_users($params);
|
||||||
$this->assertEqual($result, true);
|
$this->assertEqual($result, true);
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,11 +91,11 @@ class user_external_test extends UnitTestCase {
|
||||||
$user['username'] = 'mockuserfortestingY';
|
$user['username'] = 'mockuserfortestingY';
|
||||||
$params[] = $user;
|
$params[] = $user;
|
||||||
$this->expectException(new moodle_exception('missingrequiredfield'));
|
$this->expectException(new moodle_exception('missingrequiredfield'));
|
||||||
$result = user_external::tmp_create_users($params);
|
$result = user_external::create_users($params);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testTmp_create_users_2() {
|
function test_create_users_2() {
|
||||||
/// test we cannot create a user because the username already exist
|
/// test we cannot create a user because the username already exist
|
||||||
$params = array();
|
$params = array();
|
||||||
$user = array();
|
$user = array();
|
||||||
|
@ -107,12 +107,14 @@ class user_external_test extends UnitTestCase {
|
||||||
$params[] = $user;
|
$params[] = $user;
|
||||||
|
|
||||||
$this->expectException(new moodle_exception('wscouldnotcreateeuserindb'));
|
$this->expectException(new moodle_exception('wscouldnotcreateeuserindb'));
|
||||||
$result = user_external::tmp_create_users($params);
|
$result = user_external::create_users($params);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testTmp_get_users() {
|
function test_get_users() {
|
||||||
$params = array('search' => 'mockuserfortestingXX');
|
$params = array('search' => 'mockuserfortestingXX');
|
||||||
$users = user_external::tmp_get_users($params);
|
|
||||||
|
$users = user_external::get_users($params);
|
||||||
|
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
$this->assertEqual($user->username, 'mockuserfortestingXX');
|
$this->assertEqual($user->username, 'mockuserfortestingXX');
|
||||||
$this->assertEqual($user->firstname, 'mockuserfortesting_firstname');
|
$this->assertEqual($user->firstname, 'mockuserfortesting_firstname');
|
||||||
|
@ -127,7 +129,7 @@ class user_external_test extends UnitTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testTmp_update_users() {
|
function test_update_users() {
|
||||||
/// update several users with full information
|
/// update several users with full information
|
||||||
$params = array();
|
$params = array();
|
||||||
$user = array();
|
$user = array();
|
||||||
|
@ -156,7 +158,7 @@ class user_external_test extends UnitTestCase {
|
||||||
$user['lang']='en_utf8';
|
$user['lang']='en_utf8';
|
||||||
$user['auth']='manual';
|
$user['auth']='manual';
|
||||||
$params[] = $user;
|
$params[] = $user;
|
||||||
$result = user_external::tmp_update_users($params);
|
$result = user_external::update_users($params);
|
||||||
$this->assertEqual($result, true);
|
$this->assertEqual($result, true);
|
||||||
|
|
||||||
/// Exception: update non existing user
|
/// Exception: update non existing user
|
||||||
|
@ -166,22 +168,22 @@ class user_external_test extends UnitTestCase {
|
||||||
$user['newusername'] = 'mockuserfortesting0Y';
|
$user['newusername'] = 'mockuserfortesting0Y';
|
||||||
$params[] = $user;
|
$params[] = $user;
|
||||||
$this->expectException(new moodle_exception('wscouldnotupdatenoexistinguser')); //TODO catch the write exception
|
$this->expectException(new moodle_exception('wscouldnotupdatenoexistinguser')); //TODO catch the write exception
|
||||||
$result = user_external::tmp_update_users($params);
|
$result = user_external::update_users($params);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testTmp_update_users_2() {
|
function test_update_users_2() {
|
||||||
/// update an existing user with an already existing username
|
/// update an existing user with an already existing username
|
||||||
$params = array();
|
$params = array();
|
||||||
$user = array();
|
$user = array();
|
||||||
$user['username'] = 'mockuserfortesting0Y';
|
$user['username'] = 'mockuserfortesting0Y';
|
||||||
$user['newusername'] = 'mockuserfortestingXY';
|
$user['newusername'] = 'mockuserfortestingXY';
|
||||||
$params[] = $user;
|
$params[] = $user;
|
||||||
|
|
||||||
$this->expectException(new moodle_exception('wscouldnotupdateuserindb'));
|
$this->expectException(new moodle_exception('wscouldnotupdateuserindb'));
|
||||||
$result = user_external::tmp_update_users($params);
|
$result = user_external::update_users($params);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testTmp_delete_users() {
|
function test_delete_users() {
|
||||||
/// we delete all previously created users
|
/// we delete all previously created users
|
||||||
$params = array();
|
$params = array();
|
||||||
$user = array();
|
$user = array();
|
||||||
|
@ -193,12 +195,12 @@ class user_external_test extends UnitTestCase {
|
||||||
$user = array();
|
$user = array();
|
||||||
$user['username'] = 'mockuserfortesting1';
|
$user['username'] = 'mockuserfortesting1';
|
||||||
$params[] = $user;
|
$params[] = $user;
|
||||||
$result = user_external::tmp_delete_users($params);
|
$result = user_external::delete_users($params);
|
||||||
$this->assertEqual($result, true);
|
$this->assertEqual($result, true);
|
||||||
|
|
||||||
/// try to delete them a new time, should return exception
|
/// try to delete them a new time, should return exception
|
||||||
$this->expectException(new moodle_exception('wscouldnotdeletenoexistinguser'));
|
$this->expectException(new moodle_exception('wscouldnotdeletenoexistinguser'));
|
||||||
$result = user_external::tmp_delete_users($params);
|
$result = user_external::delete_users($params);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue