本文整理汇总了PHP中external_api类的典型用法代码示例。如果您正苦于以下问题:PHP external_api类的具体用法?PHP external_api怎么用?PHP external_api使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了external_api类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: test_get_site_info
public function test_get_site_info() {
global $DB, $USER, $CFG;
$this->resetAfterTest(true);
// This is the info we are going to check
set_config('release', '2.4dev (Build: 20120823)');
set_config('version', '2012083100.00');
// Set current user
$user = array();
$user['username'] = 'johnd';
$user['firstname'] = 'John';
$user['lastname'] = 'Doe';
self::setUser(self::getDataGenerator()->create_user($user));
// Add a web service and token.
$webservice = new stdClass();
$webservice->name = 'Test web service';
$webservice->enabled = true;
$webservice->restrictedusers = false;
$webservice->component = 'moodle';
$webservice->timecreated = time();
$webservice->downloadfiles = true;
$externalserviceid = $DB->insert_record('external_services', $webservice);
// Add a function to the service
$DB->insert_record('external_services_functions', array('externalserviceid' => $externalserviceid,
'functionname' => 'core_course_get_contents'));
$_POST['wstoken'] = 'testtoken';
$externaltoken = new stdClass();
$externaltoken->token = 'testtoken';
$externaltoken->tokentype = 0;
$externaltoken->userid = $USER->id;
$externaltoken->externalserviceid = $externalserviceid;
$externaltoken->contextid = 1;
$externaltoken->creatorid = $USER->id;
$externaltoken->timecreated = time();
$DB->insert_record('external_tokens', $externaltoken);
$siteinfo = core_webservice_external::get_site_info();
// We need to execute the return values cleaning process to simulate the web service server.
$siteinfo = external_api::clean_returnvalue(core_webservice_external::get_site_info_returns(), $siteinfo);
$this->assertEquals('johnd', $siteinfo['username']);
$this->assertEquals('John', $siteinfo['firstname']);
$this->assertEquals('Doe', $siteinfo['lastname']);
$this->assertEquals(current_language(), $siteinfo['lang']);
$this->assertEquals($USER->id, $siteinfo['userid']);
$this->assertEquals(true, $siteinfo['downloadfiles']);
$this->assertEquals($CFG->release, $siteinfo['release']);
$this->assertEquals($CFG->version, $siteinfo['version']);
$this->assertEquals($CFG->mobilecssurl, $siteinfo['mobilecssurl']);
$this->assertEquals(count($siteinfo['functions']), 1);
$function = array_pop($siteinfo['functions']);
$this->assertEquals($function['name'], 'core_course_get_contents');
$this->assertEquals($function['version'], $siteinfo['version']);
}
开发者ID:verbazend,项目名称:AWFA,代码行数:60,代码来源:externallib_test.php
示例2: test_get_glossaries_by_courses
/**
* Test get_glossaries_by_courses
*/
public function test_get_glossaries_by_courses()
{
$this->resetAfterTest(true);
// As admin.
$this->setAdminUser();
$c1 = self::getDataGenerator()->create_course();
$c2 = self::getDataGenerator()->create_course();
$g1 = self::getDataGenerator()->create_module('glossary', array('course' => $c1->id, 'name' => 'First Glossary'));
$g2 = self::getDataGenerator()->create_module('glossary', array('course' => $c1->id, 'name' => 'Second Glossary'));
$g3 = self::getDataGenerator()->create_module('glossary', array('course' => $c2->id, 'name' => 'Third Glossary'));
$s1 = $this->getDataGenerator()->create_user();
self::getDataGenerator()->enrol_user($s1->id, $c1->id);
// Check results where student is enrolled.
$this->setUser($s1);
$glossaries = mod_glossary_external::get_glossaries_by_courses(array());
$glossaries = external_api::clean_returnvalue(mod_glossary_external::get_glossaries_by_courses_returns(), $glossaries);
$this->assertCount(2, $glossaries['glossaries']);
$this->assertEquals('First Glossary', $glossaries['glossaries'][0]['name']);
$this->assertEquals('Second Glossary', $glossaries['glossaries'][1]['name']);
// Check results with specific course IDs.
$glossaries = mod_glossary_external::get_glossaries_by_courses(array($c1->id, $c2->id));
$glossaries = external_api::clean_returnvalue(mod_glossary_external::get_glossaries_by_courses_returns(), $glossaries);
$this->assertCount(2, $glossaries['glossaries']);
$this->assertEquals('First Glossary', $glossaries['glossaries'][0]['name']);
$this->assertEquals('Second Glossary', $glossaries['glossaries'][1]['name']);
$this->assertEquals('course', $glossaries['warnings'][0]['item']);
$this->assertEquals($c2->id, $glossaries['warnings'][0]['itemid']);
$this->assertEquals('1', $glossaries['warnings'][0]['warningcode']);
// Now as admin.
$this->setAdminUser();
$glossaries = mod_glossary_external::get_glossaries_by_courses(array($c2->id));
$glossaries = external_api::clean_returnvalue(mod_glossary_external::get_glossaries_by_courses_returns(), $glossaries);
$this->assertCount(1, $glossaries['glossaries']);
$this->assertEquals('Third Glossary', $glossaries['glossaries'][0]['name']);
}
开发者ID:GaganJotSingh,项目名称:moodle,代码行数:38,代码来源:external_test.php
示例3: test_get_plugins_supporting_mobile
/**
* Test get_plugins_supporting_mobile.
* This is a very basic test because currently there aren't plugins supporting Mobile in core.
*/
public function test_get_plugins_supporting_mobile()
{
$result = external::get_plugins_supporting_mobile();
$result = external_api::clean_returnvalue(external::get_plugins_supporting_mobile_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(0, $result['plugins']);
}
开发者ID:IFPBMoodle,项目名称:moodle,代码行数:11,代码来源:externallib_test.php
示例4: test_confirm_user
/**
* Test confirm_user
*/
public function test_confirm_user()
{
global $DB;
$username = 'pepe';
$password = 'abcdefAª.ªª!!3';
$firstname = 'Pepe';
$lastname = 'Pérez';
$email = '[email protected]';
// Create new user.
$result = auth_email_external::signup_user($username, $password, $firstname, $lastname, $email);
$result = external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$this->assertTrue($result['success']);
$this->assertEmpty($result['warnings']);
$secret = $DB->get_field('user', 'secret', array('username' => $username));
// Confirm the user.
$result = core_auth_external::confirm_user($username, $secret);
$result = external_api::clean_returnvalue(core_auth_external::confirm_user_returns(), $result);
$this->assertTrue($result['success']);
$this->assertEmpty($result['warnings']);
$confirmed = $DB->get_field('user', 'confirmed', array('username' => $username));
$this->assertEquals(1, $confirmed);
// Try to confirm the user again.
$result = core_auth_external::confirm_user($username, $secret);
$result = external_api::clean_returnvalue(core_auth_external::confirm_user_returns(), $result);
$this->assertFalse($result['success']);
$this->assertCount(1, $result['warnings']);
$this->assertEquals('alreadyconfirmed', $result['warnings'][0]['warningcode']);
// Try to use an invalid secret.
$this->expectException('moodle_exception');
$this->expectExceptionMessage(get_string('invalidconfirmdata', 'error'));
$result = core_auth_external::confirm_user($username, 'zzZZzz');
}
开发者ID:janeklb,项目名称:moodle,代码行数:35,代码来源:external_test.php
示例5: tool_usertours_inplace_editable
/**
* Manage inplace editable saves.
*
* @param string $itemtype The type of item.
* @param int $itemid The ID of the item.
* @param mixed $newvalue The new value
* @return string
*/
function tool_usertours_inplace_editable($itemtype, $itemid, $newvalue)
{
$context = \context_system::instance();
external_api::validate_context($context);
require_capability('tool/usertours:managetours', $context);
if ($itemtype === 'tourname') {
$tour = helper::get_tour($itemid);
$tour->set_name($newvalue)->persist();
return helper::render_tourname_inplace_editable($tour);
} else {
if ($itemtype === 'tourdescription') {
$tour = helper::get_tour($itemid);
$tour->set_description($newvalue)->persist();
return helper::render_tourdescription_inplace_editable($tour);
} else {
if ($itemtype === 'tourenabled') {
$tour = helper::get_tour($itemid);
$tour->set_enabled(!!$newvalue)->persist();
return helper::render_tourenabled_inplace_editable($tour);
} else {
if ($itemtype === 'stepname') {
$step = helper::get_step($itemid);
$step->set_title($newvalue)->persist();
return helper::render_stepname_inplace_editable($step);
}
}
}
}
}
开发者ID:dg711,项目名称:moodle,代码行数:37,代码来源:lib.php
示例6: send_response
/**
* Send the result of function call to the WS client
* formatted as XML document.
*/
protected function send_response()
{
//Check that the returned values are valid
try {
if ($this->function->returns_desc != null) {
$validatedvalues = external_api::clean_returnvalue($this->function->returns_desc, $this->returns);
} else {
$validatedvalues = null;
}
} catch (Exception $ex) {
$exception = $ex;
}
if (!empty($exception)) {
$response = $this->generate_error($exception);
} else {
//We can now convert the response to the requested REST format
if ($this->restformat == 'json') {
$response = json_encode($validatedvalues);
} else {
$response = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
$response .= '<RESPONSE>' . "\n";
$response .= self::xmlize_result($this->returns, $this->function->returns_desc);
$response .= '</RESPONSE>' . "\n";
}
}
$this->send_headers();
echo $response;
}
开发者ID:LMSeXT,项目名称:SAWEE-WS_server-engine,代码行数:32,代码来源:locallib.php
示例7: test_update_activity_completion_status_manually
/**
* Test update_activity_completion_status_manually
*/
public function test_update_activity_completion_status_manually()
{
global $DB, $CFG;
$this->resetAfterTest(true);
$CFG->enablecompletion = true;
$user = $this->getDataGenerator()->create_user();
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
$data = $this->getDataGenerator()->create_module('data', array('course' => $course->id), array('completion' => 1));
$cm = get_coursemodule_from_id('data', $data->cmid);
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id);
$this->setUser($user);
$result = core_completion_external::update_activity_completion_status_manually($data->cmid, true);
// We need to execute the return values cleaning process to simulate the web service server.
$result = external_api::clean_returnvalue(core_completion_external::update_activity_completion_status_manually_returns(), $result);
// Check in DB.
$this->assertEquals(1, $DB->get_field('course_modules_completion', 'completionstate', array('coursemoduleid' => $data->cmid)));
// Check using the API.
$completion = new completion_info($course);
$completiondata = $completion->get_data($cm);
$this->assertEquals(1, $completiondata->completionstate);
$this->assertTrue($result['status']);
$result = core_completion_external::update_activity_completion_status_manually($data->cmid, false);
// We need to execute the return values cleaning process to simulate the web service server.
$result = external_api::clean_returnvalue(core_completion_external::update_activity_completion_status_manually_returns(), $result);
$this->assertEquals(0, $DB->get_field('course_modules_completion', 'completionstate', array('coursemoduleid' => $data->cmid)));
$completiondata = $completion->get_data($cm);
$this->assertEquals(0, $completiondata->completionstate);
$this->assertTrue($result['status']);
}
开发者ID:Hirenvaghasiya,项目名称:moodle,代码行数:33,代码来源:externallib_test.php
示例8: test_validate_params
public function test_validate_params()
{
$params = array('text' => 'aaa', 'someid' => '6');
$description = new external_function_parameters(array('someid' => new external_value(PARAM_INT, 'Some int value'), 'text' => new external_value(PARAM_ALPHA, 'Some text value')));
$result = external_api::validate_parameters($description, $params);
$this->assertEqual(count($result), 2);
reset($result);
$this->assertTrue(key($result) === 'someid');
$this->assertTrue($result['someid'] === 6);
$this->assertTrue($result['text'] === 'aaa');
$params = array('someids' => array('1', 2, 'a' => '3'), 'scalar' => 666);
$description = new external_function_parameters(array('someids' => new external_multiple_structure(new external_value(PARAM_INT, 'Some ID')), 'scalar' => new external_value(PARAM_ALPHANUM, 'Some text value')));
$result = external_api::validate_parameters($description, $params);
$this->assertEqual(count($result), 2);
reset($result);
$this->assertTrue(key($result) === 'someids');
$this->assertTrue($result['someids'] == array(0 => 1, 1 => 2, 2 => 3));
$this->assertTrue($result['scalar'] === '666');
$params = array('text' => 'aaa');
$description = new external_function_parameters(array('someid' => new external_value(PARAM_INT, 'Some int value', false), 'text' => new external_value(PARAM_ALPHA, 'Some text value')));
$result = external_api::validate_parameters($description, $params);
$this->assertEqual(count($result), 2);
reset($result);
$this->assertTrue(key($result) === 'someid');
$this->assertTrue($result['someid'] === null);
$this->assertTrue($result['text'] === 'aaa');
$params = array('text' => 'aaa');
$description = new external_function_parameters(array('someid' => new external_value(PARAM_INT, 'Some int value', false, 6), 'text' => new external_value(PARAM_ALPHA, 'Some text value')));
$result = external_api::validate_parameters($description, $params);
$this->assertEqual(count($result), 2);
reset($result);
$this->assertTrue(key($result) === 'someid');
$this->assertTrue($result['someid'] === 6);
$this->assertTrue($result['text'] === 'aaa');
}
开发者ID:robadobdob,项目名称:moodle,代码行数:35,代码来源:testexternallib.php
示例9: core_tag_inplace_editable
/**
* Implements callback inplace_editable() allowing to edit values in-place
*
* @param string $itemtype
* @param int $itemid
* @param mixed $newvalue
* @return \core\output\inplace_editable
*/
function core_tag_inplace_editable($itemtype, $itemid, $newvalue)
{
\external_api::validate_context(context_system::instance());
if ($itemtype === 'tagname') {
return \core_tag\output\tagname::update($itemid, $newvalue);
} else {
if ($itemtype === 'tagareaenable') {
return \core_tag\output\tagareaenabled::update($itemid, $newvalue);
} else {
if ($itemtype === 'tagareacollection') {
return \core_tag\output\tagareacollection::update($itemid, $newvalue);
} else {
if ($itemtype === 'tagareashowstandard') {
return \core_tag\output\tagareashowstandard::update($itemid, $newvalue);
} else {
if ($itemtype === 'tagcollname') {
return \core_tag\output\tagcollname::update($itemid, $newvalue);
} else {
if ($itemtype === 'tagcollsearchable') {
return \core_tag\output\tagcollsearchable::update($itemid, $newvalue);
} else {
if ($itemtype === 'tagflag') {
return \core_tag\output\tagflag::update($itemid, $newvalue);
} else {
if ($itemtype === 'tagisstandard') {
return \core_tag\output\tagisstandard::update($itemid, $newvalue);
}
}
}
}
}
}
}
}
}
开发者ID:evltuma,项目名称:moodle,代码行数:43,代码来源:lib.php
示例10: test_view_folder
/**
* Test view_folder
*/
public function test_view_folder()
{
global $DB;
$this->resetAfterTest(true);
$this->setAdminUser();
// Setup test data.
$course = $this->getDataGenerator()->create_course();
$folder = $this->getDataGenerator()->create_module('folder', array('course' => $course->id));
$context = context_module::instance($folder->cmid);
$cm = get_coursemodule_from_instance('folder', $folder->id);
// Test invalid instance id.
try {
mod_folder_external::view_folder(0);
$this->fail('Exception expected due to invalid mod_folder instance id.');
} catch (moodle_exception $e) {
$this->assertEquals('invalidrecord', $e->errorcode);
}
// Test not-enrolled user.
$user = self::getDataGenerator()->create_user();
$this->setUser($user);
try {
mod_folder_external::view_folder($folder->id);
$this->fail('Exception expected due to not enrolled user.');
} catch (moodle_exception $e) {
$this->assertEquals('requireloginerror', $e->errorcode);
}
// Test user with full capabilities.
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id);
// Trigger and capture the event.
$sink = $this->redirectEvents();
$result = mod_folder_external::view_folder($folder->id);
$result = external_api::clean_returnvalue(mod_folder_external::view_folder_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = array_shift($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\\mod_folder\\event\\course_module_viewed', $event);
$this->assertEquals($context, $event->get_context());
$moodlefolder = new \moodle_url('/mod/folder/view.php', array('id' => $cm->id));
$this->assertEquals($moodlefolder, $event->get_url());
$this->assertEventContextNotUsed($event);
$this->assertNotEmpty($event->get_name());
// Test user with no capabilities.
// We need a explicit prohibit since this capability is only defined in authenticated user and guest roles.
assign_capability('mod/folder:view', CAP_PROHIBIT, $studentrole->id, $context->id);
// Empty all the caches that may be affected by this change.
accesslib_clear_all_caches_for_unit_testing();
course_modinfo::clear_instance_cache();
try {
mod_folder_external::view_folder($folder->id);
$this->fail('Exception expected due to missing capability.');
} catch (moodle_exception $e) {
$this->assertEquals('requireloginerror', $e->errorcode);
}
}
开发者ID:evltuma,项目名称:moodle,代码行数:59,代码来源:externallib_test.php
示例11: update
/**
* Updates cohort name and returns instance of this object
*
* @param int $cohortid
* @param string $newvalue
* @return static
*/
public static function update($cohortid, $newvalue)
{
global $DB;
$cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
$cohortcontext = \context::instance_by_id($cohort->contextid);
\external_api::validate_context($cohortcontext);
require_capability('moodle/cohort:manage', $cohortcontext);
$record = (object) array('id' => $cohort->id, 'idnumber' => $newvalue, 'contextid' => $cohort->contextid);
cohort_update_cohort($record);
$cohort->idnumber = $newvalue;
return new static($cohort);
}
开发者ID:evltuma,项目名称:moodle,代码行数:19,代码来源:cohortidnumber.php
示例12: test_get_instance_info
/**
* Test get_instance_info
*/
public function test_get_instance_info()
{
global $DB;
$this->resetAfterTest(true);
// Check if self enrolment plugin is enabled.
$selfplugin = enrol_get_plugin('self');
$this->assertNotEmpty($selfplugin);
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->assertNotEmpty($studentrole);
$coursedata = new stdClass();
$coursedata->visible = 0;
$course = self::getDataGenerator()->create_course($coursedata);
// Add enrolment methods for course.
$instanceid1 = $selfplugin->add_instance($course, array('status' => ENROL_INSTANCE_ENABLED, 'name' => 'Test instance 1', 'customint6' => 1, 'roleid' => $studentrole->id));
$instanceid2 = $selfplugin->add_instance($course, array('status' => ENROL_INSTANCE_DISABLED, 'customint6' => 1, 'name' => 'Test instance 2', 'roleid' => $studentrole->id));
$instanceid3 = $selfplugin->add_instance($course, array('status' => ENROL_INSTANCE_ENABLED, 'roleid' => $studentrole->id, 'customint6' => 1, 'name' => 'Test instance 3', 'password' => 'test'));
$enrolmentmethods = $DB->get_records('enrol', array('courseid' => $course->id, 'status' => ENROL_INSTANCE_ENABLED));
$this->assertCount(3, $enrolmentmethods);
$this->setAdminUser();
$instanceinfo1 = enrol_self_external::get_instance_info($instanceid1);
$instanceinfo1 = external_api::clean_returnvalue(enrol_self_external::get_instance_info_returns(), $instanceinfo1);
$this->assertEquals($instanceid1, $instanceinfo1['id']);
$this->assertEquals($course->id, $instanceinfo1['courseid']);
$this->assertEquals('self', $instanceinfo1['type']);
$this->assertEquals('Test instance 1', $instanceinfo1['name']);
$this->assertTrue($instanceinfo1['status']);
$this->assertFalse(isset($instanceinfo1['enrolpassword']));
$instanceinfo2 = enrol_self_external::get_instance_info($instanceid2);
$instanceinfo2 = external_api::clean_returnvalue(enrol_self_external::get_instance_info_returns(), $instanceinfo2);
$this->assertEquals($instanceid2, $instanceinfo2['id']);
$this->assertEquals($course->id, $instanceinfo2['courseid']);
$this->assertEquals('self', $instanceinfo2['type']);
$this->assertEquals('Test instance 2', $instanceinfo2['name']);
$this->assertEquals(get_string('canntenrol', 'enrol_self'), $instanceinfo2['status']);
$this->assertFalse(isset($instanceinfo2['enrolpassword']));
$instanceinfo3 = enrol_self_external::get_instance_info($instanceid3);
$instanceinfo3 = external_api::clean_returnvalue(enrol_self_external::get_instance_info_returns(), $instanceinfo3);
$this->assertEquals($instanceid3, $instanceinfo3['id']);
$this->assertEquals($course->id, $instanceinfo3['courseid']);
$this->assertEquals('self', $instanceinfo3['type']);
$this->assertEquals('Test instance 3', $instanceinfo3['name']);
$this->assertTrue($instanceinfo3['status']);
$this->assertEquals(get_string('password', 'enrol_self'), $instanceinfo3['enrolpassword']);
// Try to retrieve information using a normal user for a hidden course.
$user = self::getDataGenerator()->create_user();
$this->setUser($user);
try {
enrol_self_external::get_instance_info($instanceid3);
} catch (moodle_exception $e) {
$this->assertEquals('coursehidden', $e->errorcode);
}
}
开发者ID:parksandwildlife,项目名称:learning,代码行数:55,代码来源:externallib_test.php
示例13: update
/**
* Updates course module name
*
* @param int $itemid course module id
* @param string $newvalue new name
* @return static
*/
public static function update($itemid, $newvalue)
{
$context = context_module::instance($itemid);
// Check access.
\external_api::validate_context($context);
require_capability('moodle/course:manageactivities', $context);
// Update value.
set_coursemodule_name($itemid, $newvalue);
$coursemodulerecord = get_coursemodule_from_id('', $itemid, 0, false, MUST_EXIST);
// Return instance.
$cm = get_fast_modinfo($coursemodulerecord->course)->get_cm($itemid);
return new static($cm, true);
}
开发者ID:evltuma,项目名称:moodle,代码行数:20,代码来源:course_module_name.php
示例14: update
/**
* Updates cohort name and returns instance of this object
*
* @param int $cohortid
* @param string $newvalue
* @return static
*/
public static function update($cohortid, $newvalue)
{
global $DB;
$cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
$cohortcontext = \context::instance_by_id($cohort->contextid);
\external_api::validate_context($cohortcontext);
require_capability('moodle/cohort:manage', $cohortcontext);
$newvalue = clean_param($newvalue, PARAM_TEXT);
if (strval($newvalue) !== '') {
$record = (object) array('id' => $cohort->id, 'name' => $newvalue, 'contextid' => $cohort->contextid);
cohort_update_cohort($record);
$cohort->name = $newvalue;
}
return new static($cohort);
}
开发者ID:evltuma,项目名称:moodle,代码行数:22,代码来源:cohortname.php
示例15: test_view_scorm
/**
* Test view_scorm
*/
public function test_view_scorm()
{
global $DB;
$this->resetAfterTest(true);
$this->setAdminUser();
// Setup test data.
$course = $this->getDataGenerator()->create_course();
$scorm = $this->getDataGenerator()->create_module('scorm', array('course' => $course->id));
$context = context_module::instance($scorm->cmid);
$cm = get_coursemodule_from_instance('scorm', $scorm->id);
// Test invalid instance id.
try {
mod_scorm_external::view_scorm(0);
$this->fail('Exception expected due to invalid mod_scorm instance id.');
} catch (moodle_exception $e) {
$this->assertEquals('invalidrecord', $e->errorcode);
}
// Test not-enrolled user.
$user = self::getDataGenerator()->create_user();
$this->setUser($user);
try {
mod_scorm_external::view_scorm($scorm->id);
$this->fail('Exception expected due to not enrolled user.');
} catch (moodle_exception $e) {
$this->assertEquals('requireloginerror', $e->errorcode);
}
// Test user with full capabilities.
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id);
// Trigger and capture the event.
$sink = $this->redirectEvents();
$result = mod_scorm_external::view_scorm($scorm->id);
$result = external_api::clean_returnvalue(mod_scorm_external::view_scorm_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = array_shift($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\\mod_scorm\\event\\course_module_viewed', $event);
$this->assertEquals($context, $event->get_context());
$moodleurl = new \moodle_url('/mod/scorm/view.php', array('id' => $cm->id));
$this->assertEquals($moodleurl, $event->get_url());
$this->assertEventContextNotUsed($event);
$this->assertNotEmpty($event->get_name());
}
开发者ID:mongo0se,项目名称:moodle,代码行数:47,代码来源:externallib_test.php
示例16: test_create_notes
/**
* Test create_notes
*/
public function test_create_notes() {
global $DB, $USER, $DB;
$this->resetAfterTest(true);
$course = self::getDataGenerator()->create_course();
// Set the required capabilities by the external function
$contextid = context_course::instance($course->id)->id;
$roleid = $this->assignUserCapability('moodle/notes:manage', $contextid);
$this->assignUserCapability('moodle/course:view', $contextid, $roleid);
// Create test note data.
$note1 = array();
$note1['userid'] = $USER->id;
$note1['publishstate'] = 'personal';
$note1['courseid'] = $course->id;
$note1['text'] = 'the text';
$note1['clientnoteid'] = 4;
$notes = array($note1);
$creatednotes = core_notes_external::create_notes($notes);
// We need to execute the return values cleaning process to simulate the web service server.
$creatednotes = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes);
$thenote = $DB->get_record('post', array('id' => $creatednotes[0]['noteid']));
// Confirm that base note data was inserted correctly.
$this->assertEquals($thenote->userid, $note1['userid']);
$this->assertEquals($thenote->courseid, $note1['courseid']);
$this->assertEquals($thenote->publishstate, NOTES_STATE_DRAFT);
$this->assertEquals($thenote->content, $note1['text']);
$this->assertEquals($creatednotes[0]['clientnoteid'], $note1['clientnoteid']);
// Call without required capability
$this->unassignUserCapability('moodle/notes:manage', $contextid, $roleid);
$this->setExpectedException('required_capability_exception');
$creatednotes = core_notes_external::create_notes($notes);
}
开发者ID:Burick,项目名称:moodle,代码行数:45,代码来源:externallib_test.php
示例17: test_get_site_public_settings
public function test_get_site_public_settings()
{
global $CFG, $SITE;
$this->resetAfterTest(true);
$result = external::get_site_public_settings();
$result = external_api::clean_returnvalue(external::get_site_public_settings_returns(), $result);
// Test default values.
$context = context_system::instance();
$expected = array('wwwroot' => $CFG->wwwroot, 'httpswwwroot' => $CFG->httpswwwroot, 'sitename' => external_format_string($SITE->fullname, $context->id, true), 'guestlogin' => $CFG->guestloginbutton, 'rememberusername' => $CFG->rememberusername, 'authloginviaemail' => $CFG->authloginviaemail, 'registerauth' => $CFG->registerauth, 'forgottenpasswordurl' => $CFG->forgottenpasswordurl, 'authinstructions' => format_text($CFG->auth_instructions), 'authnoneenabled' => (int) is_enabled_auth('none'), 'enablewebservices' => $CFG->enablewebservices, 'enablemobilewebservice' => $CFG->enablemobilewebservice, 'maintenanceenabled' => $CFG->maintenance_enabled, 'maintenancemessage' => format_text($CFG->maintenance_message), 'warnings' => array());
$this->assertEquals($expected, $result);
// Change a value.
set_config('registerauth', 'email');
$authinstructions = 'Something with <b>html tags</b>';
set_config('auth_instructions', $authinstructions);
$expected['registerauth'] = 'email';
$expected['authinstructions'] = format_text($authinstructions);
$result = external::get_site_public_settings();
$result = external_api::clean_returnvalue(external::get_site_public_settings_returns(), $result);
$this->assertEquals($expected, $result);
}
开发者ID:evltuma,项目名称:moodle,代码行数:20,代码来源:externallib_test.php
示例18: urlencode
$testclient = new $testclientclass();
$serverurl = "{$CFG->wwwroot}/webservice/{$protocol}/";
if ($authmethod == 'simple') {
$serverurl .= 'simpleserver.php';
$serverurl .= '?wsusername=' . urlencode($data->wsusername);
$serverurl .= '&wspassword=' . urlencode($data->wspassword);
} else {
if ($authmethod == 'token') {
$serverurl .= 'server.php';
$serverurl .= '?wstoken=' . urlencode($data->token);
}
}
// now get the function parameters
$params = $mform->get_params();
// now test the parameters, this also fixes PHP data types
$params = external_api::validate_parameters($functioninfo->parameters_desc, $params);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('pluginname', 'webservice_' . $protocol) . ': ' . $function);
echo 'URL: ' . s($serverurl);
echo $OUTPUT->box_start();
try {
$response = $testclient->simpletest($serverurl, $function, $params);
echo str_replace("\n", '<br />', s(var_export($response, true)));
} catch (Exception $ex) {
//TODO: handle exceptions and faults without exposing of the sensitive information such as debug traces!
echo str_replace("\n", '<br />', s($ex));
}
echo $OUTPUT->box_end();
$mform->display();
echo $OUTPUT->footer();
die;
开发者ID:evltuma,项目名称:moodle,代码行数:31,代码来源:testclient.php
示例19: test_mod_anonforum_get_anonforum_discussions
//.........这里部分代码省略.........
$record = new stdClass();
$record->course = $course1->id;
$record->userid = $user1->id;
$record->anonforum = $anonforum1->id;
$discussion1 = self::getDataGenerator()->get_plugin_generator('mod_anonforum')->create_discussion($record);
$record = new stdClass();
$record->course = $course2->id;
$record->userid = $user2->id;
$record->anonforum = $anonforum2->id;
$discussion2 = self::getDataGenerator()->get_plugin_generator('mod_anonforum')->create_discussion($record);
$record = new stdClass();
$record->course = $course2->id;
$record->userid = $user2->id;
$record->anonforum = $anonforum3->id;
$discussion3 = self::getDataGenerator()->get_plugin_generator('mod_anonforum')->create_discussion($record);
// Add three replies to the discussion 1 from different users.
$record = new stdClass();
$record->discussion = $discussion1->id;
$record->parent = $discussion1->firstpost;
$record->userid = $user2->id;
$discussion1reply1 = self::getDataGenerator()->get_plugin_generator('mod_anonforum')->create_post($record);
$record->parent = $discussion1reply1->id;
$record->userid = $user3->id;
$discussion1reply2 = self::getDataGenerator()->get_plugin_generator('mod_anonforum')->create_post($record);
$record->userid = $user4->id;
$discussion1reply3 = self::getDataGenerator()->get_plugin_generator('mod_anonforum')->create_post($record);
// Add two replies to discussion 2 from different users.
$record = new stdClass();
$record->discussion = $discussion2->id;
$record->parent = $discussion2->firstpost;
$record->userid = $user1->id;
$discussion2reply1 = self::getDataGenerator()->get_plugin_generator('mod_anonforum')->create_post($record);
$record->parent = $discussion2reply1->id;
$record->userid = $user3->id;
$discussion2reply2 = self::getDataGenerator()->get_plugin_generator('mod_anonforum')->create_post($record);
// Check the forums were correctly created.
$this->assertEquals(3, $DB->count_records_select('anonforum', 'id = :anonforum1 OR id = :anonforum2 OR id = :anonforum3', array('anonforum1' => $anonforum1->id, 'anonforum2' => $anonforum2->id, 'anonforum3' => $anonforum3->id)));
// Check the discussions were correctly created.
$this->assertEquals(3, $DB->count_records_select('anonforum_discussions', 'anonforum = :anonforum1 OR anonforum = :anonforum2 OR anonforum = :anonforum3', array('anonforum1' => $anonforum1->id, 'anonforum2' => $anonforum2->id, 'anonforum3' => $anonforum3->id)));
// Check the posts were correctly created, don't forget each discussion created also creates a post.
$this->assertEquals(7, $DB->count_records_select('anonforum_posts', 'discussion = :discussion1 OR discussion = :discussion2', array('discussion1' => $discussion1->id, 'discussion2' => $discussion2->id)));
// Enrol the user in the first course.
$enrol = enrol_get_plugin('manual');
// Following line enrol and assign default role id to the user.
// So the user automatically gets mod/anonforum:viewdiscussion on all forums of the course.
$this->getDataGenerator()->enrol_user($user1->id, $course1->id);
// Now enrol into the second course.
// We don't use the dataGenerator as we need to get the $instance2 to unenrol later.
$enrolinstances = enrol_get_instances($course2->id, true);
foreach ($enrolinstances as $courseenrolinstance) {
if ($courseenrolinstance->enrol == "manual") {
$instance2 = $courseenrolinstance;
break;
}
}
$enrol->enrol_user($instance2, $user1->id);
// Assign capabilities to view discussions for forum 2.
$cm = get_coursemodule_from_id('anonforum', $anonforum2->cmid, 0, false, MUST_EXIST);
$context = context_module::instance($cm->id);
$newrole = create_role('Role 2', 'role2', 'Role 2 description');
$this->assignUserCapability('mod/anonforum:viewdiscussion', $context->id, $newrole);
// Assign capabilities to view discussions for forum 3.
$cm = get_coursemodule_from_id('anonforum', $anonforum3->cmid, 0, false, MUST_EXIST);
$context = context_module::instance($cm->id);
$this->assignUserCapability('mod/anonforum:viewdiscussion', $context->id, $newrole);
// Create what we expect to be returned when querying the forums.
$expecteddiscussions = array();
$expecteddiscussions[$discussion1->id] = array('id' => $discussion1->id, 'course' => $discussion1->course, 'anonforum' => $discussion1->anonforum, 'name' => $discussion1->name, 'firstpost' => $discussion1->firstpost, 'userid' => $discussion1->userid, 'groupid' => $discussion1->groupid, 'assessed' => $discussion1->assessed, 'timemodified' => $discussion1reply3->created, 'usermodified' => $discussion1reply3->userid, 'timestart' => $discussion1->timestart, 'timeend' => $discussion1->timeend, 'firstuserfullname' => fullname($user1), 'firstuserimagealt' => $user1->imagealt, 'firstuserpicture' => $user1->picture, 'firs
|
请发表评论