mirror of
https://github.com/moodle/moodle.git
synced 2025-04-16 14:02:32 +02:00
web service MDL-12886 add standard Course web service functions
This commit is contained in:
parent
403d51f2fa
commit
71b77297a9
271
course/external.php
Normal file
271
course/external.php
Normal file
@ -0,0 +1,271 @@
|
||||
<?php
|
||||
/**
|
||||
* Moodle - Modular Object-Oriented Dynamic Learning Environment
|
||||
* http://moodle.com
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details:
|
||||
*
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* @category Moodle
|
||||
* @package user
|
||||
* @copyright Copyright (c) 1999 onwards Martin Dougiamas http://dougiamas.com
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL License
|
||||
*/
|
||||
require_once(dirname(dirname(__FILE__)) . '/course/lib.php');
|
||||
|
||||
/**
|
||||
* course webservice api
|
||||
*
|
||||
* @author Jerome Mouneyrac
|
||||
*/
|
||||
final class course_external {
|
||||
|
||||
/**
|
||||
* Retrieve courses
|
||||
* @param array|struct $params - need to be define as struct for XMLRPC
|
||||
* @subparam integer $params:search->id - the id to search
|
||||
* @subparam string $params:search->idnumber - the idnumber to search
|
||||
* @subparam string $params:search->shortname - the shortname to search
|
||||
* @return object $return
|
||||
* @subparam integer $return:course->id
|
||||
* @subparam string $return:course->category
|
||||
* @subparam string $return:course->summary
|
||||
* @subparam string $return:course->format
|
||||
* @subparam string $return:course->numsections
|
||||
* @subparam string $return:course->startdate
|
||||
* @subparam string $return:course->fullname
|
||||
* @subparam string $return:course->shortname
|
||||
* @subparam string $return:course->idnumber
|
||||
*/
|
||||
static function get_courses($params) {
|
||||
global $USER;
|
||||
if (has_capability('moodle/course:view', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
$courses = array();
|
||||
foreach ($params as $param) {
|
||||
$course = new stdClass();
|
||||
if (key_exists('id', $param)) {
|
||||
$param['id'] = clean_param($param['id'], PARAM_INT);
|
||||
$course = get_course_by_id($param['id']);
|
||||
|
||||
} else if (key_exists('idnumber', $param)) {
|
||||
$param['idnumber'] = clean_param($param['idnumber'], PARAM_ALPHANUM);
|
||||
$course = get_course_by_idnumber($param['idnumber']);
|
||||
} else if (key_exists('shortname', $param)) {
|
||||
$param['shortname'] = clean_param($param['shortname'], PARAM_ALPHANUM);
|
||||
$course = get_course_by_shortname($param['shortname']);
|
||||
}
|
||||
if (!empty($course)) {
|
||||
$returnedcourse = new stdClass();
|
||||
$returnedcourse->id = $course->id;
|
||||
$returnedcourse->idnumber = $course->idnumber;
|
||||
$returnedcourse->shortname = $course->shortname;
|
||||
$returnedcourse->summary = $course->summary;
|
||||
$returnedcourse->format = $course->format;
|
||||
$returnedcourse->fullname = $course->fullname;
|
||||
$returnedcourse->numsections = $course->numsections;
|
||||
$returnedcourse->startdate = $course->startdate;
|
||||
$returnedcourse->category = $course->category;
|
||||
$courses[] = $returnedcourse;
|
||||
}
|
||||
}
|
||||
return $courses;
|
||||
}
|
||||
else {
|
||||
throw new moodle_exception('wscouldnotviewcoursenopermission');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create multiple courses
|
||||
* @param array|struct $params - need to be define as struct for XMLRPC
|
||||
* @subparam integer $params:course->category
|
||||
* @subparam string $params:course->summary
|
||||
* @subparam string $params:course->format
|
||||
* @subparam string $params:course->numsections
|
||||
* @subparam string $params:course->startdate
|
||||
* @subparam string $params:course->fullname
|
||||
* @subparam string $params:course->shortname
|
||||
* @subparam string $params:course->idnumber
|
||||
* @return array $return ids of new courses
|
||||
* @subreturn integer $return:id course id
|
||||
*/
|
||||
static function create_courses($params) {
|
||||
global $USER;
|
||||
if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
$courses = array();
|
||||
foreach ($params as $courseparams) {
|
||||
|
||||
$course = new stdClass();
|
||||
if (array_key_exists('category', $courseparams)) {
|
||||
$course->category = clean_param($courseparams['category'], PARAM_INT);
|
||||
}
|
||||
|
||||
if (array_key_exists('idnumber', $courseparams)) {
|
||||
$course->idnumber = clean_param($courseparams['idnumber'], PARAM_ALPHANUMEXT);
|
||||
}
|
||||
|
||||
if (array_key_exists('shortname', $courseparams)) {
|
||||
$course->shortname = clean_param($courseparams['shortname'], PARAM_ALPHANUMEXT);
|
||||
}
|
||||
|
||||
if (array_key_exists('format', $courseparams)) {
|
||||
$course->format = clean_param($courseparams['format'], PARAM_ALPHANUMEXT);
|
||||
}
|
||||
|
||||
if (array_key_exists('fullname', $courseparams)) {
|
||||
$course->fullname = clean_param($courseparams['fullname'], PARAM_ALPHANUMEXT);
|
||||
}
|
||||
|
||||
if (array_key_exists('summary', $courseparams)) {
|
||||
$course->summary = clean_param($courseparams['summary'], PARAM_ALPHANUMEXT);
|
||||
}
|
||||
|
||||
if (array_key_exists('numsections', $courseparams)) {
|
||||
$course->numsections = clean_param($courseparams['numsections'], PARAM_ALPHANUMEXT);
|
||||
}
|
||||
|
||||
if (array_key_exists('startdate', $courseparams)) {
|
||||
$course->startdate = clean_param($courseparams['startdate'], PARAM_ALPHANUMEXT);
|
||||
}
|
||||
|
||||
$courses[] = create_course($course);
|
||||
|
||||
}
|
||||
return $courses;
|
||||
}
|
||||
else {
|
||||
throw new moodle_exception('wscouldnotcreateecoursenopermission');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete multiple courses
|
||||
* @global object $DB
|
||||
* @param array|struct $params - need to be define as struct for XMLRPC
|
||||
* @subparam string $params:course->shortname
|
||||
* @subparam integer $params:course->id
|
||||
* @subparam string $params:course->shortname
|
||||
* @subparam string $params:course->idnumber
|
||||
* @return boolean result true if success
|
||||
*/
|
||||
static function delete_courses($params) {
|
||||
global $DB,$USER;
|
||||
if (has_capability('moodle/course:delete', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
$courses = array();
|
||||
$result = true;
|
||||
foreach ($params as $param) {
|
||||
$course = new stdClass();
|
||||
if (key_exists('id', $param)) {
|
||||
$param['id'] = clean_param($param['id'], PARAM_INT);
|
||||
if (!delete_course($param['id'], false)) {
|
||||
$result = false;
|
||||
}
|
||||
} else if (key_exists('idnumber', $param)) {
|
||||
$param['idnumber'] = clean_param($param['idnumber'], PARAM_ALPHANUM);
|
||||
//it doesn't cost that much to retrieve the course here
|
||||
//as it would be done into delete_course()
|
||||
$course = $DB->get_record('course', array('idnumber'=>$param['idnumber']));
|
||||
if (!delete_course($course, false)) {
|
||||
$result = false;
|
||||
}
|
||||
} else if (key_exists('shortname', $param)) {
|
||||
$param['shortname'] = clean_param($param['shortname'], PARAM_ALPHANUM);
|
||||
$course = $DB->get_record('course', array('shortname'=>$param['shortname']));
|
||||
if (!delete_course($course, false)) {
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
else {
|
||||
throw new moodle_exception('wscouldnotdeletecoursenopermission');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update some courses information
|
||||
* @global object $DB
|
||||
* @param array|struct $params - need to be define as struct for XMLRPC
|
||||
* @subparam integer $params:course->category
|
||||
* @subparam string $params:course->summary
|
||||
* @subparam string $params:course->format
|
||||
* @subparam string $params:course->numsections
|
||||
* @subparam string $params:course->startdate
|
||||
* @subparam string $params:course->fullname
|
||||
* @subparam string $params:course->shortname
|
||||
* @subparam string $params:course->idnumber
|
||||
* @return boolean result true if success
|
||||
*/
|
||||
static function update_courses($params) {
|
||||
global $DB,$USER;
|
||||
|
||||
if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
$courses = array();
|
||||
$result = true;
|
||||
foreach ($params as $courseparams) {
|
||||
|
||||
$course = new stdClass();
|
||||
if (array_key_exists('category', $courseparams)) {
|
||||
$course->category = clean_param($courseparams['category'], PARAM_INT);
|
||||
}
|
||||
|
||||
if (array_key_exists('idnumber', $courseparams)) {
|
||||
$course->idnumber = clean_param($courseparams['idnumber'], PARAM_ALPHANUMEXT);
|
||||
}
|
||||
|
||||
if (array_key_exists('shortname', $courseparams)) {
|
||||
$course->shortname = clean_param($courseparams['shortname'], PARAM_ALPHANUMEXT);
|
||||
}
|
||||
|
||||
if (array_key_exists('format', $courseparams)) {
|
||||
$course->format = clean_param($courseparams['format'], PARAM_ALPHANUMEXT);
|
||||
}
|
||||
|
||||
if (array_key_exists('fullname', $courseparams)) {
|
||||
$course->fullname = clean_param($courseparams['fullname'], PARAM_TEXT);
|
||||
}
|
||||
|
||||
if (array_key_exists('summary', $courseparams)) {
|
||||
$course->summary = clean_param($courseparams['summary'], PARAM_TEXT);
|
||||
}
|
||||
|
||||
if (array_key_exists('numsections', $courseparams)) {
|
||||
$course->numsections = clean_param($courseparams['numsections'], PARAM_ALPHANUMEXT);
|
||||
}
|
||||
|
||||
if (array_key_exists('startdate', $courseparams)) {
|
||||
$course->startdate = clean_param($courseparams['startdate'], PARAM_ALPHANUMEXT);
|
||||
}
|
||||
|
||||
if (array_key_exists('id', $courseparams)) {
|
||||
$course->id = clean_param($courseparams['id'], PARAM_INT);
|
||||
}
|
||||
|
||||
if (!update_course($course)) {
|
||||
$result = false;
|
||||
}
|
||||
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
else {
|
||||
throw new moodle_exception('wscouldnotupdatecoursenopermission');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -3455,6 +3455,31 @@ function save_local_role_names($courseid, $data) {
|
||||
function create_course($data) {
|
||||
global $CFG, $USER, $DB;
|
||||
|
||||
//check the categoryid
|
||||
if (!empty($data->category) && !$data->category==0) {
|
||||
$category = $DB->get_record('course_categories', array('id'=>$data->category));
|
||||
if (empty($category)) {
|
||||
throw new moodle_exception('noexistingcategory');
|
||||
}
|
||||
}
|
||||
|
||||
//check if the shortname already exist
|
||||
if(!empty($data->shortname)) {
|
||||
$course = $DB->get_record('course', array('shortname' => $data->shortname));
|
||||
if (!empty($course)) {
|
||||
throw new moodle_exception('shortnametaken');
|
||||
}
|
||||
}
|
||||
|
||||
//check if the id number already exist
|
||||
if(!empty($data->idnumber)) {
|
||||
$course = $DB->get_record('course', array('idnumber' => $data->idnumber));
|
||||
if (!empty($course)) {
|
||||
throw new moodle_exception('idnumbertaken');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// preprocess allowed mods
|
||||
$allowedmods = empty($data->allowedmods) ? array() : $data->allowedmods;
|
||||
unset($data->allowedmods);
|
||||
@ -3519,6 +3544,11 @@ function update_course($data) {
|
||||
|
||||
$movecat = false;
|
||||
$oldcourse = $DB->get_record('course', array('id'=>$data->id)); // should not fail, already tested above
|
||||
// check that course id exist
|
||||
if (empty($oldcourse)) {
|
||||
throw new moodle_exception('courseidnotfound');
|
||||
}
|
||||
|
||||
if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $oldcourse->category))
|
||||
or !has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $data->category))) {
|
||||
// can not move to new category, keep the old one
|
||||
@ -3602,4 +3632,19 @@ function is_course_participant ($userid, $courseid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function get_course_by_id ($id) {
|
||||
global $DB;
|
||||
return $DB->get_record('course', array('id' => $id));
|
||||
}
|
||||
|
||||
function get_course_by_shortname ($shortname) {
|
||||
global $DB;
|
||||
return $DB->get_record('course', array('shortname' => $shortname));
|
||||
}
|
||||
|
||||
function get_course_by_idnumber ($idnumber) {
|
||||
global $DB;
|
||||
return $DB->get_record('course', array('idnumber' => $idnumber));
|
||||
}
|
||||
|
||||
?>
|
||||
|
378
course/simpletest/testexternal.php
Normal file
378
course/simpletest/testexternal.php
Normal file
@ -0,0 +1,378 @@
|
||||
<?php
|
||||
/**
|
||||
* Moodle - Modular Object-Oriented Dynamic Learning Environment
|
||||
* http://moodle.com
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details:
|
||||
*
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* @category Moodle
|
||||
* @package group
|
||||
* @copyright Copyright (c) 1999 onwards Martin Dougiamas http://dougiamas.com
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Unit tests for (some of) user/external.php.
|
||||
* WARNING: DO NOT RUN THIS TEST ON A PRODUCTION SITE
|
||||
* => DO NOT UNCOMMENT THESE TEST FUNCTIONS EXCEPT IF YOU ARE DEVELOPER
|
||||
* => NONE OF THESE TEST FUNCTIONS SHOULD BE UNCOMMENT BY DEFAULT
|
||||
* => THESE TEST FUNCTIONS ARE DEPENDENT BETWEEEN EACH OTHER
|
||||
* => THE FUNCTION ORDER MUST NOT BE CHANGED
|
||||
*
|
||||
*
|
||||
* THIS TEST NEEDS TO BE RUN AS ADMIN!!!
|
||||
* @author Jerome Mouneyrac
|
||||
*/
|
||||
|
||||
require_once($CFG->dirroot . '/course/external.php');
|
||||
require_once(dirname(dirname(dirname(__FILE__))) . '/user/lib.php');
|
||||
|
||||
class course_external_test extends UnitTestCase {
|
||||
/*
|
||||
var $realDB;
|
||||
var $group;
|
||||
var $group2;
|
||||
var $userid1;
|
||||
var $userid2;
|
||||
var $userid3;
|
||||
var $userid4;
|
||||
var $userid5;
|
||||
var $course;
|
||||
var $categoryid;
|
||||
var $roleid;
|
||||
var $context;
|
||||
|
||||
function setUp() {
|
||||
global $DB;
|
||||
|
||||
/// create a category
|
||||
$tempcat = new object();
|
||||
$tempcat->name = 'categoryForTestCourse';
|
||||
$this->categoryid = $DB->insert_record('course_categories', $tempcat);
|
||||
|
||||
/// create a course
|
||||
$course->category = $this->categoryid;
|
||||
$course->summary = 'Test course for Course';
|
||||
$course->format = 'weeks';
|
||||
$course->numsections = '10';
|
||||
$course->startdate = mktime();
|
||||
$course->name = "Test course for Course";
|
||||
$course->fullname = "Test course for Course";
|
||||
$course->shortname = "TestCourseForCourse";
|
||||
$course->idnumber = 123456789;
|
||||
$course = create_course($course);
|
||||
$this->course = $course;
|
||||
|
||||
|
||||
/// create two students
|
||||
// $user = new stdClass();
|
||||
// $user->username = 'mockuserfortestingXX';
|
||||
// $user->firstname = 'mockuserfortestingX_firstname';
|
||||
// $user->lastname = 'mockuserfortestingX_lastname';
|
||||
// $user->email = 'mockuserfortestingX@moodle.com';
|
||||
// $user->password = 'mockuserfortestingX_password';
|
||||
// $this->userid1 = create_user($user);
|
||||
// $user->username = 'mockuserfortestingXY';
|
||||
// $user->firstname = 'mockuserfortestingY_firstname';
|
||||
// $user->lastname = 'mockuserfortestingY_lastname';
|
||||
// $user->email = 'mockuserfortestingY@moodle.com';
|
||||
// $user->password = 'mockuserfortestingY_password';
|
||||
// $this->userid2 = create_user($user);
|
||||
//
|
||||
// //create some more test users (not add yet to any group)
|
||||
// $user = new stdClass();
|
||||
// $user->username = 'mockuserfortestingZ';
|
||||
// $user->firstname = 'mockuserfortestingZ_firstname';
|
||||
// $user->lastname = 'mockuserfortestingZ_lastname';
|
||||
// $user->email = 'mockuserfortestingZ@moodle.com';
|
||||
// $user->password = 'mockuserfortestingZ_password';
|
||||
// $this->userid3 = create_user($user);
|
||||
// $user = new stdClass();
|
||||
// $user->username = 'mockuserfortestingZ2';
|
||||
// $user->firstname = 'mockuserfortestingZ2_firstname';
|
||||
// $user->lastname = 'mockuserfortestingZ2_lastname';
|
||||
// $user->email = 'mockuserfortestingZ2@moodle.com';
|
||||
// $user->password = 'mockuserfortestingZ2_password';
|
||||
// $this->userid4 = create_user($user);
|
||||
|
||||
// //create a user, don't add it to a role or group
|
||||
// $user = new stdClass();
|
||||
// $user->username = 'mockuserfortestingZ23';
|
||||
// $user->firstname = 'mockuserfortestingZ23_firstname';
|
||||
// $user->lastname = 'mockuserfortestingZ23_lastname';
|
||||
// $user->email = 'mockuserfortestingZ23@moodle.com';
|
||||
// $user->password = 'mockuserfortestingZ23_password';
|
||||
// $this->userid5 = create_user($user);
|
||||
|
||||
// //we're creating a new test role with viewcourse capabilyt
|
||||
// $this->context = $DB->get_record('context',array('contextlevel' => 50, 'instanceid' => $this->course->id));
|
||||
// $this->roleid = create_role('testrole', 'testrole', 'testrole');
|
||||
// assign_capability('moodle/course:view', CAP_ALLOW, $this->roleid, $this->context->id);
|
||||
//
|
||||
// //assign the students to this role
|
||||
// role_assign($this->roleid, $this->userid1, null, $this->context->id);
|
||||
// role_assign($this->roleid, $this->userid2, null, $this->context->id);
|
||||
// role_assign($this->roleid, $this->userid3, null, $this->context->id);
|
||||
// role_assign($this->roleid, $this->userid4, null, $this->context->id);
|
||||
|
||||
/// create a group with these two students
|
||||
// $this->group = new stdClass();
|
||||
// $this->group->courseid = $this->course->id;
|
||||
// $this->group->name = "Unit Test group";
|
||||
// $this->group->id = groups_create_group( $this->group, false);
|
||||
//
|
||||
// /// create a group with one of these students
|
||||
// $this->group2 = new stdClass();
|
||||
// $this->group2->courseid = $this->course->id;
|
||||
// $this->group2->name = "Unit Test group 2";
|
||||
// $this->group2->id = groups_create_group( $this->group2, false);
|
||||
//
|
||||
//
|
||||
// //add the two students as member of the group
|
||||
// groups_add_member($this->group->id, $this->userid1);
|
||||
// groups_add_member($this->group->id, $this->userid2);
|
||||
// groups_add_member($this->group2->id, $this->userid1);
|
||||
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
global $DB;
|
||||
|
||||
/// delete the course
|
||||
delete_course($this->course, false);
|
||||
|
||||
/// delete the category
|
||||
$DB->delete_records('course_categories',array('id' => $this->categoryid));
|
||||
|
||||
// /// delete the two students
|
||||
// $user = $DB->get_record('user', array('username'=>'mockuserfortestingXX', 'mnethostid'=>1));
|
||||
// delete_user($user);
|
||||
// $user = $DB->get_record('user', array('username'=>'mockuserfortestingXY', 'mnethostid'=>1));
|
||||
// delete_user($user);
|
||||
//
|
||||
// /// delete other test users
|
||||
// $user = $DB->get_record('user', array('username'=>'mockuserfortestingZ', 'mnethostid'=>1));
|
||||
// delete_user($user);
|
||||
// $user = $DB->get_record('user', array('username'=>'mockuserfortestingZ2', 'mnethostid'=>1));
|
||||
// delete_user($user);
|
||||
|
||||
// //delete the user without group
|
||||
// $user = $DB->get_record('user', array('username'=>'mockuserfortestingZ23', 'mnethostid'=>1));
|
||||
// delete_user($user);
|
||||
|
||||
// //delete role
|
||||
// delete_role($this->roleid);
|
||||
}
|
||||
|
||||
function test_create_courses() {
|
||||
$params = array();
|
||||
/// create a course
|
||||
$course = array();
|
||||
$course['category'] = $this->categoryid;
|
||||
$course['summary'] = 'Test course for Course12';
|
||||
$course['format'] = 'weeks';
|
||||
$course['numsections'] = '10';
|
||||
$course['startdate'] = mktime();
|
||||
$course['name'] = "Test course for Group12";
|
||||
$course['fullname'] = "Test course for Group12";
|
||||
$course['shortname'] = "TestCourseForGroup12";
|
||||
$params[] = $course;
|
||||
$course = array();
|
||||
$course['category'] = $this->categoryid;
|
||||
$course['summary'] = 'Test course for Course02';
|
||||
$course['format'] = 'weeks';
|
||||
$course['numsections'] = '10';
|
||||
$course['startdate'] = mktime();
|
||||
$course['name'] = "Test course for Group02";
|
||||
$course['fullname'] = "Test course for Group02";
|
||||
$course['shortname'] = "TestCourseForGroup02";
|
||||
$params[] = $course;
|
||||
$courses = course_external::create_courses($params);
|
||||
$this->assertEqual(sizeof($courses), 2);
|
||||
$this->assertIsA($courses[key($courses)], "stdClass");
|
||||
$this->assertNotNull($courses[key($courses)]);
|
||||
|
||||
/// delete the course
|
||||
delete_course($courses[key($courses)], false);
|
||||
next($courses);
|
||||
delete_course($courses[key($courses)], false);
|
||||
|
||||
/// create a course with a not existing category id
|
||||
$params = array();
|
||||
$course['category'] = 4568468468;
|
||||
$course['summary'] = 'Test course for Course2';
|
||||
$course['format'] = 'weeks';
|
||||
$course['numsections'] = '10';
|
||||
$course['startdate'] = mktime();
|
||||
$course['name'] = "Test course for Group2";
|
||||
$course['fullname'] = "Test course for Group2";
|
||||
$course['shortname'] = "TestCourseForGroup2";
|
||||
$params[] = $course;
|
||||
$this->expectException(new moodle_exception('noexistingcategory'));
|
||||
$groupids = course_external::create_courses($params);
|
||||
|
||||
}
|
||||
|
||||
function test_create_courses2() {
|
||||
//shortname already exit
|
||||
$params = array();
|
||||
$course['category'] = $this->categoryid;
|
||||
$course['summary'] = 'Test course for Course2';
|
||||
$course['format'] = 'weeks';
|
||||
$course['numsections'] = '10';
|
||||
$course['startdate'] = mktime();
|
||||
$course['name'] = "Test course for Group2";
|
||||
$course['fullname'] = "Test course for Group2";
|
||||
$course['shortname'] = "TestCourseForCourse";
|
||||
$params[] = $course;
|
||||
$this->expectException(new moodle_exception('shortnametaken'));
|
||||
$groupids = course_external::create_courses($params);
|
||||
}
|
||||
|
||||
function test_create_courses3() {
|
||||
//3. idnumber already exist
|
||||
$params = array();
|
||||
$course['category'] = $this->categoryid;
|
||||
$course['summary'] = 'Test course for Course3';
|
||||
$course['format'] = 'weeks';
|
||||
$course['numsections'] = '10';
|
||||
$course['startdate'] = mktime();
|
||||
$course['name'] = "Test course for Group3";
|
||||
$course['fullname'] = "Test course for Group3";
|
||||
$course['shortname'] = "TestCourseForGroup3";
|
||||
$course['idnumber'] = 123456789;
|
||||
$params[] = $course;
|
||||
$this->expectException(new moodle_exception('idnumbertaken'));
|
||||
$groupids = course_external::create_courses($params);
|
||||
}
|
||||
|
||||
function test_get_courses() {
|
||||
//get by id, shortname and idnumber
|
||||
$params = array();
|
||||
$course = array();
|
||||
$course['id'] = $this->course->id;
|
||||
$params[] = $course;
|
||||
$course = array();
|
||||
$course['shortname'] = $this->course->shortname;
|
||||
$params[] = $course;
|
||||
$course = array();
|
||||
$course['idnumber'] = $this->course->idnumber;
|
||||
$params[] = $course;
|
||||
$courses = course_external::get_courses($params);
|
||||
$this->assertEqual(sizeof($courses), 3);
|
||||
$coursetotest = $courses[key($courses)];
|
||||
$this->assertEqual($coursetotest->id, $this->course->id);
|
||||
$this->assertEqual($coursetotest->idnumber, $this->course->idnumber);
|
||||
$this->assertEqual($coursetotest->shortname, $this->course->shortname);
|
||||
$this->assertEqual($coursetotest->summary, $this->course->summary);
|
||||
$this->assertEqual($coursetotest->format, $this->course->format);
|
||||
$this->assertEqual($coursetotest->fullname, $this->course->fullname);
|
||||
$this->assertEqual($coursetotest->numsections, $this->course->numsections);
|
||||
$this->assertEqual($coursetotest->startdate, $this->course->startdate);
|
||||
$this->assertEqual($coursetotest->category, $this->course->category);
|
||||
next($courses);
|
||||
$coursetotest = $courses[key($courses)];
|
||||
$this->assertEqual($coursetotest->id, $this->course->id);
|
||||
$this->assertEqual($coursetotest->idnumber, $this->course->idnumber);
|
||||
$this->assertEqual($coursetotest->shortname, $this->course->shortname);
|
||||
$this->assertEqual($coursetotest->summary, $this->course->summary);
|
||||
$this->assertEqual($coursetotest->format, $this->course->format);
|
||||
$this->assertEqual($coursetotest->fullname, $this->course->fullname);
|
||||
$this->assertEqual($coursetotest->numsections, $this->course->numsections);
|
||||
$this->assertEqual($coursetotest->startdate, $this->course->startdate);
|
||||
$this->assertEqual($coursetotest->category, $this->course->category);
|
||||
next($courses);
|
||||
$coursetotest = $courses[key($courses)];
|
||||
$this->assertEqual($coursetotest->id, $this->course->id);
|
||||
$this->assertEqual($coursetotest->idnumber, $this->course->idnumber);
|
||||
$this->assertEqual($coursetotest->shortname, $this->course->shortname);
|
||||
$this->assertEqual($coursetotest->summary, $this->course->summary);
|
||||
$this->assertEqual($coursetotest->format, $this->course->format);
|
||||
$this->assertEqual($coursetotest->fullname, $this->course->fullname);
|
||||
$this->assertEqual($coursetotest->numsections, $this->course->numsections);
|
||||
$this->assertEqual($coursetotest->startdate, $this->course->startdate);
|
||||
$this->assertEqual($coursetotest->category, $this->course->category);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function test_delete_courses() {
|
||||
$params = array();
|
||||
/// create a course
|
||||
$course->category = $this->categoryid;
|
||||
$course->summary = 'Test course for Course 2 delete';
|
||||
$course->format = 'weeks';
|
||||
$course->numsections = '10';
|
||||
$course->startdate = mktime();
|
||||
$course->name = "Test course for Course 2 delete";
|
||||
$course->fullname = "Test course for Course 2 delete";
|
||||
$course->shortname = "TestCourseForCourse 2 delete";
|
||||
$course->idnumber = 0123456789;
|
||||
$course = create_course($course);
|
||||
$params[] = (array) $course;
|
||||
$result = course_external::delete_courses($params);
|
||||
$this->assertEqual($result, true);
|
||||
}
|
||||
|
||||
function test_update_courses() {
|
||||
$params = array();
|
||||
$course['id'] = $this->course->id;
|
||||
$course['category'] = $this->categoryid;
|
||||
$course['summary'] = 'Test course for Course 2 update';
|
||||
$course['format'] = 'weeks';
|
||||
$course['numsections'] = '10';
|
||||
$course['startdate'] = mktime();
|
||||
$course['fullname'] = "Test course for Course 2 update";
|
||||
$course['shortname'] = "TestCourseForCourse2update";
|
||||
$course['idnumber'] = 8005007;
|
||||
$params[] = $course;
|
||||
$result = course_external::update_courses($params);
|
||||
$this->assertEqual($result, true);
|
||||
$dbcourse = get_course_by_id($course['id']);
|
||||
$this->assertEqual($dbcourse->idnumber, $course['idnumber']);
|
||||
$this->assertEqual($dbcourse->shortname, $course['shortname']);
|
||||
$this->assertEqual($dbcourse->summary, $course['summary']);
|
||||
$this->assertEqual($dbcourse->format, $course['format']);
|
||||
$this->assertEqual($dbcourse->fullname, $course['fullname']);
|
||||
$this->assertEqual($dbcourse->numsections, $course['numsections']);
|
||||
$this->assertEqual($dbcourse->startdate, $course['startdate']);
|
||||
$this->assertEqual($dbcourse->category, $course['category']);
|
||||
|
||||
//if id doesn't exist catch exception
|
||||
$params = array();
|
||||
$course['id'] = 6546544;
|
||||
$course['category'] = $this->categoryid;
|
||||
$course['summary'] = 'Test course for Course 2 update';
|
||||
$course['format'] = 'weeks';
|
||||
$course['numsections'] = '10';
|
||||
$course['startdate'] = mktime();
|
||||
$course['fullname'] = "Test course for Course 2 update";
|
||||
$course['shortname'] = "TestCourseForCourse2update";
|
||||
$course['idnumber'] = 8005007;
|
||||
$params[] = $course;
|
||||
$this->expectException(new moodle_exception('courseidnotfound'));
|
||||
$result = course_external::update_courses($params);
|
||||
|
||||
}
|
||||
|
||||
function test_get_course_activities() {
|
||||
}
|
||||
|
||||
function test_get_course_resources() {
|
||||
}
|
||||
*/
|
||||
}
|
||||
?>
|
@ -163,9 +163,11 @@ $string['commentmisconf'] = 'Comment ID is misconfigured';
|
||||
$string['componentisuptodate'] = 'Component is up-to-date';
|
||||
$string['confirmsesskeybad'] = 'Sorry, but your session key could not be confirmed to carry out this action. This security feature prevents against accidental or malicious execution of important functions in your name. Please make sure you really wanted to execute this function.';
|
||||
$string['couldnotassignrole'] = 'A serious but unspecified error occurred while trying to assign a role to you';
|
||||
$string['couldnotupdatenoexistinguser'] = 'Cannot update the user - user doesn\'t exist';
|
||||
$string['countriesphpempty'] = 'Error: The file countries.php in language pack $a is empty or missing.';
|
||||
$string['coursedoesntexistcannotcreategroup'] = 'Cannot create group: the course doesn\'t exist';
|
||||
$string['coursegroupunknown'] = 'Course corresponding to group $a not specified';
|
||||
$string['courseidnotfound'] = 'Course id doesn\'t exist';
|
||||
$string['coursemisconf'] = 'Course is misconfigured';
|
||||
$string['courserequestdisabled'] = 'Sorry, but requesting courses has been disabled by the administrator';
|
||||
$string['csvemptyfile'] = 'The CSV file is empty';
|
||||
@ -237,6 +239,7 @@ $string['guestnoeditprofileother'] = 'The guest user profile cannot be edited';
|
||||
$string['guestnorate'] = 'Guests are not allowed to rate entries';
|
||||
$string['guestsarenotallowed'] = 'The guest user is not allowed to do this';
|
||||
$string['hashpoolproblem'] = 'Incorrect pool file content $a.';
|
||||
$string['idnumbertaken'] = 'ID number is already used for another course';
|
||||
$string['incorrectext'] = 'File has an incorrect extension';
|
||||
$string['invalidaction'] = 'Invalid action parameter';
|
||||
$string['invalidactivityid'] = 'Invalid Activity ID';
|
||||
@ -342,6 +345,7 @@ $string['noinstances'] = 'There are no instances of $a in this course!';
|
||||
$string['noguest'] = 'No guests here!';
|
||||
$string['nologinas'] = 'You are not allowed to login as that user';
|
||||
$string['noadmins'] = 'No administrators!';
|
||||
$string['noexistingcategory'] = 'No existing category';
|
||||
$string['notlocalisederrormessage'] = '$a';
|
||||
$string['nousers'] = 'No such user!';
|
||||
$string['nonmeaningfulcontent'] = 'Non meaningful content';
|
||||
@ -400,6 +404,7 @@ $string['sessionerroruser2'] = 'A server error that affects your login session w
|
||||
$string['sessionipnomatch'] = 'Sorry, but your IP number seems to have changed from when you first logged in. This security feature prevents crackers stealing your identity while logged in to this site. Normal users should not be seeing this message - please ask the site administrator for help.';
|
||||
$string['sessionipnomatch2'] = 'Sorry, but your IP number seems to have changed from when you first logged in. This security feature prevents crackers stealing your identity while logged in to this site. You may see this error if you use wireless networks or if you are roaming between different networks. Please ask the site administrator for more help.<br /><br />If you want to continue please press F5 key to refresh this page.';
|
||||
$string['sessionnotwritable'] = 'Write permission problem detected in session directory.<br /><br />Please notify server administrator.';
|
||||
$string['shortnametaken'] = 'Short name is already used for another course';
|
||||
$string['socksnotsupported'] = 'SOCKS5 proxy is not supported in PHP4';
|
||||
$string['spellcheckernotconf'] = 'Spellchecker not configured';
|
||||
$string['sslonlyaccess'] = 'For security reasons only https connections are allowed, sorry.';
|
||||
@ -478,6 +483,7 @@ $string['wrongroleid'] = 'Incorrect role ID!';
|
||||
$string['wrongsourcebase'] = 'Wrong source URL base';
|
||||
$string['wrongzipfilename'] = 'Wrong ZIP file name';
|
||||
$string['wscouldnotaddgroupmembernopermission'] = 'WS - Could not add group member - No permission';
|
||||
$string['wscouldnotcreateecoursenopermission'] = 'WS - Could not create course - No permission';
|
||||
$string['wscouldnotcreategroupnopermission'] = 'WS - Could not create group - No permission';
|
||||
$string['wscouldnotcreateeuserindb'] = 'WS - Could not create a user';
|
||||
$string['wscouldnotcreateeusernopermission'] = 'WS - Could not create a user - No permission';
|
||||
|
Loading…
x
Reference in New Issue
Block a user