Commit 100bc51f authored by Eloy Lafuente's avatar Eloy Lafuente
Browse files

MDL-73485 phpunit: externallib, generator and filter tescase names

All externallib_test, generator_test and filter_test classes:

- Namespaced with component[\level2-API]
- Moved to level2-API subdirectory when required.
- Fixed incorrect use statements with leading backslash.
- Changed code to point to global scope when needed.
- Fix some relative paths and comments here and there.
- All them passing individually.
- Complete runs passing too.

Special mention to tests under testing/tests:

1) The core_testing component doesn't exist.
2) But testing/tests are allowed because there is a suite pointing to it (phpunit.xml).
3) So, the only possible namespace for them is "core".
4) And to avoid problems with other core testcases (under lib/tests)
   they have been renamed to have testing_xxxx as prefix.

Finally, also modified calendar/tests/events/events_test.php because it uses
some renamed (core_calendar_externallib_testcase => \core_calendar\externallib_test)
classes.
parent e63604fb
......@@ -13,22 +13,10 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* External learning plans webservice API tests.
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
namespace tool_lp;
use core_competency\api;
use tool_lp\external;
use core_competency\invalid_persistent_exception;
use core_competency\plan;
use core_competency\related_competency;
......@@ -38,6 +26,13 @@ use core_competency\plan_competency;
use core_competency\template;
use core_competency\template_competency;
use core_competency\course_competency_settings;
use externallib_advanced_testcase;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
/**
* External learning plans webservice API tests.
......@@ -46,24 +41,24 @@ use core_competency\course_competency_settings;
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_lp_external_testcase extends externallib_advanced_testcase {
class externallib_test extends externallib_advanced_testcase {
/** @var stdClass $creator User with enough permissions to create insystem context. */
/** @var \stdClass $creator User with enough permissions to create insystem context. */
protected $creator = null;
/** @var stdClass $catcreator User with enough permissions to create incategory context. */
/** @var \stdClass $catcreator User with enough permissions to create incategory context. */
protected $catcreator = null;
/** @var stdClass $category Category */
/** @var \stdClass $category Category */
protected $category = null;
/** @var stdClass $category Category */
/** @var \stdClass $category Category */
protected $othercategory = null;
/** @var stdClass $user User with enough permissions to view insystem context */
/** @var \stdClass $user User with enough permissions to view insystem context */
protected $user = null;
/** @var stdClass $catuser User with enough permissions to view incategory context */
/** @var \stdClass $catuser User with enough permissions to view incategory context */
protected $catuser = null;
/** @var int Creator role id */
......@@ -87,8 +82,8 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$catcreator = $this->getDataGenerator()->create_user();
$category = $this->getDataGenerator()->create_category();
$othercategory = $this->getDataGenerator()->create_category();
$syscontext = context_system::instance();
$catcontext = context_coursecat::instance($category->id);
$syscontext = \context_system::instance();
$catcontext = \context_coursecat::instance($category->id);
// Fetching default authenticated user role.
$authrole = $DB->get_record('role', array('id' => $CFG->defaultuserroleid));
......@@ -157,33 +152,33 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
// First we search with no capability assigned.
$this->setUser($ux);
$result = external::search_users('yyylan', 'moodle/competency:planmanage');
$result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(0, $result['users']);
$this->assertEquals(0, $result['count']);
// Now we assign a different capability.
$usercontext = context_user::instance($u1->id);
$systemcontext = context_system::instance();
$usercontext = \context_user::instance($u1->id);
$systemcontext = \context_system::instance();
$customrole = $this->assignUserCapability('moodle/competency:planview', $usercontext->id);
$result = external::search_users('yyylan', 'moodle/competency:planmanage');
$result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(0, $result['users']);
$this->assertEquals(0, $result['count']);
// Now we assign a matching capability in the same role.
$usercontext = context_user::instance($u1->id);
$usercontext = \context_user::instance($u1->id);
$this->assignUserCapability('moodle/competency:planmanage', $usercontext->id, $customrole);
$result = external::search_users('yyylan', 'moodle/competency:planmanage');
$result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(1, $result['users']);
$this->assertEquals(1, $result['count']);
// Now assign another role with the same capability (test duplicates).
role_assign($this->creatorrole, $ux->id, $usercontext->id);
$result = external::search_users('yyylan', 'moodle/competency:planmanage');
$result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(1, $result['users']);
$this->assertEquals(1, $result['count']);
......@@ -192,7 +187,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
role_assign($this->creatorrole, $ux2->id, $systemcontext->id);
$this->setUser($ux2);
$result = external::search_users('yyylan', 'moodle/competency:planmanage');
$result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(1, $result['users']);
$this->assertEquals(1, $result['count']);
......@@ -201,7 +196,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
role_assign($this->creatorrole, $ux3->id, $usercontext->id);
$this->setUser($ux3);
$result = external::search_users('yyylan', 'moodle/competency:planmanage');
$result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(1, $result['users']);
$this->assertEquals(1, $result['count']);
......@@ -211,14 +206,14 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
// Now add a prevent override (will change nothing because we still have an ALLOW).
assign_capability('moodle/competency:planmanage', CAP_PREVENT, $customrole, $usercontext->id);
$result = external::search_users('yyylan', 'moodle/competency:planmanage');
$result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(1, $result['users']);
$this->assertEquals(1, $result['count']);
// Now change to a prohibit override (should prevent access).
assign_capability('moodle/competency:planmanage', CAP_PROHIBIT, $customrole, $usercontext->id);
$result = external::search_users('yyylan', 'moodle/competency:planmanage');
$result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(1, $result['users']);
$this->assertEquals(1, $result['count']);
......@@ -237,10 +232,10 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$slave2 = $dg->create_user(array('lastname' => 'MOODLER'));
$slave3 = $dg->create_user(array('lastname' => 'MOODLER'));
$syscontext = context_system::instance();
$slave1context = context_user::instance($slave1->id);
$slave2context = context_user::instance($slave2->id);
$slave3context = context_user::instance($slave3->id);
$syscontext = \context_system::instance();
$slave1context = \context_user::instance($slave1->id);
$slave2context = \context_user::instance($slave2->id);
$slave3context = \context_user::instance($slave3->id);
// Creating a role giving the site config.
$roleid = $dg->create_role();
......@@ -306,19 +301,19 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
// We need to give the user the capability we are searching for on each of the test users.
$this->setAdminUser();
$usercontext = context_user::instance($u1->id);
$usercontext = \context_user::instance($u1->id);
$dummyrole = $this->assignUserCapability('moodle/competency:planmanage', $usercontext->id);
$usercontext = context_user::instance($u2->id);
$usercontext = \context_user::instance($u2->id);
$this->assignUserCapability('moodle/competency:planmanage', $usercontext->id, $dummyrole);
$usercontext = context_user::instance($u3->id);
$usercontext = \context_user::instance($u3->id);
$this->assignUserCapability('moodle/competency:planmanage', $usercontext->id, $dummyrole);
$this->setUser($ux);
$usercontext = context_user::instance($u1->id);
$usercontext = \context_user::instance($u1->id);
$this->assignUserCapability('moodle/competency:planmanage', $usercontext->id, $dummyrole);
$usercontext = context_user::instance($u2->id);
$usercontext = \context_user::instance($u2->id);
$this->assignUserCapability('moodle/competency:planmanage', $usercontext->id, $dummyrole);
$usercontext = context_user::instance($u3->id);
$usercontext = \context_user::instance($u3->id);
$this->assignUserCapability('moodle/competency:planmanage', $usercontext->id, $dummyrole);
$this->setAdminUser();
......@@ -326,14 +321,14 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
// No identity fields.
$CFG->showuseridentity = '';
$result = external::search_users('cats', 'moodle/competency:planmanage');
$result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(0, $result['users']);
$this->assertEquals(0, $result['count']);
// Filter by name.
$CFG->showuseridentity = '';
$result = external::search_users('dyyylan', 'moodle/competency:planmanage');
$result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(2, $result['users']);
$this->assertEquals(2, $result['count']);
$this->assertEquals($u2->id, $result['users'][0]['id']);
......@@ -342,7 +337,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
// Filter by institution and name.
$CFG->showuseridentity = 'institution';
$result = external::search_users('bob', 'moodle/competency:planmanage');
$result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(2, $result['users']);
$this->assertEquals(2, $result['count']);
$this->assertEquals($u1->id, $result['users'][0]['id']);
......@@ -351,7 +346,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
// Filter by id number.
$CFG->showuseridentity = 'idnumber';
$result = external::search_users('cats', 'moodle/competency:planmanage');
$result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(1, $result['users']);
$this->assertEquals(1, $result['count']);
$this->assertEquals($u1->id, $result['users'][0]['id']);
......@@ -365,7 +360,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
// Filter by email.
$CFG->showuseridentity = 'email';
$result = external::search_users('yyy', 'moodle/competency:planmanage');
$result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(3, $result['users']);
$this->assertEquals(3, $result['count']);
$this->assertEquals($u2->id, $result['users'][0]['id']);
......@@ -378,7 +373,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
// Filter by any.
$CFG->showuseridentity = 'idnumber,email,phone1,phone2,department,institution';
$result = external::search_users('yyy', 'moodle/competency:planmanage');
$result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(3, $result['users']);
$this->assertEquals(3, $result['count']);
$this->assertArrayHasKey('idnumber', $result['users'][0]);
......@@ -394,12 +389,12 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
// Only names are included.
$result = external::search_users('fish');
$result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(0, $result['users']);
$this->assertEquals(0, $result['count']);
$result = external::search_users('bob', 'moodle/competency:planmanage');
$result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(1, $result['users']);
$this->assertEquals(1, $result['count']);
$this->assertEquals($u1->id, $result['users'][0]['id']);
......
......@@ -14,15 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Moodle Mobile admin tool external functions tests.
*
* @package tool_mobile
* @category external
* @copyright 2016 Juan Leyva
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.1
*/
namespace tool_mobile;
use externallib_advanced_testcase;
defined('MOODLE_INTERNAL') || die();
......@@ -32,9 +26,6 @@ require_once($CFG->dirroot . '/webservice/tests/helpers.php');
require_once($CFG->dirroot . '/admin/tool/mobile/tests/fixtures/output/mobile.php');
require_once($CFG->dirroot . '/webservice/lib.php');
use tool_mobile\external;
use tool_mobile\api;
/**
* Moodle Mobile admin tool external functions tests.
*
......@@ -43,7 +34,7 @@ use tool_mobile\api;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.1
*/
class tool_mobile_external_testcase extends externallib_advanced_testcase {
class externallib_test extends externallib_advanced_testcase {
/**
* Test get_plugins_supporting_mobile.
......@@ -51,7 +42,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
*/
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);
$result = \external_api::clean_returnvalue(external::get_plugins_supporting_mobile_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertArrayHasKey('plugins', $result);
$this->assertTrue(is_array($result['plugins']));
......@@ -62,10 +53,10 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$this->resetAfterTest(true);
$result = external::get_public_config();
$result = external_api::clean_returnvalue(external::get_public_config_returns(), $result);
$result = \external_api::clean_returnvalue(external::get_public_config_returns(), $result);
// Test default values.
$context = context_system::instance();
$context = \context_system::instance();
list($authinstructions, $notusedformat) = external_format_text($CFG->auth_instructions, FORMAT_MOODLE, $context->id);
list($maintenancemessage, $notusedformat) = external_format_text($CFG->maintenance_message, FORMAT_MOODLE, $context->id);
......@@ -125,7 +116,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$irecord = $issuer->to_record();
$irecord->clientid = 'mock';
$irecord->clientsecret = 'mock';
core\oauth2\api::update_issuer($irecord);
\core\oauth2\api::update_issuer($irecord);
set_config('hostname', 'localhost', 'auth_cas');
set_config('auth_logo', 'http://invalidurl.com//invalid/', 'auth_cas');
......@@ -153,7 +144,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
}
$result = external::get_public_config();
$result = external_api::clean_returnvalue(external::get_public_config_returns(), $result);
$result = \external_api::clean_returnvalue(external::get_public_config_returns(), $result);
// First check providers.
$identityproviders = $result['identityproviders'];
unset($result['identityproviders']);
......@@ -172,7 +163,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$newurl = 'validimage.png';
set_config('auth_logo', $newurl, 'auth_cas');
$result = external::get_public_config();
$result = external_api::clean_returnvalue(external::get_public_config_returns(), $result);
$result = \external_api::clean_returnvalue(external::get_public_config_returns(), $result);
$this->assertStringContainsString($newurl, $result['identityproviders'][1]['iconurl']);
}
......@@ -190,13 +181,13 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
set_config('supportemail', 'test@test.com');
$result = external::get_config();
$result = external_api::clean_returnvalue(external::get_config_returns(), $result);
$result = \external_api::clean_returnvalue(external::get_config_returns(), $result);
// SITE summary is null in phpunit which gets transformed to an empty string by format_text.
list($sitesummary, $unused) = external_format_text($SITE->summary, $SITE->summaryformat, context_system::instance()->id);
list($sitesummary, $unused) = external_format_text($SITE->summary, $SITE->summaryformat, \context_system::instance()->id);
// Test default values.
$context = context_system::instance();
$context = \context_system::instance();
$expected = array(
array('name' => 'fullname', 'value' => $SITE->fullname),
array('name' => 'shortname', 'value' => $SITE->shortname),
......@@ -251,7 +242,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
array_splice($expected, 11);
$result = external::get_config('frontpagesettings');
$result = external_api::clean_returnvalue(external::get_config_returns(), $result);
$result = \external_api::clean_returnvalue(external::get_config_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals($expected, $result['settings']);
}
......@@ -277,7 +268,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$_GET['wstoken'] = $token->token; // Mock parameters.
// Fake the app.
core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
\core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
'AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 MoodleMobile');
// Even if we force the password change for the current user we should be able to retrieve the key.
......@@ -285,9 +276,9 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$this->setCurrentTimeStart();
$result = external::get_autologin_key($token->privatetoken);
$result = external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
$result = \external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
// Validate the key.
$this->assertEquals(32, core_text::strlen($result['key']));
$this->assertEquals(32, \core_text::strlen($result['key']));
$key = $DB->get_record('user_private_key', array('value' => $result['key']));
$this->assertEquals($USER->id, $key->userid);
$this->assertTimeCurrent($key->validuntil - api::LOGIN_KEY_TTL);
......@@ -308,7 +299,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$this->resetAfterTest(true);
// Fake the app.
core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
\core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
'AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 MoodleMobile');
// Need to disable webservices to verify that's checked.
......@@ -328,7 +319,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
global $CFG;
// Fake the app.
core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
\core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
'AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 MoodleMobile');
// Need to simulate a non HTTPS site here.
......@@ -352,7 +343,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$this->setAdminUser();
// Fake the app.
core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
\core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
'AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 MoodleMobile');
$this->expectException('moodle_exception');
......@@ -376,17 +367,17 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$_GET['wstoken'] = $token->token; // Mock parameters.
// Fake the app.
core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
\core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
'AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 MoodleMobile');
$result = external::get_autologin_key($token->privatetoken);
$result = external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
$result = \external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
// Mock last time request.
$mocktime = time() - 7 * MINSECS;
set_user_preference('tool_mobile_autologin_request_last', $mocktime, $USER);
$result = external::get_autologin_key($token->privatetoken);
$result = external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
$result = \external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
// Change min time between requests to 30 seconds.
set_config('autologinmintimebetweenreq', 30, 'tool_mobile');
......@@ -395,7 +386,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$mocktime = time() - MINSECS;
set_user_preference('tool_mobile_autologin_request_last', $mocktime, $USER);
$result = external::get_autologin_key($token->privatetoken); // All good, we were expecint 30 seconds or more.
$result = external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
$result = \external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
// We just requested one token, we must wait.
$this->expectException('moodle_exception');
......@@ -424,7 +415,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$paramval = 16;
$result = external::get_content('tool_mobile', 'test_view', array(array('name' => 'param1', 'value' => $paramval)));
$result = external_api::clean_returnvalue(external::get_content_returns(), $result);
$result = \external_api::clean_returnvalue(external::get_content_returns(), $result);
$this->assertCount(1, $result['templates']);
$this->assertCount(1, $result['otherdata']);
$this->assertCount(2, $result['restrict']['users']);
......@@ -448,7 +439,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$paramval = 16;
$result = external::get_content('tool_mobile', 'test_view_disabled',
array(array('name' => 'param1', 'value' => $paramval)));
$result = external_api::clean_returnvalue(external::get_content_returns(), $result);
$result = \external_api::clean_returnvalue(external::get_content_returns(), $result);
$this->assertTrue($result['disabled']);
}
......@@ -505,7 +496,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$token = external_generate_token_for_current_user($service);
$_POST['wstoken'] = $token->token;
// Workaround for external_api::call_external_function requiring sesskey.
// Workaround for \external_api::call_external_function requiring sesskey.
$_POST['sesskey'] = sesskey();
// Call some functions.
......@@ -531,21 +522,21 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$result = external::call_external_functions($requests);
// We need to execute the return values cleaning process to simulate the web service server.
$result = external_api::clean_returnvalue(external::call_external_functions_returns(), $result);
$result = \external_api::clean_returnvalue(external::call_external_functions_returns(), $result);
// Only 3 responses, the 4th request is not executed because the 3rd throws an exception.
$this->assertCount(3, $result['responses']);
$this->assertFalse($result['responses'][0]['error']);
$coursedata = external_api::clean_returnvalue(
core_course_external::get_courses_by_field_returns(),
core_course_external::get_courses_by_field('id', $course->id));
$coursedata = \external_api::clean_returnvalue(
\core_course_external::get_courses_by_field_returns(),
\core_course_external::get_courses_by_field('id', $course->id));
$this->assertEquals(json_encode($coursedata), $result['responses'][0]['data']);
$this->assertFalse($result['responses'][1]['error']);
$userdata = external_api::clean_returnvalue(
core_user_external::get_users_by_field_returns(),
core_user_external::get_users_by_field('id', [$user1->id]));
$userdata = \external_api::clean_returnvalue(
\core_user_external::get_users_by_field_returns(),
\core_user_external::get_users_by_field('id', [$user1->id]));
$this->assertEquals(json_encode($userdata), $result['responses'][1]['data']);
$this->assertTrue($result['responses'][2]['error']);
......@@ -641,11 +632,11 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$token = external_generate_token_for_current_user($service);
// Fake the app.
core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
\core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
'AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 MoodleMobile');
$result = external::get_tokens_for_qr_login($qrloginkey, $USER->id);
$result = external_api::clean_returnvalue(external::get_tokens_for_qr_login_returns(), $result);
$result = \external_api::clean_returnvalue(external::get_tokens_for_qr_login_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertEquals($token->token, $result['token']);
......@@ -665,7 +656,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$this->resetAfterTest(true);
$this->setAdminUser();
set_config('qrcodetype', tool_mobile\api::QR_CODE_DISABLED, 'tool_mobile');
set_config('qrcodetype', api::QR_CODE_DISABLED, 'tool_mobile');
$this->expectExceptionMessage(get_string('qrcodedisabled', 'tool_mobile'));
$result = external::get_tokens_for_qr_login('', $USER->id);
......@@ -682,7 +673,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$this->setUser($user);
// Fake the app.
core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
\core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
'AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 MoodleMobile');
// Need to disable webservices to verify that's checked.
......@@ -702,7 +693,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
global $CFG, $USER;
// Fake the app.
core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
\core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
'AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 MoodleMobile');
// Need to simulate a non HTTPS site here.
......@@ -726,7 +717,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$this->setAdminUser();
// Fake the app.
core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
\core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
'AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 MoodleMobile');
$this->expectException('moodle_exception');
......@@ -758,7 +749,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
set_config('sitesubscriptionkey', json_encode($sitesubscriptionkey), 'tool_mobile');
$result = external::validate_subscription_key($sitesubscriptionkey['key']);
$result = external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
$result = \external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertTrue($result['validated']);
}
......@@ -773,13 +764,13 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
set_config('sitesubscriptionkey', json_encode($sitesubscriptionkey), 'tool_mobile');
$result = external::validate_subscription_key('fakekey');
$result = external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
$result = \external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertFalse($result['validated']);
// The valid one has been invalidated because the previous attempt.
$result = external::validate_subscription_key($sitesubscriptionkey['key']);
$result = external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
$result = \external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertFalse($result['validated']);
}
......@@ -791,7 +782,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$this->resetAfterTest(true);
$result = external::validate_subscription_key('fakekey');
$result = external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
$result = \external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertFalse($result['validated']);
}
......@@ -806,7 +797,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
set_config('sitesubscriptionkey', json_encode($sitesubscriptionkey), 'tool_mobile');
$result = external::validate_subscription_key($sitesubscriptionkey['key']);
$result = external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
$result = \external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertFalse($result['validated']);
}
......
......@@ -14,16 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* PHPUnit data generator tests.
*
* @package tool_monitor
* @category test