PageRenderTime 88ms CodeModel.GetById 35ms app.highlight 42ms RepoModel.GetById 1ms app.codeStats 0ms

/webservice/simpletest/testwebservice.php

https://github.com/blackboard-open-source/moodle
PHP | 1573 lines | 1104 code | 242 blank | 227 comment | 44 complexity | cfa6f75c666ba74fdd3e6f5146da63dc MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2
   3// This file is part of Moodle - http://moodle.org/
   4//
   5// Moodle is free software: you can redistribute it and/or modify
   6// it under the terms of the GNU General Public License as published by
   7// the Free Software Foundation, either version 3 of the License, or
   8// (at your option) any later version.
   9//
  10// Moodle is distributed in the hope that it will be useful,
  11// but WITHOUT ANY WARRANTY; without even the implied warranty of
  12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13// GNU General Public License for more details.
  14//
  15// You should have received a copy of the GNU General Public License
  16// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17
  18/**
  19 * Test the different web service protocols.
  20 *
  21 * @author jerome@moodle.com
  22 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  23 * @package web service
  24 */
  25if (!defined('MOODLE_INTERNAL')) {
  26    ///  It must be included from a Moodle page
  27    die('Direct access to this script is forbidden.');
  28}
  29
  30/**
  31 * How to configure this unit tests:
  32 * 0- Enable the web service you wish to test in the Moodle administration
  33 * 1- Create a service with all functions in the Moodle administration
  34 * 2- Create a token associate this service and to an admin (or a user with all required capabilities)
  35 * 3- Configure setUp() function:
  36 *      a- write the token
  37 *      b- activate the protocols you wish to test
  38 *      c- activate the functions you wish to test (readonlytests and writetests arrays)
  39 *      d- set the number of time the web services are run
  40 * Do not run WRITE test function on a production site as they impact the DB (even though every
  41 * test should clean the modified data)
  42 *
  43 * How to write a new function:
  44 * 1- Add the function name to the array readonlytests/writetests
  45 * 2- Set it as false when you commit!
  46 * 3- write the function  - Do not prefix the function name by 'test'
  47 */
  48class webservice_test extends UnitTestCase {
  49
  50    public $testtoken;
  51    public $testrest;
  52    public $testxmlrpc;
  53    public $testsoap;
  54    public $timerrest;
  55    public $timerxmlrpc;
  56    public $timersoap;
  57    public $readonlytests;
  58    public $writetests;
  59
  60    function setUp() {
  61        //token to test
  62        $this->testtoken = 'acabec9d20933913f14309785324f579';
  63
  64        //protocols to test
  65        $this->testrest = false; //Does not work till XML => PHP is implemented (MDL-22965)
  66        $this->testxmlrpc = false;
  67        $this->testsoap = false;
  68
  69        ////// READ-ONLY DB tests ////
  70        $this->readonlytests = array(
  71            'moodle_group_get_groups' => false,
  72            'moodle_course_get_courses' => false,
  73            'moodle_user_get_users_by_id' => false,
  74            'moodle_enrol_get_enrolled_users' => false,
  75            'moodle_group_get_course_groups' => false,
  76            'moodle_group_get_groupmembers' => false,
  77            'moodle_webservice_get_siteinfo' => false,
  78            'core_course_get_contents' => false
  79        );
  80
  81        ////// WRITE DB tests ////
  82        $this->writetests = array(
  83            'moodle_user_create_users' => false,
  84            'moodle_course_create_courses' => false,
  85            'moodle_user_delete_users' => false,
  86            'moodle_user_update_users' => false,
  87            'moodle_role_assign' => false,
  88            'moodle_role_unassign' => false,
  89            'moodle_group_add_groupmembers' => false,
  90            'moodle_group_delete_groupmembers' => false,
  91            'moodle_group_create_groups' => false,
  92            'moodle_group_delete_groups' => false,
  93            'moodle_enrol_manual_enrol_users' => false,
  94            'moodle_message_send_messages' => false,
  95            'moodle_notes_create_notes' => false
  96        );
  97
  98        //performance testing: number of time the web service are run
  99        $this->iteration = 1;
 100
 101        //DO NOT CHANGE
 102        //reset the timers
 103        $this->timerrest = 0;
 104        $this->timerxmlrpc = 0;
 105        $this->timersoap = 0;
 106    }
 107
 108    function testRun() {
 109        global $CFG;
 110
 111        if (!$this->testrest and !$this->testxmlrpc and !$this->testsoap) {
 112            print_r("Web service unit tests are not run as not setup.
 113                (see /webservice/simpletest/testwebservice.php)");
 114        }
 115
 116        if (!empty($this->testtoken)) {
 117
 118            //Does not work till XML => PHP is implemented (MDL-22965)
 119            if ($this->testrest) {
 120
 121                $this->timerrest = time();
 122
 123                require_once($CFG->dirroot . "/webservice/rest/lib.php");
 124                $restclient = new webservice_rest_client($CFG->wwwroot
 125                                . '/webservice/rest/server.php', $this->testtoken);
 126
 127                for ($i = 1; $i <= $this->iteration; $i = $i + 1) {
 128                    foreach ($this->readonlytests as $functioname => $run) {
 129                        if ($run) {
 130                            //$this->{$functioname}($restclient);
 131                        }
 132                    }
 133                    foreach ($this->writetests as $functioname => $run) {
 134                        if ($run) {
 135                            //$this->{$functioname}($restclient);
 136                        }
 137                    }
 138                }
 139
 140                $this->timerrest = time() - $this->timerrest;
 141                //here you could call a log function to display the timer
 142                //example:
 143                //error_log('REST time: ');
 144                //error_log(print_r($this->timerrest));
 145            }
 146
 147            if ($this->testxmlrpc) {
 148
 149                $this->timerxmlrpc = time();
 150
 151                require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
 152                $xmlrpcclient = new webservice_xmlrpc_client($CFG->wwwroot
 153                                . '/webservice/xmlrpc/server.php', $this->testtoken);
 154
 155                for ($i = 1; $i <= $this->iteration; $i = $i + 1) {
 156                    foreach ($this->readonlytests as $functioname => $run) {
 157                        if ($run) {
 158                            $this->{$functioname}($xmlrpcclient);
 159                        }
 160                    }
 161                    foreach ($this->writetests as $functioname => $run) {
 162                        if ($run) {
 163                            $this->{$functioname}($xmlrpcclient);
 164                        }
 165                    }
 166                }
 167
 168                $this->timerxmlrpc = time() - $this->timerxmlrpc;
 169                //here you could call a log function to display the timer
 170                //example:
 171                //error_log('XML-RPC time: ');
 172                //error_log(print_r($this->timerxmlrpc));
 173            }
 174
 175            if ($this->testsoap) {
 176
 177                $this->timersoap = time();
 178
 179                require_once($CFG->dirroot . "/webservice/soap/lib.php");
 180                $soapclient = new webservice_soap_client($CFG->wwwroot
 181                                . '/webservice/soap/server.php', $this->testtoken,
 182                        array("features" => SOAP_WAIT_ONE_WAY_CALLS)); //force SOAP synchronous mode
 183                                                                     //when function return null
 184                $soapclient->setWsdlCache(false);
 185
 186                for ($i = 1; $i <= $this->iteration; $i = $i + 1) {
 187                    foreach ($this->readonlytests as $functioname => $run) {
 188                        if ($run) {
 189                            $this->{$functioname}($soapclient);
 190                        }
 191                    }
 192                    foreach ($this->writetests as $functioname => $run) {
 193                        if ($run) {
 194                            $this->{$functioname}($soapclient);
 195                        }
 196                    }
 197                }
 198
 199                $this->timersoap = time() - $this->timersoap;
 200                //here you could call a log function to display the timer
 201                //example:
 202                //error_log('SOAP time: ');
 203                //error_log(print_r($this->timersoap));
 204            }
 205        }
 206    }
 207
 208    ///// WEB SERVICE TEST FUNCTIONS
 209
 210    function moodle_group_get_groups($client) {
 211        global $DB;
 212        $dbgroups = $DB->get_records('groups');
 213        $groupids = array();
 214        foreach ($dbgroups as $dbgroup) {
 215            $groupids[] = $dbgroup->id;
 216        }
 217        $function = 'moodle_group_get_groups';
 218
 219        $params = array('groupids' => $groupids);
 220        $groups = $client->call($function, $params);
 221        $this->assertEqual(count($groups), count($groupids));
 222    }
 223
 224    function moodle_webservice_get_siteinfo($client) {
 225        global $SITE, $CFG;
 226
 227        $function = 'moodle_webservice_get_siteinfo';
 228
 229        $params = array();
 230        $info = $client->call($function, $params);
 231
 232        $this->assertEqual($info['sitename'], $SITE->fullname);
 233        $this->assertEqual($info['siteurl'],  $CFG->wwwroot);
 234    }
 235
 236    function moodle_user_get_users_by_id($client) {
 237        global $DB;
 238        $dbusers = $DB->get_records('user', array('deleted' => 0));
 239        $userids = array();
 240        foreach ($dbusers as $dbuser) {
 241            $userids[] = $dbuser->id;
 242        }
 243        $function = 'moodle_user_get_users_by_id';
 244
 245        $params = array('userids' => $userids);
 246        $users = $client->call($function, $params);
 247
 248        $this->assertEqual(count($users), count($userids));
 249    }
 250
 251    function core_course_get_contents($client) {
 252        global $DB, $CFG;
 253        $dbcourses = $DB->get_records('course');
 254        $function = 'core_course_get_contents';
 255
 256        $coursecontents = array();
 257
 258        foreach ($dbcourses as $dbcourse) {
 259            $params = array('courseid' => $dbcourse->id);
 260
 261            if (file_exists($CFG->dirroot . '/' . '/course/format/' . $dbcourse->format . '/lib.php')) {
 262                $coursecontents = $client->call($function, $params);
 263            }
 264
 265            //Display the content of $coursecontents in your php log and check if you obtain
 266            //what you are expecting
 267            //error_log(print_r($coursecontents, true));
 268        }
 269    }
 270
 271    /**
 272     * This test will:
 273     * 1- create a user (core call)
 274     * 2- enrol this user in the courses supporting enrolment
 275     * 3- unenrol this user (core call)
 276     */
 277    function moodle_enrol_manual_enrol_users($client) {
 278        global $DB, $CFG;
 279
 280        require_once($CFG->dirroot . "/user/lib.php");
 281        require_once($CFG->dirroot . "/user/profile/lib.php");
 282        require_once($CFG->dirroot . "/lib/enrollib.php");
 283
 284        //Delete some previous test data
 285        if ($user = $DB->get_record('user', array('username' => 'veryimprobabletestusername2'))) {
 286            $DB->delete_records('user', array('id' => $user->id));
 287        }
 288        if ($role = $DB->get_record('role', array('shortname' => 'role1thatshouldnotexist'))) {
 289            set_role_contextlevels($role->id, array(CONTEXT_COURSE));
 290            delete_role($role->id);
 291        }
 292
 293        //create a user
 294        $user = new stdClass();
 295        $user->username = 'veryimprobabletestusername2';
 296        $user->password = 'testpassword2';
 297        $user->firstname = 'testfirstname2';
 298        $user->lastname = 'testlastname2';
 299        $user->email = 'testemail1@moodle.com';
 300        $user->id = user_create_user($user);
 301
 302        $roleid = create_role('role1thatshouldnotexist', 'role1thatshouldnotexist', '');
 303        set_role_contextlevels($roleid, array(CONTEXT_COURSE));
 304
 305        $enrolments = array();
 306        $courses = $DB->get_records('course');
 307
 308        foreach ($courses as $course) {
 309            if ($course->id > 1) {
 310                $enrolments[] = array('roleid' => $roleid,
 311                    'userid' => $user->id, 'courseid' => $course->id);
 312                $enrolledcourses[] = $course;
 313            }
 314        }
 315
 316        //web service call
 317        $function = 'moodle_enrol_manual_enrol_users';
 318        $wsparams = array('enrolments' => $enrolments);
 319        $enrolmentsresult = $client->call($function, $wsparams);
 320
 321        //get instance that can unenrol
 322        $enrols = enrol_get_plugins(true);
 323        $enrolinstances = enrol_get_instances($course->id, true);
 324        $unenrolled = false;
 325        foreach ($enrolinstances as $instance) {
 326            if (!$unenrolled and $enrols[$instance->enrol]->allow_unenrol($instance)) {
 327                $unenrolinstance = $instance;
 328                $unenrolled = true;
 329            }
 330        }
 331
 332        //test and unenrol the user
 333        $enrolledusercourses = enrol_get_users_courses($user->id);
 334        foreach ($enrolledcourses as $course) {
 335            //test
 336            $this->assertEqual(true, isset($enrolledusercourses[$course->id]));
 337
 338            //unenrol the user
 339            $enrols[$unenrolinstance->enrol]->unenrol_user($unenrolinstance, $user->id, $roleid);
 340        }
 341
 342        //delete user
 343        $DB->delete_records('user', array('id' => $user->id));
 344
 345        //delete the context level
 346        set_role_contextlevels($roleid, array(CONTEXT_COURSE));
 347
 348        //delete role
 349        delete_role($roleid);
 350    }
 351
 352
 353    function moodle_enrol_get_enrolled_users($client) {
 354        global $DB;
 355
 356        //function settings
 357        $withcapability = '';
 358        $groupid = null;
 359        $onlyactive = false;
 360
 361        $dbcourses = $DB->get_records('course');
 362        $function = 'moodle_enrol_get_enrolled_users';
 363
 364        foreach ($dbcourses as $dbcourse) {
 365
 366            $params = array();
 367
 368            $coursecontext = get_context_instance(CONTEXT_COURSE, $dbcourse->id);
 369
 370            list($sql, $params) = get_enrolled_sql($coursecontext, $withcapability, $groupid, $onlyactive);
 371            $sql = "SELECT DISTINCT ue.userid, e.courseid
 372                      FROM {user_enrolments} ue
 373                      JOIN {enrol} e ON (e.id = ue.enrolid)
 374                     WHERE e.courseid = :courseid AND ue.userid IN ($sql)";
 375
 376            $params['courseid'] = $dbcourse->id;
 377
 378            $enrolledusers = $DB->get_records_sql($sql, $params);
 379
 380            $wsparams = array('courseid' => $dbcourse->id, 'withcapability' => $withcapability,
 381                'groupid' => $groupid, 'onlyactive' => $onlyactive);
 382            $resultusers = $client->call($function, $wsparams);
 383
 384            $this->assertEqual(count($resultusers), count($enrolledusers));
 385        }
 386    }
 387
 388    function moodle_course_get_courses($client) {
 389        global $DB;
 390
 391        $function = 'moodle_course_get_courses';
 392
 393        //retrieve all courses from db
 394        $dbcourses = $DB->get_records('course');
 395        $courseids = array();
 396        foreach ($dbcourses as $dbcourse) {
 397            $courseids[] = $dbcourse->id;
 398        }
 399
 400        //retrieve all courses by id
 401        $params = array('options' => array('ids' => $courseids));
 402        $courses = $client->call($function, $params);
 403
 404        //check it is the same course count
 405        $this->assertEqual(count($courses), count($courseids));
 406
 407        //check all course values are identic
 408        foreach ($courses as $course) {
 409            $this->assertEqual($course['fullname'],
 410                    $dbcourses[$course['id']]->fullname);
 411            $this->assertEqual($course['shortname'],
 412                    $dbcourses[$course['id']]->shortname);
 413            $this->assertEqual($course['categoryid'],
 414                    $dbcourses[$course['id']]->category);
 415            $this->assertEqual($course['categorysortorder'],
 416                    $dbcourses[$course['id']]->sortorder);
 417            $this->assertEqual($course['idnumber'],
 418                    $dbcourses[$course['id']]->idnumber);
 419            $this->assertEqual($course['summary'],
 420                    $dbcourses[$course['id']]->summary);
 421            $this->assertEqual($course['summaryformat'],
 422                    $dbcourses[$course['id']]->summaryformat);
 423            $this->assertEqual($course['format'],
 424                    $dbcourses[$course['id']]->format);
 425            $this->assertEqual($course['showgrades'],
 426                    $dbcourses[$course['id']]->showgrades);
 427            $this->assertEqual($course['newsitems'],
 428                    $dbcourses[$course['id']]->newsitems);
 429            $this->assertEqual($course['startdate'],
 430                    $dbcourses[$course['id']]->startdate);
 431            $this->assertEqual($course['numsections'],
 432                    $dbcourses[$course['id']]->numsections);
 433            $this->assertEqual($course['maxbytes'],
 434                    $dbcourses[$course['id']]->maxbytes);
 435            $this->assertEqual($course['visible'],
 436                    $dbcourses[$course['id']]->visible);
 437            $this->assertEqual($course['hiddensections'],
 438                    $dbcourses[$course['id']]->hiddensections);
 439            $this->assertEqual($course['groupmode'],
 440                    $dbcourses[$course['id']]->groupmode);
 441            $this->assertEqual($course['groupmodeforce'],
 442                    $dbcourses[$course['id']]->groupmodeforce);
 443            $this->assertEqual($course['defaultgroupingid'],
 444                    $dbcourses[$course['id']]->defaultgroupingid);
 445            $this->assertEqual($course['lang'],
 446                    $dbcourses[$course['id']]->lang);
 447            $this->assertEqual($course['timecreated'],
 448                    $dbcourses[$course['id']]->timecreated);
 449            $this->assertEqual($course['timemodified'],
 450                    $dbcourses[$course['id']]->timemodified);
 451            if (key_exists('enablecompletion', $course)) {
 452                $this->assertEqual($course['enablecompletion'],
 453                        $dbcourses[$course['id']]->enablecompletion);
 454            }
 455            if (key_exists('completionstartonenrol', $course)) {
 456                $this->assertEqual($course['completionstartonenrol'],
 457                        $dbcourses[$course['id']]->completionstartonenrol);
 458            }
 459            if (key_exists('completionnotify', $course)) {
 460                $this->assertEqual($course['completionnotify'],
 461                        $dbcourses[$course['id']]->completionnotify);
 462            }
 463            $this->assertEqual($course['forcetheme'],
 464                    $dbcourses[$course['id']]->theme);
 465        }
 466    }
 467
 468    function moodle_course_create_courses($client) {
 469        global $DB, $CFG;
 470
 471        ///Test data
 472        $courseconfig = get_config('moodlecourse');
 473
 474        $themeobjects = get_list_of_themes();
 475        $theme = key($themeobjects);
 476        $categoryid = $DB->get_record('course_categories', array(), '*', IGNORE_MULTIPLE)->id;
 477        $categoryid = empty($categoryid) ? 0 : $categoryid;
 478
 479        $course1 = new stdClass();
 480        $course1->fullname = 'Test Data create course 1';
 481        $course1->shortname = 'testdatacourse1';
 482        $course1->categoryid = $categoryid;
 483        $course1->idnumber = '328327982372342343234';
 484        $course1->summary = 'This is a summary';
 485        $course1->summaryformat = FORMAT_HTML;
 486        $course1->format = $courseconfig->format;
 487        $course1->showgrades = $courseconfig->showgrades;
 488        $course1->showreports = $courseconfig->showreports;
 489        $course1->newsitems = $courseconfig->newsitems;
 490        $course1->startdate = time();
 491        $course1->numsections = $courseconfig->numsections;
 492        $course1->maxbytes = $courseconfig->maxbytes;
 493        $course1->visible = $courseconfig->visible;
 494        $course1->hiddensections = $courseconfig->hiddensections;
 495        $course1->groupmode = $courseconfig->groupmode;
 496        $course1->groupmodeforce = $courseconfig->groupmodeforce;
 497        $course1->defaultgroupingid = 0;
 498        if (!empty($courseconfig->lang)) {
 499            $course1->lang = $courseconfig->lang;
 500        }
 501        $course1->enablecompletion = $courseconfig->enablecompletion;
 502        $course1->completionstartonenrol = $courseconfig->completionstartonenrol;
 503        $course1->completionnotify = 0;
 504        $course1->forcetheme = $theme;
 505
 506        $course2 = new stdClass();
 507        $course2->fullname = 'Test Data create course 2';
 508        $course2->shortname = 'testdatacourse2';
 509        $course2->categoryid = $categoryid;
 510
 511        $courses = array($course1, $course2);
 512
 513        //do not run the test if course1 or course2 already exists
 514        $existingcourses = $DB->get_records_list('course', 'fullname',
 515                        array($course1->fullname, $course2->fullname));
 516        if (!empty($existingcourses)) {
 517            throw new moodle_exception('testdatacoursesalreadyexist');
 518        }
 519
 520        $function = 'moodle_course_create_courses';
 521        $params = array('courses' => $courses);
 522        $resultcourses = $client->call($function, $params);
 523        $this->assertEqual(count($courses), count($resultcourses));
 524
 525        //retrieve user1 from the DB and check values
 526        $dbcourse1 = $DB->get_record('course', array('fullname' => $course1->fullname));
 527        $this->assertEqual($dbcourse1->fullname, $course1->fullname);
 528        $this->assertEqual($dbcourse1->shortname, $course1->shortname);
 529        $this->assertEqual($dbcourse1->category, $course1->categoryid);
 530        $this->assertEqual($dbcourse1->idnumber, $course1->idnumber);
 531        $this->assertEqual($dbcourse1->summary, $course1->summary);
 532        $this->assertEqual($dbcourse1->summaryformat, $course1->summaryformat);
 533        $this->assertEqual($dbcourse1->format, $course1->format);
 534        $this->assertEqual($dbcourse1->showgrades, $course1->showgrades);
 535        $this->assertEqual($dbcourse1->showreports, $course1->showreports);
 536        $this->assertEqual($dbcourse1->newsitems, $course1->newsitems);
 537        $this->assertEqual($dbcourse1->startdate, $course1->startdate);
 538        $this->assertEqual($dbcourse1->numsections, $course1->numsections);
 539        $this->assertEqual($dbcourse1->maxbytes, $course1->maxbytes);
 540        $this->assertEqual($dbcourse1->visible, $course1->visible);
 541        $this->assertEqual($dbcourse1->hiddensections, $course1->hiddensections);
 542        $this->assertEqual($dbcourse1->groupmode, $course1->groupmode);
 543        $this->assertEqual($dbcourse1->groupmodeforce, $course1->groupmodeforce);
 544        $this->assertEqual($dbcourse1->defaultgroupingid, $course1->defaultgroupingid);
 545        if (!empty($courseconfig->lang)) {
 546            $this->assertEqual($dbcourse1->lang, $course1->lang);
 547        }
 548        if (completion_info::is_enabled_for_site()) {
 549            $this->assertEqual($dbcourse1->enablecompletion, $course1->enablecompletion);
 550            $this->assertEqual($dbcourse1->completionstartonenrol, $course1->completionstartonenrol);
 551        }
 552        $this->assertEqual($dbcourse1->completionnotify, $course1->completionnotify);
 553        if (!empty($CFG->allowcoursethemes)) {
 554            $this->assertEqual($dbcourse1->theme, $course1->forcetheme);
 555        }
 556
 557        //retrieve user2 from the DB and check values
 558        $dbcourse2 = $DB->get_record('course', array('fullname' => $course2->fullname));
 559        $this->assertEqual($dbcourse2->fullname, $course2->fullname);
 560        $this->assertEqual($dbcourse2->shortname, $course2->shortname);
 561        $this->assertEqual($dbcourse2->category, $course2->categoryid);
 562        $this->assertEqual($dbcourse2->summaryformat, FORMAT_MOODLE);
 563        $this->assertEqual($dbcourse2->format, $courseconfig->format);
 564        $this->assertEqual($dbcourse2->showgrades, $courseconfig->showgrades);
 565        $this->assertEqual($dbcourse2->showreports, $courseconfig->showreports);
 566        $this->assertEqual($dbcourse2->newsitems, $courseconfig->newsitems);
 567        $this->assertEqual($dbcourse2->numsections, $courseconfig->numsections);
 568        $this->assertEqual($dbcourse2->maxbytes, $courseconfig->maxbytes);
 569        $this->assertEqual($dbcourse2->visible, $courseconfig->visible);
 570        $this->assertEqual($dbcourse2->hiddensections, $courseconfig->hiddensections);
 571        $this->assertEqual($dbcourse2->groupmode, $courseconfig->groupmode);
 572        $this->assertEqual($dbcourse2->groupmodeforce, $courseconfig->groupmodeforce);
 573        $this->assertEqual($dbcourse2->defaultgroupingid, 0);
 574
 575        //delete users from DB
 576        $DB->delete_records_list('course', 'id',
 577                array($dbcourse1->id, $dbcourse2->id));
 578    }
 579
 580    function moodle_user_create_users($client) {
 581        global $DB, $CFG;
 582
 583        //Test data
 584        //a full user: user1
 585        $user1 = new stdClass();
 586        $user1->username = 'testusername1';
 587        $user1->password = 'testpassword1';
 588        $user1->firstname = 'testfirstname1';
 589        $user1->lastname = 'testlastname1';
 590        $user1->email = 'testemail1@moodle.com';
 591        $user1->auth = 'manual';
 592        $user1->idnumber = 'testidnumber1';
 593        $user1->lang = 'en';
 594        $user1->theme = 'standard';
 595        $user1->timezone = '-12.5';
 596        $user1->mailformat = 0;
 597        $user1->description = 'Hello World!';
 598        $user1->city = 'testcity1';
 599        $user1->country = 'au';
 600        $preferencename1 = 'preference1';
 601        $preferencename2 = 'preference2';
 602        $user1->preferences = array(
 603            array('type' => $preferencename1, 'value' => 'preferencevalue1'),
 604            array('type' => $preferencename2, 'value' => 'preferencevalue2'));
 605        $customfieldname1 = 'testdatacustom1';
 606        $customfieldname2 = 'testdatacustom2';
 607        $user1->customfields = array(
 608            array('type' => $customfieldname1, 'value' => 'customvalue'),
 609            array('type' => $customfieldname2, 'value' => 'customvalue2'));
 610        //a small user: user2
 611        $user2 = new stdClass();
 612        $user2->username = 'testusername2';
 613        $user2->password = 'testpassword2';
 614        $user2->firstname = 'testfirstname2';
 615        $user2->lastname = 'testlastname2';
 616        $user2->email = 'testemail1@moodle.com';
 617        $user2->timezone = 'Pacific/Port_Moresby';
 618
 619        $users = array($user1, $user2);
 620
 621        //do not run the test if user1 or user2 already exists
 622        $existingusers = $DB->get_records_list('user', 'username',
 623                        array($user1->username, $user2->username));
 624        if (!empty($existingusers)) {
 625            throw new moodle_exception('testdatausersalreadyexist');
 626        }
 627
 628        //do not run the test if data test custom fields already exists
 629        $existingcustomfields = $DB->get_records_list('user_info_field', 'shortname',
 630                        array($customfieldname1, $customfieldname2));
 631        if (!empty($existingcustomfields)) {
 632            throw new moodle_exception('testdatacustomfieldsalreadyexist');
 633        }
 634
 635        //create the custom fields
 636        $customfield = new stdClass();
 637        $customfield->shortname = $customfieldname1;
 638        $customfield->name = $customfieldname1;
 639        $customfield->datatype = 'text';
 640        $DB->insert_record('user_info_field', $customfield);
 641        $customfield = new stdClass();
 642        $customfield->shortname = $customfieldname2;
 643        $customfield->name = $customfieldname2;
 644        $customfield->datatype = 'text';
 645        $DB->insert_record('user_info_field', $customfield);
 646
 647        $function = 'moodle_user_create_users';
 648        $params = array('users' => $users);
 649        $resultusers = $client->call($function, $params);
 650        $this->assertEqual(count($users), count($resultusers));
 651
 652        //retrieve user1 from the DB and check values
 653        $dbuser1 = $DB->get_record('user', array('username' => $user1->username));
 654        $this->assertEqual($dbuser1->firstname, $user1->firstname);
 655        $this->assertEqual($dbuser1->password,
 656                hash_internal_user_password($user1->password));
 657        $this->assertEqual($dbuser1->lastname, $user1->lastname);
 658        $this->assertEqual($dbuser1->email, $user1->email);
 659        $this->assertEqual($dbuser1->auth, $user1->auth);
 660        $this->assertEqual($dbuser1->idnumber, $user1->idnumber);
 661        $this->assertEqual($dbuser1->lang, $user1->lang);
 662        $this->assertEqual($dbuser1->theme, $user1->theme);
 663        $this->assertEqual($dbuser1->timezone, $user1->timezone);
 664        $this->assertEqual($dbuser1->mailformat, $user1->mailformat);
 665        $this->assertEqual($dbuser1->description, $user1->description);
 666        $this->assertEqual($dbuser1->city, $user1->city);
 667        $this->assertEqual($dbuser1->country, $user1->country);
 668        $user1preference1 = get_user_preferences($user1->preferences[0]['type'],
 669                        null, $dbuser1->id);
 670        $this->assertEqual($user1->preferences[0]['value'], $user1preference1);
 671        $user1preference2 = get_user_preferences($user1->preferences[1]['type'],
 672                        null, $dbuser1->id);
 673        $this->assertEqual($user1->preferences[1]['value'], $user1preference2);
 674        require_once($CFG->dirroot . "/user/profile/lib.php");
 675        $customfields = profile_user_record($dbuser1->id);
 676
 677        $customfields = (array) $customfields;
 678        $customfieldname1 = $user1->customfields[0]['type'];
 679        $customfieldname2 = $user1->customfields[1]['type'];
 680        $this->assertEqual($customfields[$customfieldname1],
 681                $user1->customfields[0]['value']);
 682        $this->assertEqual($customfields[$customfieldname2],
 683                $user1->customfields[1]['value']);
 684
 685
 686        //retrieve user2 from the DB and check values
 687        $dbuser2 = $DB->get_record('user', array('username' => $user2->username));
 688        $this->assertEqual($dbuser2->firstname, $user2->firstname);
 689        $this->assertEqual($dbuser2->password,
 690                hash_internal_user_password($user2->password));
 691        $this->assertEqual($dbuser2->lastname, $user2->lastname);
 692        $this->assertEqual($dbuser2->email, $user2->email);
 693        $this->assertEqual($dbuser2->timezone, $user2->timezone);
 694
 695        //unset preferences
 696        $DB->delete_records('user_preferences', array('userid' => $dbuser1->id));
 697
 698        //clear custom fields data
 699        $DB->delete_records('user_info_data', array('userid' => $dbuser1->id));
 700
 701        //delete custom fields
 702        $DB->delete_records_list('user_info_field', 'shortname',
 703                array($customfieldname1, $customfieldname2));
 704
 705        //delete users from DB
 706        $DB->delete_records_list('user', 'id',
 707                array($dbuser1->id, $dbuser2->id));
 708    }
 709
 710    function moodle_user_delete_users($client) {
 711        global $DB, $CFG;
 712
 713        //Set test data
 714        //a full user: user1
 715        $user1 = new stdClass();
 716        $user1->username = 'veryimprobabletestusername1';
 717        $user1->password = 'testpassword1';
 718        $user1->firstname = 'testfirstname1';
 719        $user1->lastname = 'testlastname1';
 720        $user1->email = 'testemail1@moodle.com';
 721        $user1->auth = 'manual';
 722        $user1->idnumber = 'testidnumber1';
 723        $user1->lang = 'en';
 724        $user1->theme = 'standard';
 725        $user1->timezone = 99;
 726        $user1->mailformat = 0;
 727        $user1->description = 'Hello World!';
 728        $user1->city = 'testcity1';
 729        $user1->country = 'au';
 730        $preferencename1 = 'preference1';
 731        $preferencename2 = 'preference2';
 732        $user1->preferences = array(
 733            array('type' => $preferencename1, 'value' => 'preferencevalue1'),
 734            array('type' => $preferencename2, 'value' => 'preferencevalue2'));
 735        $customfieldname1 = 'testdatacustom1';
 736        $customfieldname2 = 'testdatacustom2';
 737        $user1->customfields = array(
 738            array('type' => $customfieldname1, 'value' => 'customvalue'),
 739            array('type' => $customfieldname2, 'value' => 'customvalue2'));
 740        //a small user: user2
 741        $user2 = new stdClass();
 742        $user2->username = 'veryimprobabletestusername2';
 743        $user2->password = 'testpassword2';
 744        $user2->firstname = 'testfirstname2';
 745        $user2->lastname = 'testlastname2';
 746        $user2->email = 'testemail1@moodle.com';
 747        $users = array($user1, $user2);
 748
 749        //can run this test only if test usernames don't exist
 750        $searchusers = $DB->get_records_list('user', 'username',
 751                array($user1->username, $user1->username));
 752        if (count($searchusers) == 0) {
 753            //create two users
 754            require_once($CFG->dirroot."/user/lib.php");
 755            require_once($CFG->dirroot."/user/profile/lib.php");
 756            $user1->id = user_create_user($user1);
 757            // custom fields
 758            if(!empty($user1->customfields)) {
 759                foreach($user1->customfields as $customfield) {
 760                    $user1->{"profile_field_".$customfield['type']} = $customfield['value'];
 761                }
 762                profile_save_data((object) $user1);
 763            }
 764            //preferences
 765            if (!empty($user1->preferences)) {
 766                foreach($user1->preferences as $preference) {
 767                    set_user_preference($preference['type'], $preference['value'],$user1->id);
 768                }
 769            }
 770            $user2->id = user_create_user($user2);
 771
 772            //create the custom fields
 773            $customfield = new stdClass();
 774            $customfield->shortname = $customfieldname1;
 775            $customfield->name = $customfieldname1;
 776            $customfield->datatype = 'text';
 777            $DB->insert_record('user_info_field', $customfield);
 778            $customfield = new stdClass();
 779            $customfield->shortname = $customfieldname2;
 780            $customfield->name = $customfieldname2;
 781            $customfield->datatype = 'text';
 782            $DB->insert_record('user_info_field', $customfield);
 783
 784            //search for them => TEST they exists
 785            $searchusers = $DB->get_records_list('user', 'username',
 786                    array($user1->username, $user2->username));
 787            $this->assertEqual(count($users), count($searchusers));
 788
 789            //delete the users by webservice
 790            $function = 'moodle_user_delete_users';
 791            $params = array('users' => array($user1->id, $user2->id));
 792            $client->call($function, $params);
 793
 794            //search for them => TESTS they don't exists
 795            $searchusers = $DB->get_records_list('user', 'username',
 796                    array($user1->username, $user2->username));
 797           
 798            $this->assertTrue(empty($searchusers));
 799
 800            //unset preferences
 801            $DB->delete_records('user_preferences', array('userid' => $user1->id));
 802
 803            //clear custom fields data
 804            $DB->delete_records('user_info_data', array('userid' => $user1->id));
 805
 806            //delete custom fields
 807            $DB->delete_records_list('user_info_field', 'shortname',
 808                    array($customfieldname1, $customfieldname2));
 809
 810            //delete users from DB
 811            $DB->delete_records_list('user', 'id',
 812                    array($user1->id, $user2->id));
 813        }
 814    }
 815
 816    function moodle_user_update_users($client) {
 817        global $DB, $CFG;
 818
 819        //Set test data
 820        //a full user: user1
 821        $user1 = new stdClass();
 822        $user1->username = 'veryimprobabletestusername1';
 823        $user1->password = 'testpassword1';
 824        $user1->firstname = 'testfirstname1';
 825        $user1->lastname = 'testlastname1';
 826        $user1->email = 'testemail1@moodle.com';
 827        $user1->auth = 'manual';
 828        $user1->idnumber = 'testidnumber1';
 829        $user1->lang = 'en';
 830        $user1->theme = 'standard';
 831        $user1->timezone = 99;
 832        $user1->mailformat = 0;
 833        $user1->description = 'Hello World!';
 834        $user1->city = 'testcity1';
 835        $user1->country = 'au';
 836        $preferencename1 = 'preference1';
 837        $preferencename2 = 'preference2';
 838        $user1->preferences = array(
 839            array('type' => $preferencename1, 'value' => 'preferencevalue1'),
 840            array('type' => $preferencename2, 'value' => 'preferencevalue2'));
 841        $customfieldname1 = 'testdatacustom1';
 842        $customfieldname2 = 'testdatacustom2';
 843        $user1->customfields = array(
 844            array('type' => $customfieldname1, 'value' => 'customvalue'),
 845            array('type' => $customfieldname2, 'value' => 'customvalue2'));
 846        //a small user: user2
 847        $user2 = new stdClass();
 848        $user2->username = 'veryimprobabletestusername2';
 849        $user2->password = 'testpassword2';
 850        $user2->firstname = 'testfirstname2';
 851        $user2->lastname = 'testlastname2';
 852        $user2->email = 'testemail1@moodle.com';
 853        $users = array($user1, $user2);
 854
 855        //can run this test only if test usernames don't exist
 856        $searchusers = $DB->get_records_list('user', 'username',
 857                array($user1->username, $user1->username));
 858        if (count($searchusers) == 0) {
 859            //create two users
 860            require_once($CFG->dirroot."/user/lib.php");
 861            require_once($CFG->dirroot."/user/profile/lib.php");
 862            $user1->id = user_create_user($user1);
 863            //unset field created by user_create_user
 864            unset($user1->timemodified);
 865            unset($user1->timecreated);
 866
 867            // custom fields
 868            if(!empty($user1->customfields)) {
 869                foreach($user1->customfields as $customfield) {
 870                    $customuser1->id = $user1->id;
 871                    $customuser1->{"profile_field_".$customfield['type']} = $customfield['value'];
 872                }
 873                profile_save_data((object) $customuser1);
 874            }
 875            //preferences
 876            if (!empty($user1->preferences)) {
 877                foreach($user1->preferences as $preference) {
 878                    set_user_preference($preference['type'], $preference['value'],$user1->id);
 879                }
 880            }
 881            $user2->id = user_create_user($user2);
 882            unset($user2->timemodified);
 883            unset($user2->timecreated);
 884
 885             //create the custom fields
 886            $customfield = new stdClass();
 887            $customfield->shortname = $customfieldname1;
 888            $customfield->name = $customfieldname1;
 889            $customfield->datatype = 'text';
 890            $DB->insert_record('user_info_field', $customfield);
 891            $customfield = new stdClass();
 892            $customfield->shortname = $customfieldname2;
 893            $customfield->name = $customfieldname2;
 894            $customfield->datatype = 'text';
 895            $DB->insert_record('user_info_field', $customfield);
 896            
 897            //search for them => TEST they exists
 898            $searchusers = $DB->get_records_list('user', 'username',
 899                    array($user1->username, $user2->username));
 900            $this->assertEqual(count($users), count($searchusers));
 901
 902            //update the test data
 903            $user1->username = 'veryimprobabletestusername1_updated';
 904            $user1->password = 'testpassword1_updated';
 905            $user1->firstname = 'testfirstname1_updated';
 906            $user1->lastname = 'testlastname1_updated';
 907            $user1->email = 'testemail1_updated@moodle.com';
 908            $user1->auth = 'manual';
 909            $user1->idnumber = 'testidnumber1_updated';
 910            $user1->lang = 'en';
 911            $user1->theme = 'standard';
 912            $user1->timezone = 98;
 913            $user1->mailformat = 1;
 914            $user1->description = 'Hello World!_updated';
 915            $user1->city = 'testcity1_updated';
 916            $user1->country = 'au';
 917            $preferencename1 = 'preference1';
 918            $preferencename2 = 'preference2';
 919            $user1->preferences = array(
 920            array('type' => $preferencename1, 'value' => 'preferencevalue1_updated'),
 921            array('type' => $preferencename2, 'value' => 'preferencevalue2_updated'));
 922            $customfieldname1 = 'testdatacustom1';
 923            $customfieldname2 = 'testdatacustom2';
 924            $user1->customfields = array(
 925            array('type' => $customfieldname1, 'value' => 'customvalue_updated'),
 926            array('type' => $customfieldname2, 'value' => 'customvalue2_updated'));
 927            $user2->username = 'veryimprobabletestusername2_updated';
 928            $user2->password = 'testpassword2_updated';
 929            $user2->firstname = 'testfirstname2_updated';
 930            $user2->lastname = 'testlastname2_updated';
 931            $user2->email = 'testemail1_updated@moodle.com';
 932            $users = array($user1, $user2);
 933            
 934            //update the users by web service
 935            $function = 'moodle_user_update_users';
 936            $params = array('users' => $users);
 937            $client->call($function, $params);
 938
 939            //compare DB user with the test data
 940            $dbuser1 = $DB->get_record('user', array('username' => $user1->username));
 941            $this->assertEqual($dbuser1->firstname, $user1->firstname);
 942            $this->assertEqual($dbuser1->password,
 943                    hash_internal_user_password($user1->password));
 944            $this->assertEqual($dbuser1->lastname, $user1->lastname);
 945            $this->assertEqual($dbuser1->email, $user1->email);
 946            $this->assertEqual($dbuser1->auth, $user1->auth);
 947            $this->assertEqual($dbuser1->idnumber, $user1->idnumber);
 948            $this->assertEqual($dbuser1->lang, $user1->lang);
 949            $this->assertEqual($dbuser1->theme, $user1->theme);
 950            $this->assertEqual($dbuser1->timezone, $user1->timezone);
 951            $this->assertEqual($dbuser1->mailformat, $user1->mailformat);
 952            $this->assertEqual($dbuser1->description, $user1->description);
 953            $this->assertEqual($dbuser1->city, $user1->city);
 954            $this->assertEqual($dbuser1->country, $user1->country);
 955            $user1preference1 = get_user_preferences($user1->preferences[0]['type'],
 956                            null, $dbuser1->id);
 957            $this->assertEqual($user1->preferences[0]['value'], $user1preference1);
 958            $user1preference2 = get_user_preferences($user1->preferences[1]['type'],
 959                            null, $dbuser1->id);
 960            $this->assertEqual($user1->preferences[1]['value'], $user1preference2);
 961            require_once($CFG->dirroot . "/user/profile/lib.php");
 962            $customfields = profile_user_record($dbuser1->id);
 963
 964            $customfields = (array) $customfields;
 965            $customfieldname1 = $user1->customfields[0]['type'];
 966            $customfieldname2 = $user1->customfields[1]['type'];
 967            $this->assertEqual($customfields[$customfieldname1],
 968                    $user1->customfields[0]['value']);
 969            $this->assertEqual($customfields[$customfieldname2],
 970                    $user1->customfields[1]['value']);
 971
 972            $dbuser2 = $DB->get_record('user', array('username' => $user2->username));
 973            $this->assertEqual($dbuser2->firstname, $user2->firstname);
 974            $this->assertEqual($dbuser2->password,
 975                    hash_internal_user_password($user2->password));
 976            $this->assertEqual($dbuser2->lastname, $user2->lastname);
 977            $this->assertEqual($dbuser2->email, $user2->email);
 978
 979            //unset preferences
 980            $DB->delete_records('user_preferences', array('userid' => $dbuser1->id));
 981
 982            //clear custom fields data
 983            $DB->delete_records('user_info_data', array('userid' => $dbuser1->id));
 984
 985            //delete custom fields
 986            $DB->delete_records_list('user_info_field', 'shortname',
 987                    array($customfieldname1, $customfieldname2));
 988
 989            //delete users from DB
 990            $DB->delete_records_list('user', 'id',
 991                    array($dbuser1->id, $dbuser2->id));
 992
 993        }
 994    }
 995
 996    function moodle_role_assign($client) {
 997        global $DB, $CFG;
 998
 999        $searchusers = $DB->get_records_list('user', 'username',
1000                array('veryimprobabletestusername2'));
1001        $searchroles = $DB->get_records_list('role', 'shortname',
1002                array('role1thatshouldnotexist', 'role2thatshouldnotexist'));
1003
1004        if (empty($searchusers) and empty($searchroles)) {
1005
1006            //create a temp user
1007            $user = new stdClass();
1008            $user->username = 'veryimprobabletestusername2';
1009            $user->password = 'testpassword2';
1010            $user->firstname = 'testfirstname2';
1011            $user->lastname = 'testlastname2';
1012            $user->email = 'testemail1@moodle.com';
1013            require_once($CFG->dirroot."/user/lib.php");
1014            $user->id = user_create_user($user);
1015
1016            //create two roles
1017            $role1->id = create_role('role1thatshouldnotexist', 'role1thatshouldnotexist', '');
1018            $role2->id = create_role('role2thatshouldnotexist', 'role2thatshouldnotexist', '');
1019
1020            //assign user to role by webservice
1021            $context = get_system_context();
1022            $assignments = array(
1023                array('roleid' => $role1->id, 'userid' => $user->id, 'contextid' => $context->id),
1024                array('roleid' => $role2->id, 'userid' => $user->id, 'contextid' => $context->id)
1025            );
1026
1027            $function = 'moodle_role_assign';
1028            $params = array('assignments' => $assignments);
1029            $client->call($function, $params);
1030
1031            //check that the assignment work
1032            $roles = get_user_roles($context, $user->id, false);
1033            foreach ($roles as $role) {
1034                $this->assertTrue(($role->roleid == $role1->id) or ($role->roleid == $role2->id) );
1035            }
1036
1037            //unassign roles from user
1038            role_unassign($role1->id, $user->id, $context->id, '', NULL);
1039            role_unassign($role2->id, $user->id, $context->id, '', NULL);
1040
1041            //delete user from DB
1042            $DB->delete_records('user', array('id' => $user->id));
1043
1044            //delete the two role from DB
1045            delete_role($role1->id);
1046            delete_role($role2->id);
1047        }
1048    }
1049
1050    function moodle_role_unassign($client) {
1051        global $DB, $CFG;
1052
1053        $searchusers = $DB->get_records_list('user', 'username',
1054                array('veryimprobabletestusername2'));
1055        $searchroles = $DB->get_records_list('role', 'shortname',
1056                array('role1thatshouldnotexist', 'role2thatshouldnotexist'));
1057
1058        if (empty($searchusers) and empty($searchroles)) {
1059
1060            //create a temp user
1061            $user = new stdClass();
1062            $user->username = 'veryimprobabletestusername2';
1063            $user->password = 'testpassword2';
1064            $user->firstname = 'testfirstname2';
1065            $user->lastname = 'testlastname2';
1066            $user->email = 'testemail1@moodle.com';
1067            require_once($CFG->dirroot."/user/lib.php");
1068            $user->id = user_create_user($user);
1069
1070            //create two roles
1071            $role1->id = create_role('role1thatshouldnotexist', 'role1thatshouldnotexist', '');
1072            $role2->id = create_role('role2thatshouldnotexist', 'role2thatshouldnotexist', '');
1073        
1074            //assign roles from user
1075            $context = get_system_context();
1076            role_assign($role1->id, $user->id, $context->id);
1077            role_assign($role2->id, $user->id, $context->id);
1078
1079            //check that the local assignment work
1080            $roles = get_user_roles($context, $user->id, false);
1081            foreach ($roles as $role) {
1082                $this->assertTrue(($role->roleid == $role1->id) or ($role->roleid == $role2->id) );
1083            }
1084
1085            //unassign user to role by webservice          
1086            $assignments = array(
1087                array('roleid' => $role1->id, 'userid' => $user->id, 'contextid' => $context->id),
1088                array('roleid' => $role2->id, 'userid' => $user->id, 'contextid' => $context->id)
1089            );
1090            $function = 'moodle_role_unassign';
1091            $params = array('assignments' => $assignments);
1092            $client->call($function, $params);
1093
1094            //check that the web service unassignment work
1095            $roles = get_user_roles($context, $user->id, false);
1096            $this->assertTrue(empty($roles));
1097
1098            //delete user from DB
1099            $DB->delete_records('user', array('id' => $user->id));
1100
1101            //delete the two role from DB
1102            delete_role($role1->id);
1103            delete_role($role2->id);
1104        }
1105
1106    }
1107
1108    /**
1109     * READ ONLY test
1110     * TODO: find a better solution that running web service for each course
1111     * in the system
1112     * For each courses, test the number of groups
1113     * @param object $client
1114     */
1115    function moodle_group_get_course_groups($client) {
1116        global $DB;
1117
1118        $courses = $DB->get_records('course');
1119        foreach($courses as $course) {
1120            $coursegroups = groups_get_all_groups($course->id);
1121            $function = 'moodle_group_get_course_groups';
1122            $params = array('courseid' => $course->id);
1123            $groups = $client->call($function, $params);
1124            $this->assertEqual(count($groups), count($coursegroups));
1125        }
1126    }
1127
1128
1129    /**
1130     * READ ONLY test
1131     * Test that the same number of members are returned
1132     * for each existing group in the system
1133     * @param object $client
1134     */
1135    function moodle_group_get_groupmembers($client) {
1136        global $DB;
1137
1138        $groups = $DB->get_records('groups');
1139        $groupids = array();
1140        foreach ($groups as $group) {
1141            $groupids[] = $group->id;
1142        }
1143        $function = 'moodle_group_get_groupmembers';
1144        $params = array('groupids' => $groupids);
1145        $groupsmembers = $client->call($function, $params);
1146
1147        foreach($groupsmembers as $groupmembers) {
1148            $dbgroupmembers = groups_get_members($groupmembers['groupid']);
1149            unset($groups[$groupmembers['groupid']]);
1150            $this->assertEqual(count($dbgroupmembers), count($groupmembers['userids']));
1151        }
1152
1153        //check that all existing groups have been returned by the web service function
1154        $this->assertTrue(empty($groups));
1155       
1156        
1157    }
1158
1159    function moodle_group_add_groupmembers($client) {
1160        global $DB, $CFG;
1161
1162        //create category
1163        $category = new stdClass();
1164        $category->name = 'tmpcategoryfortest123';
1165        $category->id = $DB->insert_record('c…

Large files files are truncated, but you can click here to view the full file