MDL-60365 tool_mobile: Extra configuration checks
[moodle.git] / admin / tool / mobile / tests / api_test.php
CommitLineData
961c9549
JL
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/**
18 * Moodle Mobile admin tool api tests.
19 *
20 * @package tool_mobile
21 * @category external
22 * @copyright 2016 Juan Leyva
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 * @since Moodle 3.1
25 */
26
27defined('MOODLE_INTERNAL') || die();
28
29global $CFG;
30
31require_once($CFG->dirroot . '/webservice/tests/helpers.php');
32
33use tool_mobile\api;
34
35/**
36 * Moodle Mobile admin tool api tests.
37 *
38 * @package tool_mobile
39 * @copyright 2016 Juan Leyva
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41 * @since Moodle 3.1
42 */
43class tool_mobile_api_testcase extends externallib_advanced_testcase {
44
45 /**
46 * Test get_autologin_key.
47 */
48 public function test_get_autologin_key() {
49 global $USER, $DB;
50
51 $this->resetAfterTest(true);
52 $this->setAdminUser();
53
54 // Set server timezone for test.
55 $this->setTimezone('UTC');
56 // SEt user to GMT+5.
57 $USER->timezone = 5;
58
93432c78 59 $timenow = $this->setCurrentTimeStart();
961c9549
JL
60 $key = api::get_autologin_key();
61
62 $key = $DB->get_record('user_private_key', array('value' => $key), '*', MUST_EXIST);
93432c78 63 $this->assertTimeCurrent($key->validuntil - api::LOGIN_KEY_TTL);
961c9549
JL
64 $this->assertEquals('0.0.0.0', $key->iprestriction);
65 }
66a159f8
JL
66
67 /**
68 * Test get_potential_config_issues.
69 */
70 public function test_get_potential_config_issues() {
71 global $CFG;
72 require_once($CFG->dirroot . '/message/lib.php');
73
74 $this->resetAfterTest(true);
75 $this->setAdminUser();
76
77 $CFG->userquota = '73289234723498234723423489273423497234234';
78 $CFG->debugdisplay = 1;
79 set_config('debugauthdb', 1, 'auth_db');
80 set_config('debugdb', 1, 'enrol_database');
81 $expectedissues = array('nohttpsformobilewarning', 'invaliduserquotawarning', 'adodbdebugwarning', 'displayerrorswarning',
82 'mobilenotificationsdisabledwarning');
83
84 $processors = get_message_processors();
85 foreach ($processors as $processor => $status) {
86 if ($processor == 'airnotifier' && $status->enabled) {
87 unset($expectedissues['mobilenotificationsdisabledwarning']);
88 }
89 }
90
91 $issues = api::get_potential_config_issues();
92 $this->assertCount(count($expectedissues), $issues);
93 foreach ($issues as $issue) {
94 $this->assertTrue(in_array($issue[0], $expectedissues));
95 }
96 }
961c9549 97}