[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 defined('MOODLE_INTERNAL') || die(); 18 19 global $CFG; 20 require_once($CFG->dirroot . '/webservice/externallib.php'); 21 require_once($CFG->dirroot . '/webservice/tests/helpers.php'); 22 23 /** 24 * External course functions unit tests 25 * 26 * @package core_webservice 27 * @category external 28 * @copyright 2012 Paul Charsley 29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 30 */ 31 class core_webservice_externallib_testcase extends externallib_advanced_testcase { 32 33 public function setUp() { 34 // Calling parent is good, always 35 parent::setUp(); 36 37 // We always need enabled WS for this testcase 38 set_config('enablewebservices', '1'); 39 } 40 41 public function test_get_site_info() { 42 global $DB, $USER, $CFG; 43 44 $this->resetAfterTest(true); 45 46 // This is the info we are going to check 47 set_config('release', '2.4dev (Build: 20120823)'); 48 set_config('version', '2012083100.00'); 49 50 // Set current user 51 $user = array(); 52 $user['username'] = 'johnd'; 53 $user['firstname'] = 'John'; 54 $user['lastname'] = 'Doe'; 55 self::setUser(self::getDataGenerator()->create_user($user)); 56 57 // Add a web service and token. 58 $webservice = new stdClass(); 59 $webservice->name = 'Test web service'; 60 $webservice->enabled = true; 61 $webservice->restrictedusers = false; 62 $webservice->component = 'moodle'; 63 $webservice->timecreated = time(); 64 $webservice->downloadfiles = true; 65 $webservice->uploadfiles = true; 66 $externalserviceid = $DB->insert_record('external_services', $webservice); 67 68 // Add a function to the service 69 $DB->insert_record('external_services_functions', array('externalserviceid' => $externalserviceid, 70 'functionname' => 'core_course_get_contents')); 71 72 $_POST['wstoken'] = 'testtoken'; 73 $externaltoken = new stdClass(); 74 $externaltoken->token = 'testtoken'; 75 $externaltoken->tokentype = 0; 76 $externaltoken->userid = $USER->id; 77 $externaltoken->externalserviceid = $externalserviceid; 78 $externaltoken->contextid = 1; 79 $externaltoken->creatorid = $USER->id; 80 $externaltoken->timecreated = time(); 81 $DB->insert_record('external_tokens', $externaltoken); 82 83 $siteinfo = core_webservice_external::get_site_info(); 84 85 // We need to execute the return values cleaning process to simulate the web service server. 86 $siteinfo = external_api::clean_returnvalue(core_webservice_external::get_site_info_returns(), $siteinfo); 87 88 $this->assertEquals('johnd', $siteinfo['username']); 89 $this->assertEquals('John', $siteinfo['firstname']); 90 $this->assertEquals('Doe', $siteinfo['lastname']); 91 $this->assertEquals(current_language(), $siteinfo['lang']); 92 $this->assertEquals($USER->id, $siteinfo['userid']); 93 $this->assertEquals(true, $siteinfo['downloadfiles']); 94 $this->assertEquals($CFG->release, $siteinfo['release']); 95 $this->assertEquals($CFG->version, $siteinfo['version']); 96 $this->assertEquals($CFG->mobilecssurl, $siteinfo['mobilecssurl']); 97 $this->assertEquals(count($siteinfo['functions']), 1); 98 $function = array_pop($siteinfo['functions']); 99 $this->assertEquals($function['name'], 'core_course_get_contents'); 100 $this->assertEquals($function['version'], $siteinfo['version']); 101 $this->assertEquals(1, $siteinfo['downloadfiles']); 102 $this->assertEquals(1, $siteinfo['uploadfiles']); 103 } 104 105 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |