MDL-34962 added release number to returned values
[moodle.git] / webservice / tests / externallib_test.php
CommitLineData
639bc8b2
PC
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
17defined('MOODLE_INTERNAL') || die();
18
19global $CFG;
20
21require_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 */
31class core_webservice_external_testcase extends externallib_advanced_testcase {
32
33 /**
34 * Tests set up
35 */
36 protected function setUp() {
37 global $CFG;
38 require_once($CFG->dirroot . '/webservice/externallib.php');
39 $_POST = array();
40 // Enable the webservices and set a release number.
41 set_config('enablewebservices', '1');
42 set_config('release', '2.4dev (Build: 20120823)');
43 set_config('version', '2012083100.00');
44 }
45
46 public function test_get_site_info() {
47 global $DB, $USER, $CFG;
48
49 $this->resetAfterTest(true);
50 $user = array();
51 $user['username'] = 'johnd';
52 $user['firstname'] = 'John';
53 $user['lastname'] = 'Doe';
54 self::setUser(self::getDataGenerator()->create_user($user));
55
56 // Add a web service and token.
57 $webservice = new stdClass();
58 $webservice->name = 'Test web service';
59 $webservice->enabled = true;
60 $webservice->restrictedusers = false;
61 $webservice->component = 'moodle';
62 $webservice->timecreated = time();
63 $webservice->downloadfiles = true;
64 $externalserviceid = $DB->insert_record('external_services', $webservice);
65
66 $_POST['wstoken'] = 'testtoken';
67 $externaltoken = new stdClass();
68 $externaltoken->token = 'testtoken';
69 $externaltoken->tokentype = 0;
70 $externaltoken->userid = $USER->id;
71 $externaltoken->externalserviceid = $externalserviceid;
72 $externaltoken->contextid = 1;
73 $externaltoken->creatorid = $USER->id;
74 $externaltoken->timecreated = time();
75 $DB->insert_record('external_tokens', $externaltoken);
76
77 $siteinfo = core_webservice_external::get_site_info();
78
79 $this->assertEquals('johnd', $siteinfo['username']);
80 $this->assertEquals('John', $siteinfo['firstname']);
81 $this->assertEquals('Doe', $siteinfo['lastname']);
82 $this->assertEquals($USER->id, $siteinfo['userid']);
83 $this->assertEquals(true, $siteinfo['downloadfiles']);
84 $this->assertEquals($CFG->release, $siteinfo['release']);
85 $this->assertEquals($CFG->version, $siteinfo['version']);
86 }
87
88}