Replace deprecated annotations

This commit is contained in:
Dmitrii Metelkin 2022-08-19 10:08:02 +10:00
parent 0341b05f99
commit 78ec637899
3 changed files with 95 additions and 91 deletions

View file

@ -185,62 +185,58 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
/** /**
* Test that auth plugin throws correct exception if default mapping field is not provided. * Test that auth plugin throws correct exception if default mapping field is not provided.
*
* @expectedException \invalid_parameter_exception
* @expectedExceptionMessage Invalid parameter value detected (Required field "email" is not set or empty.)
*/ */
public function test_throwing_exception_if_default_mapping_field_is_not_provided() { public function test_throwing_exception_if_default_mapping_field_is_not_provided() {
$user = array(); $user = array();
$this->expectException(invalid_parameter_exception::class);
$this->expectExceptionMessage('Invalid parameter value detected (Required field "email" is not set or empty.)');
$actual = $this->auth->get_login_url($user); $actual = $this->auth->get_login_url($user);
} }
/** /**
* Test that auth plugin throws correct exception if username mapping field is not provided, but set in configs. * Test that auth plugin throws correct exception if username mapping field is not provided, but set in configs.
*
* @expectedException \invalid_parameter_exception
* @expectedExceptionMessage Invalid parameter value detected (Required field "username" is not set or empty.)
*/ */
public function test_throwing_exception_if_mapping_field_username_is_not_provided() { public function test_throwing_exception_if_mapping_field_username_is_not_provided() {
$user = array(); $user = array();
set_config('mappingfield', 'username', 'auth_userkey'); set_config('mappingfield', 'username', 'auth_userkey');
$this->auth = new auth_plugin_userkey(); $this->auth = new auth_plugin_userkey();
$this->expectException(invalid_parameter_exception::class);
$this->expectExceptionMessage('Invalid parameter value detected (Required field "username" is not set or empty.)');
$actual = $this->auth->get_login_url($user); $actual = $this->auth->get_login_url($user);
} }
/** /**
* Test that auth plugin throws correct exception if idnumber mapping field is not provided, but set in configs. * Test that auth plugin throws correct exception if idnumber mapping field is not provided, but set in configs.
*
* @expectedException \invalid_parameter_exception
* @expectedExceptionMessage Invalid parameter value detected (Required field "idnumber" is not set or empty.)
*/ */
public function test_throwing_exception_if_mapping_field_idnumber_is_not_provided() { public function test_throwing_exception_if_mapping_field_idnumber_is_not_provided() {
$user = array(); $user = array();
set_config('mappingfield', 'idnumber', 'auth_userkey'); set_config('mappingfield', 'idnumber', 'auth_userkey');
$this->auth = new auth_plugin_userkey(); $this->auth = new auth_plugin_userkey();
$this->expectException(invalid_parameter_exception::class);
$this->expectExceptionMessage('Invalid parameter value detected (Required field "idnumber" is not set or empty.)');
$actual = $this->auth->get_login_url($user); $actual = $this->auth->get_login_url($user);
} }
/** /**
* Test that auth plugin throws correct exception if we trying to request not existing user. * Test that auth plugin throws correct exception if we trying to request not existing user.
*
* @expectedException \invalid_parameter_exception
* @expectedExceptionMessage Invalid parameter value detected (User is not exist)
*/ */
public function test_throwing_exception_if_user_is_not_exist() { public function test_throwing_exception_if_user_is_not_exist() {
$user = array(); $user = array();
$user['email'] = 'notexists@test.com'; $user['email'] = 'notexists@test.com';
$this->expectException(invalid_parameter_exception::class);
$this->expectExceptionMessage('Invalid parameter value detected (User is not exist)');
$actual = $this->auth->get_login_url($user); $actual = $this->auth->get_login_url($user);
} }
/** /**
* Test that auth plugin throws correct exception if we trying to request user, * Test that auth plugin throws correct exception if we trying to request user,
* but ip field is not set and iprestriction is enabled. * but ip field is not set and iprestriction is enabled.
*
* @expectedException \invalid_parameter_exception
* @expectedExceptionMessage Invalid parameter value detected (Required parameter "ip" is not set.)
*/ */
public function test_throwing_exception_if_iprestriction_is_enabled_but_ip_is_missing_in_data() { public function test_throwing_exception_if_iprestriction_is_enabled_but_ip_is_missing_in_data() {
$user = array(); $user = array();
@ -248,6 +244,9 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
set_config('iprestriction', true, 'auth_userkey'); set_config('iprestriction', true, 'auth_userkey');
$this->auth = new auth_plugin_userkey(); $this->auth = new auth_plugin_userkey();
$this->expectException(invalid_parameter_exception::class);
$this->expectExceptionMessage('Invalid parameter value detected (Required parameter "ip" is not set.)');
$actual = $this->auth->get_login_url($user); $actual = $this->auth->get_login_url($user);
} }
@ -349,11 +348,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
/** /**
* Test that we can request a key for a new user. * Test that we can request a key for a new user.
*
* @expectedException \invalid_parameter_exception
* @expectedExceptionMessage Unable to create user, missing value(s): username,firstname,lastname
*/ */
public function test_missing_data_to_create_user() { public function test_missing_data_to_create_user() {
global $CFG, $DB; global $CFG, $DB;
@ -367,13 +362,14 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
$user->email = 'username@test.com'; $user->email = 'username@test.com';
$user->ip = '192.168.1.1'; $user->ip = '192.168.1.1';
$this->expectException(invalid_parameter_exception::class);
$this->expectExceptionMessage('Unable to create user, missing value(s): username,firstname,lastname');
$this->auth->get_login_url($user); $this->auth->get_login_url($user);
} }
/** /**
* Test that when we attempt to create a new user duplicate usernames are caught. * Test that when we attempt to create a new user duplicate usernames are caught.
* @expectedException \invalid_parameter_exception
* @expectedExceptionMessage Username already exists: username
*/ */
public function test_create_refuse_duplicate_username() { public function test_create_refuse_duplicate_username() {
set_config('createuser', true, 'auth_userkey'); set_config('createuser', true, 'auth_userkey');
@ -395,14 +391,14 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
$duplicateuser = clone($originaluser); $duplicateuser = clone($originaluser);
$duplicateuser->email = 'duplicateuser@test.com'; $duplicateuser->email = 'duplicateuser@test.com';
$this->expectException(invalid_parameter_exception::class);
$this->expectExceptionMessage('Username already exists: username');
$this->auth->get_login_url($duplicateuser); $this->auth->get_login_url($duplicateuser);
} }
/** /**
* Test that when we attempt to create a new user duplicate emails are caught. * Test that when we attempt to create a new user duplicate emails are caught.
*
* @expectedException \invalid_parameter_exception
* @expectedExceptionMessage Email address already exists: username@test.com
*/ */
public function test_create_refuse_duplicate_email() { public function test_create_refuse_duplicate_email() {
set_config('createuser', true, 'auth_userkey'); set_config('createuser', true, 'auth_userkey');
@ -425,6 +421,9 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
$duplicateuser = clone($originaluser); $duplicateuser = clone($originaluser);
$duplicateuser->username = 'duplicateuser'; $duplicateuser->username = 'duplicateuser';
$this->expectException(invalid_parameter_exception::class);
$this->expectExceptionMessage('Email address already exists: username@test.com');
$this->auth->get_login_url($duplicateuser); $this->auth->get_login_url($duplicateuser);
} }
@ -472,9 +471,6 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
/** /**
* Test that when we attempt to update a user duplicate emails are caught. * Test that when we attempt to update a user duplicate emails are caught.
*
* @expectedException \invalid_parameter_exception
* @expectedExceptionMessage Email address already exists: trytoduplicate@test.com
*/ */
public function test_update_refuse_duplicate_email() { public function test_update_refuse_duplicate_email() {
set_config('updateuser', true, 'auth_userkey'); set_config('updateuser', true, 'auth_userkey');
@ -495,14 +491,14 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
$originaluser->city = 'brighton'; $originaluser->city = 'brighton';
$originaluser->ip = '192.168.1.1'; $originaluser->ip = '192.168.1.1';
$this->expectException(invalid_parameter_exception::class);
$this->expectExceptionMessage('Email address already exists: trytoduplicate@test.com');
$this->auth->get_login_url($originaluser); $this->auth->get_login_url($originaluser);
} }
/** /**
* Test that when we attempt to update a user duplicate usernames are caught. * Test that when we attempt to update a user duplicate usernames are caught.
*
* @expectedException \invalid_parameter_exception
* @expectedExceptionMessage Username already exists: trytoduplicate
*/ */
public function test_update_refuse_duplicate_username() { public function test_update_refuse_duplicate_username() {
set_config('updateuser', true, 'auth_userkey'); set_config('updateuser', true, 'auth_userkey');
@ -522,6 +518,9 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
$originaluser->city = 'brighton'; $originaluser->city = 'brighton';
$originaluser->ip = '192.168.1.1'; $originaluser->ip = '192.168.1.1';
$this->expectException(invalid_parameter_exception::class);
$this->expectExceptionMessage('Username already exists: trytoduplicate');
$this->auth->get_login_url($originaluser); $this->auth->get_login_url($originaluser);
} }
@ -693,57 +692,55 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
/** /**
* Test required parameter exception gets thrown id try to login, but key is not set. * Test required parameter exception gets thrown id try to login, but key is not set.
*
* @expectedException moodle_exception
* @expectedExceptionMessage A required parameter (key) was missing
*/ */
public function test_required_parameter_exception_thrown_if_key_not_set() { public function test_required_parameter_exception_thrown_if_key_not_set() {
$this->expectException(moodle_exception::class);
$this->expectExceptionMessage('A required parameter (key) was missing');
$this->auth->user_login_userkey(); $this->auth->user_login_userkey();
} }
/** /**
* Test that incorrect key exception gets thrown if a key is incorrect. * Test that incorrect key exception gets thrown if a key is incorrect.
*
* @expectedException moodle_exception
* @expectedExceptionMessage Incorrect key
*/ */
public function test_invalid_key_exception_thrown_if_invalid_key() { public function test_invalid_key_exception_thrown_if_invalid_key() {
$this->expectException(moodle_exception::class);
$this->expectExceptionMessage('Incorrect key');
$_POST['key'] = 'InvalidKey'; $_POST['key'] = 'InvalidKey';
$this->auth->user_login_userkey(); $this->auth->user_login_userkey();
} }
/** /**
* Test that expired key exception gets thrown if a key is expired. * Test that expired key exception gets thrown if a key is expired.
*
* @expectedException moodle_exception
* @expectedExceptionMessage Expired key
*/ */
public function test_expired_key_exception_thrown_if_expired_key() { public function test_expired_key_exception_thrown_if_expired_key() {
$this->create_user_private_key(['validuntil' => time() - 3000]); $this->create_user_private_key(['validuntil' => time() - 3000]);
$this->expectException(moodle_exception::class);
$this->expectExceptionMessage('Expired key');
$_POST['key'] = 'TestKey'; $_POST['key'] = 'TestKey';
$this->auth->user_login_userkey(); $this->auth->user_login_userkey();
} }
/** /**
* Test that IP address mismatch exception gets thrown if incorrect IP. * Test that IP address mismatch exception gets thrown if incorrect IP.
*
* @expectedException moodle_exception
* @expectedExceptionMessage Client IP address mismatch
*/ */
public function test_ipmismatch_exception_thrown_if_ip_is_incorrect() { public function test_ipmismatch_exception_thrown_if_ip_is_incorrect() {
$this->create_user_private_key(['iprestriction' => '192.168.1.1']); $this->create_user_private_key(['iprestriction' => '192.168.1.1']);
$_POST['key'] = 'TestKey'; $_POST['key'] = 'TestKey';
$_SERVER['HTTP_CLIENT_IP'] = '192.168.1.2'; $_SERVER['HTTP_CLIENT_IP'] = '192.168.1.2';
$this->expectException(moodle_exception::class);
$this->expectExceptionMessage('Client IP address mismatch');
$this->auth->user_login_userkey(); $this->auth->user_login_userkey();
} }
/** /**
* Test that IP address mismatch exception gets thrown if incorrect IP and outside whitelist. * Test that IP address mismatch exception gets thrown if incorrect IP and outside whitelist.
*
* @expectedException moodle_exception
* @expectedExceptionMessage Client IP address mismatch
*/ */
public function test_ipmismatch_exception_thrown_if_ip_is_outside_whitelist() { public function test_ipmismatch_exception_thrown_if_ip_is_outside_whitelist() {
set_config('ipwhitelist', '10.0.0.0/8;172.16.0.0/12;192.168.0.0/16', 'auth_userkey'); set_config('ipwhitelist', '10.0.0.0/8;172.16.0.0/12;192.168.0.0/16', 'auth_userkey');
@ -751,14 +748,15 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
$_POST['key'] = 'TestKey'; $_POST['key'] = 'TestKey';
$_SERVER['HTTP_CLIENT_IP'] = '192.161.1.2'; $_SERVER['HTTP_CLIENT_IP'] = '192.161.1.2';
$this->expectException(moodle_exception::class);
$this->expectExceptionMessage('Client IP address mismatch');
$this->auth->user_login_userkey(); $this->auth->user_login_userkey();
} }
/** /**
* Test that IP address mismatch exception gets thrown if user id is incorrect. * Test that IP address mismatch exception gets thrown if user id is incorrect.
*
* @expectedException moodle_exception
* @expectedExceptionMessageRegExp /Invalid user id/i
*/ */
public function test_invalid_user_exception_thrown_if_user_is_invalid() { public function test_invalid_user_exception_thrown_if_user_is_invalid() {
$this->create_user_private_key([ $this->create_user_private_key([
@ -769,6 +767,10 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
$_POST['key'] = 'TestKey'; $_POST['key'] = 'TestKey';
$_SERVER['HTTP_CLIENT_IP'] = '192.168.1.1'; $_SERVER['HTTP_CLIENT_IP'] = '192.168.1.1';
$this->expectException(moodle_exception::class);
$this->expectExceptionMessage('Invalid user');
$this->auth->user_login_userkey(); $this->auth->user_login_userkey();
} }
@ -797,9 +799,6 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
/** /**
* Test that a user logs in and gets redirected correctly. * Test that a user logs in and gets redirected correctly.
*
* @expectedException moodle_exception
* @expectedExceptionMessage Unsupported redirect to http://www.example.com/moodle detected, execution terminated.
*/ */
public function test_that_user_logged_in_and_redirected() { public function test_that_user_logged_in_and_redirected() {
global $CFG; global $CFG;
@ -807,6 +806,10 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
$this->create_user_private_key(); $this->create_user_private_key();
$CFG->wwwroot = 'http://www.example.com/moodle'; $CFG->wwwroot = 'http://www.example.com/moodle';
$_POST['key'] = 'TestKey'; $_POST['key'] = 'TestKey';
$this->expectException(moodle_exception::class);
$this->expectExceptionMessage('Unsupported redirect to http://www.example.com/moodle detected, execution terminated');
@$this->auth->user_login_userkey(); @$this->auth->user_login_userkey();
} }
@ -832,25 +835,21 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
/** /**
* Test that a user gets redirected to internal wantsurl URL successful log in. * Test that a user gets redirected to internal wantsurl URL successful log in.
*
* @expectedException moodle_exception
* @expectedExceptionMessage Unsupported redirect to /course/index.php?id=12&key=134 detected, execution terminated.
*/ */
public function test_that_user_gets_redirected_to_internal_wantsurl() { public function test_that_user_gets_redirected_to_internal_wantsurl() {
$this->create_user_private_key(); $this->create_user_private_key();
$_POST['key'] = 'TestKey'; $_POST['key'] = 'TestKey';
$_POST['wantsurl'] = '/course/index.php?id=12&key=134'; $_POST['wantsurl'] = '/course/index.php?id=12&key=134';
$this->expectException(moodle_exception::class);
$this->expectExceptionMessage('Unsupported redirect to /course/index.php?id=12&key=134 detected, execution terminated');
// Using @ is the only way to test this. Thanks moodle! // Using @ is the only way to test this. Thanks moodle!
@$this->auth->user_login_userkey(); @$this->auth->user_login_userkey();
} }
/** /**
* Test that a user gets redirected to external wantsurl URL successful log in. * Test that a user gets redirected to external wantsurl URL successful log in.
*
* @expectedException moodle_exception
* @expectedExceptionMessage Unsupported redirect to http://test.com/course/index.php?id=12&key=134 detected,
* execution terminated.
*/ */
public function test_that_user_gets_redirected_to_external_wantsurl() { public function test_that_user_gets_redirected_to_external_wantsurl() {
$this->create_user_private_key(); $this->create_user_private_key();
@ -858,15 +857,15 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
$_POST['key'] = 'TestKey'; $_POST['key'] = 'TestKey';
$_POST['wantsurl'] = 'http://test.com/course/index.php?id=12&key=134'; $_POST['wantsurl'] = 'http://test.com/course/index.php?id=12&key=134';
$this->expectException(moodle_exception::class);
$this->expectExceptionMessage('Unsupported redirect to http://test.com/course/index.php?id=12&key=134 detected, execution terminated');
// Using @ is the only way to test this. Thanks moodle! // Using @ is the only way to test this. Thanks moodle!
@$this->auth->user_login_userkey(); @$this->auth->user_login_userkey();
} }
/** /**
* Test that login hook redirects a user if skipsso not set and ssourl is set. * Test that login hook redirects a user if skipsso not set and ssourl is set.
*
* @expectedException moodle_exception
* @expectedExceptionMessage Unsupported redirect to http://google.com detected, execution terminated.
*/ */
public function test_loginpage_hook_redirects_if_skipsso_not_set_and_ssourl_set() { public function test_loginpage_hook_redirects_if_skipsso_not_set_and_ssourl_set() {
global $SESSION; global $SESSION;
@ -875,6 +874,9 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
set_config('ssourl', 'http://google.com', 'auth_userkey'); set_config('ssourl', 'http://google.com', 'auth_userkey');
$this->auth = new auth_plugin_userkey(); $this->auth = new auth_plugin_userkey();
$this->expectException(moodle_exception::class);
$this->expectExceptionMessage('Unsupported redirect to http://google.com detected, execution terminated.');
$this->auth->loginpage_hook(); $this->auth->loginpage_hook();
} }
@ -906,9 +908,6 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
/** /**
* Test that pre login hook redirects a user if skipsso not set and ssourl is set. * Test that pre login hook redirects a user if skipsso not set and ssourl is set.
*
* @expectedException moodle_exception
* @expectedExceptionMessage Unsupported redirect to http://google.com detected, execution terminated.
*/ */
public function test_pre_loginpage_hook_redirects_if_skipsso_not_set_and_ssourl_set() { public function test_pre_loginpage_hook_redirects_if_skipsso_not_set_and_ssourl_set() {
global $SESSION; global $SESSION;
@ -917,6 +916,9 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
set_config('ssourl', 'http://google.com', 'auth_userkey'); set_config('ssourl', 'http://google.com', 'auth_userkey');
$this->auth = new auth_plugin_userkey(); $this->auth = new auth_plugin_userkey();
$this->expectException(moodle_exception::class);
$this->expectExceptionMessage('Unsupported redirect to http://google.com detected, execution terminated.');
$this->auth->pre_loginpage_hook(); $this->auth->pre_loginpage_hook();
} }
@ -1021,23 +1023,23 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
/** /**
* Test when try to logout, but required return is not set. * Test when try to logout, but required return is not set.
*
* @expectedException moodle_exception
* @expectedExceptionMessage A required parameter (return) was missing
*/ */
public function test_user_logout_userkey_when_required_return_not_set() { public function test_user_logout_userkey_when_required_return_not_set() {
$this->expectException(moodle_exception::class);
$this->expectExceptionMessage('A required parameter (return) was missing');
$this->auth->user_logout_userkey(); $this->auth->user_logout_userkey();
} }
/** /**
* Test when try to logout, but user is not logged in. * Test when try to logout, but user is not logged in.
*
* @expectedException moodle_exception
* @expectedExceptionMessage Unsupported redirect to http://google.com detected, execution terminated.
*/ */
public function test_user_logout_userkey_when_user_is_not_logged_in() { public function test_user_logout_userkey_when_user_is_not_logged_in() {
$_POST['return'] = 'http://google.com'; $_POST['return'] = 'http://google.com';
$this->expectException(moodle_exception::class);
$this->expectExceptionMessage('Unsupported redirect to http://google.com detected, execution terminated.');
$this->auth->user_logout_userkey(); $this->auth->user_logout_userkey();
} }
@ -1064,12 +1066,13 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
/** /**
* Test when try to logout, but user logged in with different auth type. * Test when try to logout, but user logged in with different auth type.
*
* @expectedException moodle_exception
* @expectedExceptionMessage A required parameter (return) was missing
*/ */
public function test_user_logout_userkey_when_user_logged_in_but_return_not_set() { public function test_user_logout_userkey_when_user_logged_in_but_return_not_set() {
$this->setUser($this->user); $this->setUser($this->user);
$this->expectException(moodle_exception::class);
$this->expectExceptionMessage('A required parameter (return) was missing');
$this->auth->user_logout_userkey(); $this->auth->user_logout_userkey();
} }

View file

@ -154,9 +154,6 @@ class core_userkey_manager_testcase extends advanced_testcase {
/** /**
* Test that IP address mismatch exception gets thrown if incorrect IP and outside whitelist. * Test that IP address mismatch exception gets thrown if incorrect IP and outside whitelist.
*
* @expectedException moodle_exception
* @expectedExceptionMessage Client IP address mismatch
*/ */
public function test_exception_if_ip_is_outside_whitelist() { public function test_exception_if_ip_is_outside_whitelist() {
global $DB; global $DB;
@ -169,6 +166,9 @@ class core_userkey_manager_testcase extends advanced_testcase {
$_SERVER['HTTP_CLIENT_IP'] = '193.168.1.2'; $_SERVER['HTTP_CLIENT_IP'] = '193.168.1.2';
$this->expectException(moodle_exception::class);
$this->expectExceptionMessage('Client IP address mismatch');
$manager->validate_key($value); $manager->validate_key($value);
} }

View file

@ -50,9 +50,6 @@ class auth_userkey_externallib_testcase extends advanced_testcase {
/** /**
* Test call with incorrect required parameter. * Test call with incorrect required parameter.
*
* @expectedException webservice_access_exception
* @expectedExceptionMessage Access control exception (The userkey authentication plugin is disabled.)
*/ */
public function test_throwing_plugin_disabled_exception() { public function test_throwing_plugin_disabled_exception() {
$this->setAdminUser(); $this->setAdminUser();
@ -60,6 +57,10 @@ class auth_userkey_externallib_testcase extends advanced_testcase {
$params = array( $params = array(
'bla' => 'exists@test.com', 'bla' => 'exists@test.com',
); );
$this->expectException(webservice_access_exception::class);
$this->expectExceptionMessage('Access control exception (The userkey authentication plugin is disabled.)');
// Simulate the web service server. // Simulate the web service server.
$result = auth_userkey_external::request_login_url($params); $result = auth_userkey_external::request_login_url($params);
$result = external_api::clean_returnvalue(auth_userkey_external::request_login_url_returns(), $result); $result = external_api::clean_returnvalue(auth_userkey_external::request_login_url_returns(), $result);
@ -146,9 +147,6 @@ class auth_userkey_externallib_testcase extends advanced_testcase {
/** /**
* Test call with missing email required parameter. * Test call with missing email required parameter.
*
* @expectedException invalid_parameter_exception
* @expectedExceptionMessage Invalid parameter value detected (Required field "email" is not set or empty.)
*/ */
public function test_exception_thrown_if_required_parameter_email_is_not_set() { public function test_exception_thrown_if_required_parameter_email_is_not_set() {
global $CFG; global $CFG;
@ -160,14 +158,14 @@ class auth_userkey_externallib_testcase extends advanced_testcase {
'bla' => 'exists@test.com', 'bla' => 'exists@test.com',
); );
$this->expectException(invalid_parameter_exception::class);
$this->expectExceptionMessage('Invalid parameter value detected (Required field "email" is not set or empty.)');
auth_userkey_external::request_login_url($params); auth_userkey_external::request_login_url($params);
} }
/** /**
* Test call with missing ip required parameter. * Test call with missing ip required parameter.
*
* @expectedException invalid_parameter_exception
* @expectedExceptionMessage Invalid parameter value detected (Required parameter "ip" is not set.)
*/ */
public function test_exception_thrown_if_required_parameter_op_is_not_set() { public function test_exception_thrown_if_required_parameter_op_is_not_set() {
global $CFG; global $CFG;
@ -181,14 +179,14 @@ class auth_userkey_externallib_testcase extends advanced_testcase {
'email' => 'exists@test.com', 'email' => 'exists@test.com',
); );
$this->expectException(invalid_parameter_exception::class);
$this->expectExceptionMessage('Invalid parameter value detected (Required parameter "ip" is not set.)');
auth_userkey_external::request_login_url($params); auth_userkey_external::request_login_url($params);
} }
/** /**
* Test request for a user who is not exist. * Test request for a user who is not exist.
*
* @expectedException invalid_parameter_exception
* @expectedExceptionMessage Invalid parameter value detected (User is not exist)
*/ */
public function test_request_not_existing_user() { public function test_request_not_existing_user() {
global $CFG; global $CFG;
@ -200,6 +198,9 @@ class auth_userkey_externallib_testcase extends advanced_testcase {
'email' => 'notexists@test.com', 'email' => 'notexists@test.com',
); );
$this->expectException(invalid_parameter_exception::class);
$this->expectExceptionMessage('Invalid parameter value detected (User is not exist)');
// Simulate the web service server. // Simulate the web service server.
$result = auth_userkey_external::request_login_url($params); $result = auth_userkey_external::request_login_url($params);
$result = external_api::clean_returnvalue(auth_userkey_external::request_login_url_returns(), $result); $result = external_api::clean_returnvalue(auth_userkey_external::request_login_url_returns(), $result);
@ -207,9 +208,6 @@ class auth_userkey_externallib_testcase extends advanced_testcase {
/** /**
* Test that permission exception gets thrown if user doesn't have required permissions. * Test that permission exception gets thrown if user doesn't have required permissions.
*
* @expectedException required_capability_exception
* @expectedExceptionMessage Sorry, but you do not currently have permissions to do that (Generate login user key)
*/ */
public function test_throwing_of_permission_exception() { public function test_throwing_of_permission_exception() {
global $CFG; global $CFG;
@ -221,6 +219,9 @@ class auth_userkey_externallib_testcase extends advanced_testcase {
'email' => 'notexists@test.com', 'email' => 'notexists@test.com',
); );
$this->expectException(required_capability_exception::class);
$this->expectExceptionMessage('Sorry, but you do not currently have permissions to do that (Generate login user key)');
// Simulate the web service server. // Simulate the web service server.
$result = auth_userkey_external::request_login_url($params); $result = auth_userkey_external::request_login_url($params);
$result = external_api::clean_returnvalue(auth_userkey_external::request_login_url_returns(), $result); $result = external_api::clean_returnvalue(auth_userkey_external::request_login_url_returns(), $result);