Commit 0c53a3de authored by Eloy Lafuente's avatar Eloy Lafuente
Browse files

MDL-73476 phpunit: events, external and search tescase names

All events_test, external_test and search_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 lib/external/tests/external_test.php:
- external is not a valid component
- hence, its only valid namespace is "core"
- also, it's testing lib/external/externallib.php
- hence, the file (and class) have been renamed to external_externallib_test.php
  (to avoid conflicts with other external_test that may exist in core)
parent 0e188470
......@@ -24,13 +24,17 @@
* @since Moodle 3.8
*/
namespace tool_analytics\external;
use externallib_advanced_testcase;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
require_once(__DIR__ . '/../../../../analytics/tests/fixtures/test_indicator_max.php');
require_once(__DIR__ . '/../../../../analytics/tests/fixtures/test_target_course_level_shortname.php');
require_once($CFG->dirroot . '/analytics/tests/fixtures/test_indicator_max.php');
require_once($CFG->dirroot . '/analytics/tests/fixtures/test_target_course_level_shortname.php');
/**
* Tool analytics external functions tests
......@@ -41,7 +45,7 @@ require_once(__DIR__ . '/../../../../analytics/tests/fixtures/test_target_course
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.8
*/
class tool_analytics_external_testcase extends externallib_advanced_testcase {
class external_test extends externallib_advanced_testcase {
/**
* test_potential_contexts description
......@@ -73,7 +77,7 @@ class tool_analytics_external_testcase extends externallib_advanced_testcase {
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
$this->expectException(required_capability_exception::class);
$this->expectException(\required_capability_exception::class);
$this->assertCount(2, \tool_analytics\external::potential_contexts());
}
}
......@@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
defined('MOODLE_INTERNAL') || die();
namespace tool_capability\event;
/**
* Class for capability overview events.
......@@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2014 Petr Skoda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class tool_capability_events_testcase extends advanced_testcase {
class events_test extends \advanced_testcase {
/**
* Setup testcase.
......@@ -54,11 +54,11 @@ class tool_capability_events_testcase extends advanced_testcase {
$event = reset($events);
$this->assertInstanceOf('\tool_capability\event\report_viewed', $event);
$this->assertEquals(context_system::instance(), $event->get_context());
$this->assertEquals(\context_system::instance(), $event->get_context());
$expected = array(SITEID, "admin", "tool capability", "tool/capability/index.php");
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
$url = new moodle_url('/admin/tool/capability/index.php');
$url = new \moodle_url('/admin/tool/capability/index.php');
$this->assertEquals($url, $event->get_url());
$event->get_name();
}
......
......@@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
defined('MOODLE_INTERNAL') || die();
namespace tool_langimport\event;
/**
* Test class for langimport events.
......@@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2014 Dan Poltawski
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class tool_langimport_events_testcase extends advanced_testcase {
class events_test extends \advanced_testcase {
/**
* Setup testcase.
......@@ -53,7 +53,7 @@ class tool_langimport_events_testcase extends advanced_testcase {
$event = reset($events);
$this->assertInstanceOf('\tool_langimport\event\langpack_updated', $event);
$this->assertEquals(context_system::instance(), $event->get_context());
$this->assertEquals(\context_system::instance(), $event->get_context());
}
public function test_langpack_updated_validation() {
......@@ -73,7 +73,7 @@ class tool_langimport_events_testcase extends advanced_testcase {
$event = reset($events);
$this->assertInstanceOf('\tool_langimport\event\langpack_imported', $event);
$this->assertEquals(context_system::instance(), $event->get_context());
$this->assertEquals(\context_system::instance(), $event->get_context());
}
public function test_langpack_installed_validation() {
......@@ -93,7 +93,7 @@ class tool_langimport_events_testcase extends advanced_testcase {
$event = reset($events);
$this->assertInstanceOf('\tool_langimport\event\langpack_removed', $event);
$this->assertEquals(context_system::instance(), $event->get_context());
$this->assertEquals(\context_system::instance(), $event->get_context());
}
public function test_langpack_removed_validation() {
......
......@@ -23,12 +23,12 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace tool_monitor\event;
/**
* Tests that the tool_monitor events are valid and triggered correctly.
*/
class tool_monitor_events_testcase extends advanced_testcase {
class events_test extends \advanced_testcase {
/**
* Tests set up.
......@@ -47,7 +47,7 @@ class tool_monitor_events_testcase extends advanced_testcase {
$user = $this->getDataGenerator()->create_user();
// Create the variables for the rule we want to create.
$ruledata = new stdClass();
$ruledata = new \stdClass();
$ruledata->userid = $user->id;
$ruledata->courseid = $course->id;
$ruledata->plugin = 'mod_assign';
......@@ -68,7 +68,7 @@ class tool_monitor_events_testcase extends advanced_testcase {
// Confirm that the event contains the expected values.
$this->assertInstanceOf('\tool_monitor\event\rule_created', $event);
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals(\context_course::instance($course->id), $event->get_context());
$this->assertEquals($rule->id, $event->objectid);
$this->assertEventContextNotUsed($event);
......@@ -84,7 +84,7 @@ class tool_monitor_events_testcase extends advanced_testcase {
// Confirm that the event uses the system context.
$this->assertInstanceOf('\tool_monitor\event\rule_created', $event);
$this->assertEquals(context_system::instance(), $event->get_context());
$this->assertEquals(\context_system::instance(), $event->get_context());
}
/**
......@@ -96,13 +96,13 @@ class tool_monitor_events_testcase extends advanced_testcase {
$course = $this->getDataGenerator()->create_course();
// Create the rule we are going to update.
$createrule = new stdClass();
$createrule = new \stdClass();
$createrule->courseid = $course->id;
$rule = $monitorgenerator->create_rule($createrule);
// Trigger and capture the event.
$sink = $this->redirectEvents();
$updaterule = new stdClass();
$updaterule = new \stdClass();
$updaterule->id = $rule->id;
\tool_monitor\rule_manager::update_rule($updaterule);
$events = $sink->get_events();
......@@ -111,7 +111,7 @@ class tool_monitor_events_testcase extends advanced_testcase {
// Confirm that the event contains the expected values.
$this->assertInstanceOf('\tool_monitor\event\rule_updated', $event);
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals(\context_course::instance($course->id), $event->get_context());
$this->assertEquals($rule->id, $event->objectid);
$this->assertEventContextNotUsed($event);
......@@ -121,7 +121,7 @@ class tool_monitor_events_testcase extends advanced_testcase {
// Trigger and capture the event.
$sink = $this->redirectEvents();
$updaterule = new stdClass();
$updaterule = new \stdClass();
$updaterule->id = $rule->id;
\tool_monitor\rule_manager::update_rule($updaterule);
$events = $sink->get_events();
......@@ -130,7 +130,7 @@ class tool_monitor_events_testcase extends advanced_testcase {
// Confirm that the event uses the system context.
$this->assertInstanceOf('\tool_monitor\event\rule_updated', $event);
$this->assertEquals(context_system::instance(), $event->get_context());
$this->assertEquals(\context_system::instance(), $event->get_context());
}
/**
......@@ -142,7 +142,7 @@ class tool_monitor_events_testcase extends advanced_testcase {
$course = $this->getDataGenerator()->create_course();
// Create the rule we are going to delete.
$createrule = new stdClass();
$createrule = new \stdClass();
$createrule->courseid = $course->id;
$rule = $monitorgenerator->create_rule($createrule);
......@@ -155,12 +155,12 @@ class tool_monitor_events_testcase extends advanced_testcase {
// Confirm that the event contains the expected values.
$this->assertInstanceOf('\tool_monitor\event\rule_deleted', $event);
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals(\context_course::instance($course->id), $event->get_context());
$this->assertEquals($rule->id, $event->objectid);
$this->assertEventContextNotUsed($event);
// Now let's delete a system rule (courseid = 0).
$createrule = new stdClass();
$createrule = new \stdClass();
$createrule->courseid = 0;
$rule = $monitorgenerator->create_rule($createrule);
......@@ -173,7 +173,7 @@ class tool_monitor_events_testcase extends advanced_testcase {
// Confirm that the event uses the system context.
$this->assertInstanceOf('\tool_monitor\event\rule_deleted', $event);
$this->assertEquals(context_system::instance(), $event->get_context());
$this->assertEquals(\context_system::instance(), $event->get_context());
}
/**
......@@ -197,7 +197,7 @@ class tool_monitor_events_testcase extends advanced_testcase {
// Confirm that the event contains the expected values.
$this->assertInstanceOf('\tool_monitor\event\subscription_created', $event);
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals(\context_course::instance($course->id), $event->get_context());
$this->assertEquals($subscriptionid, $event->objectid);
$this->assertEventContextNotUsed($event);
......@@ -210,7 +210,7 @@ class tool_monitor_events_testcase extends advanced_testcase {
// Confirm that the event uses the system context.
$this->assertInstanceOf('\tool_monitor\event\subscription_created', $event);
$this->assertEquals(context_system::instance(), $event->get_context());
$this->assertEquals(\context_system::instance(), $event->get_context());
}
/**
......@@ -225,7 +225,7 @@ class tool_monitor_events_testcase extends advanced_testcase {
// Create a rule to subscribe to.
$rule = $monitorgenerator->create_rule();
$sub = new stdClass();
$sub = new \stdClass();
$sub->courseid = $course->id;
$sub->userid = $user->id;
$sub->ruleid = $rule->id;
......@@ -242,12 +242,12 @@ class tool_monitor_events_testcase extends advanced_testcase {
// Confirm that the event contains the expected values.
$this->assertInstanceOf('\tool_monitor\event\subscription_deleted', $event);
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals(\context_course::instance($course->id), $event->get_context());
$this->assertEquals($subscription->id, $event->objectid);
$this->assertEventContextNotUsed($event);
// Now let's delete a system subscription.
$sub = new stdClass();
$sub = new \stdClass();
$sub->courseid = 0;
$sub->userid = $user->id;
$sub->ruleid = $rule->id;
......@@ -264,7 +264,7 @@ class tool_monitor_events_testcase extends advanced_testcase {
// Confirm that the event uses the system context.
$this->assertInstanceOf('\tool_monitor\event\subscription_deleted', $event);
$this->assertEquals(context_system::instance(), $event->get_context());
$this->assertEquals(\context_system::instance(), $event->get_context());
// Now, create a bunch of subscriptions for the rule we created.
$subids = array();
......@@ -286,7 +286,7 @@ class tool_monitor_events_testcase extends advanced_testcase {
// Get all the events and ensure they are valid.
foreach ($events as $event) {
$this->assertInstanceOf('\tool_monitor\event\subscription_deleted', $event);
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals(\context_course::instance($course->id), $event->get_context());
$this->assertEventContextNotUsed($event);
$this->assertArrayHasKey($event->objectid, $subids);
unset($subids[$event->objectid]);
......@@ -309,7 +309,7 @@ class tool_monitor_events_testcase extends advanced_testcase {
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
// Create a rule we want to subscribe to.
$rule = new stdClass();
$rule = new \stdClass();
$rule->userid = $user->id;
$rule->courseid = $course->id;
$rule->plugin = 'mod_book';
......@@ -319,14 +319,14 @@ class tool_monitor_events_testcase extends advanced_testcase {
$rule = $monitorgenerator->create_rule($rule);
// Create the subscription.
$sub = new stdClass();
$sub = new \stdClass();
$sub->courseid = $course->id;
$sub->userid = $user->id;
$sub->ruleid = $rule->id;
$monitorgenerator->create_subscription($sub);
// Now create the \mod_book\event\chapter_viewed event we are listening for.
$context = context_module::instance($book->cmid);
$context = \context_module::instance($book->cmid);
$event = \mod_book\event\chapter_viewed::create_from_chapter($book, $context, $chapter);
// Trigger and capture the event.
......@@ -338,7 +338,7 @@ class tool_monitor_events_testcase extends advanced_testcase {
// Confirm that the event contains the expected values.
$this->assertInstanceOf('\tool_monitor\event\subscription_criteria_met', $event);
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals(\context_course::instance($course->id), $event->get_context());
$this->assertEventContextNotUsed($event);
}
}
......@@ -23,7 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace tool_recyclebin\event;
/**
* Events tests class.
......@@ -33,7 +33,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_recyclebin_events_testcase extends advanced_testcase {
class events_test extends \advanced_testcase {
/**
* Test set up.
......@@ -70,7 +70,7 @@ class tool_recyclebin_events_testcase extends advanced_testcase {
// Check that the event contains the expected values.
$this->assertInstanceOf('\tooL_recyclebin\event\category_bin_item_created', $event);
$this->assertEquals(context_coursecat::instance($course->category), $event->get_context());
$this->assertEquals(\context_coursecat::instance($course->category), $event->get_context());
$this->assertEquals($item->id, $event->objectid);
$this->assertEventContextNotUsed($event);
}
......@@ -99,7 +99,7 @@ class tool_recyclebin_events_testcase extends advanced_testcase {
// Check that the event contains the expected values.
$this->assertInstanceOf('\tooL_recyclebin\event\category_bin_item_deleted', $event);
$this->assertEquals(context_coursecat::instance($course->category), $event->get_context());
$this->assertEquals(\context_coursecat::instance($course->category), $event->get_context());
$this->assertEquals($item->id, $event->objectid);
$this->assertEventContextNotUsed($event);
}
......@@ -127,7 +127,7 @@ class tool_recyclebin_events_testcase extends advanced_testcase {
// Check that the event contains the expected values.
$this->assertInstanceOf('\tooL_recyclebin\event\category_bin_item_restored', $event);
$this->assertEquals(context_coursecat::instance($course->category), $event->get_context());
$this->assertEquals(\context_coursecat::instance($course->category), $event->get_context());
$this->assertEquals($item->id, $event->objectid);
$this->assertEventContextNotUsed($event);
}
......@@ -156,7 +156,7 @@ class tool_recyclebin_events_testcase extends advanced_testcase {
// Check that the event contains the expected values.
$this->assertInstanceOf('\tooL_recyclebin\event\course_bin_item_created', $event);
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals(\context_course::instance($course->id), $event->get_context());
$this->assertEquals($item->id, $event->objectid);
$this->assertEventContextNotUsed($event);
}
......@@ -189,7 +189,7 @@ class tool_recyclebin_events_testcase extends advanced_testcase {
// Check that the event contains the expected values.
$this->assertInstanceOf('\tooL_recyclebin\event\course_bin_item_deleted', $event);
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals(\context_course::instance($course->id), $event->get_context());
$this->assertEquals($item->id, $event->objectid);
$this->assertEventContextNotUsed($event);
}
......@@ -221,7 +221,7 @@ class tool_recyclebin_events_testcase extends advanced_testcase {
foreach ($events as $event) {
if ($event instanceof \tooL_recyclebin\event\course_bin_item_restored) {
// Check that the event contains the expected values.
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals(\context_course::instance($course->id), $event->get_context());
$this->assertEquals($item->id, $event->objectid);
$this->assertEventContextNotUsed($event);
$eventscount++;
......
......@@ -24,6 +24,11 @@
* @since Moodle 3.2
*/
namespace auth_email\external;
use auth_email_external;
use externallib_advanced_testcase;
defined('MOODLE_INTERNAL') || die();
global $CFG;
......@@ -38,7 +43,7 @@ require_once($CFG->dirroot . '/webservice/tests/helpers.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.2
*/
class auth_email_external_testcase extends externallib_advanced_testcase {
class external_test extends externallib_advanced_testcase {
/**
* Set up for every test
......@@ -65,7 +70,7 @@ class auth_email_external_testcase extends externallib_advanced_testcase {
$CFG->sitepolicy = 'https://moodle.org';
$result = auth_email_external::get_signup_settings();
$result = external_api::clean_returnvalue(auth_email_external::get_signup_settings_returns(), $result);
$result = \external_api::clean_returnvalue(auth_email_external::get_signup_settings_returns(), $result);
// Check expected data.
$this->assertEquals(array('firstname', 'lastname'), $result['namefields']);
......@@ -114,10 +119,10 @@ class auth_email_external_testcase extends externallib_advanced_testcase {
'datatype' => 'textarea', 'signup' => 1, 'visible' => 1, 'required' => 1, 'sortorder' => 2));
$result = auth_email_external::get_signup_settings();
$result = external_api::clean_returnvalue(auth_email_external::get_signup_settings_returns(), $result);
$result = \external_api::clean_returnvalue(auth_email_external::get_signup_settings_returns(), $result);
// Format the original data.
$sitecontext = context_system::instance();
$sitecontext = \context_system::instance();
$categoryname = external_format_string($categoryname, $sitecontext->id);
$fieldname = external_format_string($fieldname, $sitecontext->id);
......@@ -168,7 +173,7 @@ class auth_email_external_testcase extends externallib_advanced_testcase {
// Create new user.
$result = auth_email_external::signup_user($username, $password, $firstname, $lastname, $email, $city, $country,
'', '', $customprofilefields);
$result = external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$result = \external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$this->assertTrue($result['success']);
$this->assertEmpty($result['warnings']);
$user = $DB->get_record('user', array('username' => $username));
......@@ -189,7 +194,7 @@ class auth_email_external_testcase extends externallib_advanced_testcase {
$password = 'abc';
$result = auth_email_external::signup_user($username, $password, $firstname, $lastname, $email, $city, $country,
'', '', $customprofilefields);
$result = external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$result = \external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$this->assertFalse($result['success']);
$this->assertCount(3, $result['warnings']);
$expectederrors = array('username', 'email', 'password');
......
......@@ -24,6 +24,12 @@
* @since Moodle 3.2
*/
namespace core_auth\external;
use auth_email_external;
use core_auth_external;
use externallib_advanced_testcase;
defined('MOODLE_INTERNAL') || die();
global $CFG;
......@@ -38,7 +44,7 @@ require_once($CFG->dirroot . '/webservice/tests/helpers.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.2
*/
class core_auth_external_testcase extends externallib_advanced_testcase {
class external_test extends externallib_advanced_testcase {
/** @var string Original error log */
protected $oldlog;
......@@ -79,14 +85,14 @@ class core_auth_external_testcase extends externallib_advanced_testcase {
// Create new user.
$result = auth_email_external::signup_user($username, $password, $firstname, $lastname, $email);
$result = external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$result = \external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$this->assertTrue($result['success']);
$this->assertEmpty($result['warnings']);
$secret = $DB->get_field('user', 'secret', array('username' => $username));
// Confirm the user.
$result = core_auth_external::confirm_user($username, $secret);
$result = external_api::clean_returnvalue(core_auth_external::confirm_user_returns(), $result);
$result = \external_api::clean_returnvalue(core_auth_external::confirm_user_returns(), $result);
$this->assertTrue($result['success']);
$this->assertEmpty($result['warnings']);
$confirmed = $DB->get_field('user', 'confirmed', array('username' => $username));
......@@ -94,13 +100,13 @@ class core_auth_external_testcase extends externallib_advanced_testcase {
// Try to confirm the user again.
$result = core_auth_external::confirm_user($username, $secret);
$result = external_api::clean_returnvalue(core_auth_external::confirm_user_returns(), $result);
$result = \external_api::clean_returnvalue(core_auth_external::confirm_user_returns(), $result);
$this->assertFalse($result['success']);
$this->assertCount(1, $result['warnings']);
$this->assertEquals('alreadyconfirmed', $result['warnings'][0]['warningcode']);
// Try to use an invalid secret.
$this->expectException('moodle_exception');
$this->expectException('\moodle_exception');
$this->expectExceptionMessage(get_string('invalidconfirmdata', 'error'));
$result = core_auth_external::confirm_user($username, 'zzZZzz');
}
......@@ -113,7 +119,7 @@ class core_auth_external_testcase extends externallib_advanced_testcase {
$CFG->agedigitalconsentverification = 0;
$result = core_auth_external::is_age_digital_consent_verification_enabled();
$result = external_api::clean_returnvalue(
$result = \external_api::clean_returnvalue(
core_auth_external::is_age_digital_consent_verification_enabled_returns(), $result);
$this->assertFalse($result['status']);
}
......@@ -126,7 +132,7 @@ class core_auth_external_testcase extends externallib_advanced_testcase {
$CFG->agedigitalconsentverification = 1;
$result = core_auth_external::is_age_digital_consent_verification_enabled();
$result = external_api::clean_returnvalue(
$result = \external_api::clean_returnvalue(
core_auth_external::is_age_digital_consent_verification_enabled_returns(), $result);
$this->assertTrue($result['status']);
}
......@@ -145,12 +151,12 @@ class core_auth_external_testcase extends externallib_advanced_testcase {
// Create new user.
$result = auth_email_external::signup_user($username, $password, $firstname, $lastname, $email);
$result = external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$result = \external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$this->assertTrue($result['success']);
$this->assertEmpty($result['warnings']);
$result = core_auth_external::resend_confirmation_email($username, $password);
$result = external_api::clean_returnvalue(core_auth_external::resend_confirmation_email_returns(), $result);
$result = \external_api::clean_returnvalue(core_auth_external::resend_confirmation_email_returns(), $result);
$this->assertTrue($result['status']);
$this->assertEmpty($result['warnings']);
$confirmed = $DB->get_field('user', 'confirmed', array('username' => $username));
......@@ -170,12 +176,12 @@ class core_auth_external_testcase extends externallib_advanced_testcase {
// Create new user.
$result = auth_email_external::signup_user($username, $password, $firstname, $lastname, $email);
$result = external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$result = \external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$this->assertTrue($result['success']);
$this->assertEmpty($result['warnings']);
$_SERVER['HTTP_USER_AGENT'] = 'no browser'; // Hack around missing user agent in CLI scripts.
$this->expectException('moodle_exception');
$this->expectException('\moodle_exception');
$this->expectExceptionMessage('error/invalidlogin');
$result = core_auth_external::resend_confirmation_email('abc', $password);
}
......@@ -193,12 +199,12 @@ class core_auth_external_testcase extends externallib_advanced_testcase {
// Create new user.
$result = auth_email_external::signup_user($username, $password, $firstname, $lastname, $email);
$result = external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$result = \external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$this->assertTrue($result['success']);
$this->assertEmpty($result['warnings']);
$_SERVER['HTTP_USER_AGENT'] = 'no browser'; // Hack around missing user agent in CLI scripts.
$this->expectException('moodle_exception');
$this->expectException('\moodle_exception');
$this->expectExceptionMessage('error/invalidlogin');
$result = core_auth_external::resend_confirmation_email($username, 'abc');
}
......@@ -217,17 +223,17 @@ class core_auth_external_testcase extends externallib_advanced_testcase {
// Create new user.
$result = auth_email_external::signup_user($username, $password, $firstname, $lastname, $email);
$result = external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$result = \external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$this->assertTrue($result['success']);
$this->assertEmpty($result['warnings']);
$secret = $DB->get_field('user', 'secret', array('username' => $username));
// Confirm the user.
$result = core_auth_external::confirm_user($username, $secret);
$result = external_api::clean_returnvalue(core_auth_external::confirm_user_returns(), $result);
$result = \external_api::clean_returnvalue(core_auth_external::confirm_user_returns(), $result);
$this->assertTrue($result['success']);
$this->expectException('moodle_exception');
$this->expectException('\moodle_exception');
$this->expectExceptionMessage('error/alreadyconfirmed');
core_auth_external::resend_confirmation_email($username, $password);
}
......
......@@ -24,6 +24,11 @@
* @since Moodle 3.1
*/
namespace core_badges\external;
use core_badges_external;
use externallib_advanced_testcase;
defined('MOODLE_INTERNAL') || die();
global $CFG;
......@@ -40,7 +45,7 @@ require_once($CFG->libdir . '/badgeslib.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.1
*/
class core_badges_external_testcase extends externallib_advanced_testcase {
class external_test extends externallib_advanced_testcase {
/** @var stdClass $course */
private $course;
......@@ -68,7 +73,7 @@ class core_badges_external_testcase extends externallib_advanced_testcase {