2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Moodle Mobile admin tool external functions tests.
20 * @package tool_mobile
22 * @copyright 2016 Juan Leyva
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') || die();
31 require_once($CFG->dirroot . '/webservice/tests/helpers.php');
33 use tool_mobile\external;
36 * External learning plans webservice API tests.
38 * @package tool_mobile
39 * @copyright 2016 Juan Leyva
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
43 class tool_mobile_external_testcase extends externallib_advanced_testcase {
46 * Test get_plugins_supporting_mobile.
47 * This is a very basic test because currently there aren't plugins supporting Mobile in core.
49 public function test_get_plugins_supporting_mobile() {
50 $result = external::get_plugins_supporting_mobile();
51 $result = external_api::clean_returnvalue(external::get_plugins_supporting_mobile_returns(), $result);
52 $this->assertCount(0, $result['warnings']);
53 $this->assertArrayHasKey('plugins', $result);
54 $this->assertTrue(is_array($result['plugins']));
57 public function test_get_site_public_settings() {
60 $this->resetAfterTest(true);
61 $result = external::get_site_public_settings();
62 $result = external_api::clean_returnvalue(external::get_site_public_settings_returns(), $result);
64 // Test default values.
65 $context = context_system::instance();
67 'wwwroot' => $CFG->wwwroot,
68 'httpswwwroot' => $CFG->httpswwwroot,
69 'sitename' => external_format_string($SITE->fullname, $context->id, true),
70 'guestlogin' => $CFG->guestloginbutton,
71 'rememberusername' => $CFG->rememberusername,
72 'authloginviaemail' => $CFG->authloginviaemail,
73 'registerauth' => $CFG->registerauth,
74 'forgottenpasswordurl' => $CFG->forgottenpasswordurl,
75 'authinstructions' => format_text($CFG->auth_instructions),
76 'authnoneenabled' => (int) is_enabled_auth('none'),
77 'enablewebservices' => $CFG->enablewebservices,
78 'enablemobilewebservice' => $CFG->enablemobilewebservice,
79 'maintenanceenabled' => $CFG->maintenance_enabled,
80 'maintenancemessage' => format_text($CFG->maintenance_message),
83 $this->assertEquals($expected, $result);
86 set_config('registerauth', 'email');
87 $authinstructions = 'Something with <b>html tags</b>';
88 set_config('auth_instructions', $authinstructions);
90 $expected['registerauth'] = 'email';
91 $expected['authinstructions'] = format_text($authinstructions);
93 $result = external::get_site_public_settings();
94 $result = external_api::clean_returnvalue(external::get_site_public_settings_returns(), $result);
95 $this->assertEquals($expected, $result);