mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 02:16:41 +02:00
Merge branch 'MDL-29318-master' of git://github.com/junpataleta/moodle
This commit is contained in:
commit
48fa567da2
5 changed files with 77 additions and 15 deletions
|
@ -4313,6 +4313,27 @@ class core_moodlelib_testcase extends advanced_testcase {
|
|||
'Fetch data using an invalid username' => [
|
||||
'username', 's2', false
|
||||
],
|
||||
'Fetch by email' => [
|
||||
'email', 's1@example.com', true
|
||||
],
|
||||
'Fetch data using a non-existent email' => [
|
||||
'email', 's2@example.com', false
|
||||
],
|
||||
'Fetch data using a non-existent email, throw exception' => [
|
||||
'email', 's2@example.com', false, dml_missing_record_exception::class
|
||||
],
|
||||
'Multiple accounts with the same email' => [
|
||||
'email', 's1@example.com', false, 1
|
||||
],
|
||||
'Multiple accounts with the same email, throw exception' => [
|
||||
'email', 's1@example.com', false, 1, dml_multiple_records_exception::class
|
||||
],
|
||||
'Fetch data using a valid user ID' => [
|
||||
'id', true, true
|
||||
],
|
||||
'Fetch data using a non-existent user ID' => [
|
||||
'id', false, false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -4323,10 +4344,15 @@ class core_moodlelib_testcase extends advanced_testcase {
|
|||
* @param string $field The field to use for the query.
|
||||
* @param string|boolean $value The field value. When fetching by ID, set true to fetch valid user ID, false otherwise.
|
||||
* @param boolean $success Whether we expect for the fetch to succeed or return false.
|
||||
* @param int $allowaccountssameemail Value for $CFG->allowaccountssameemail.
|
||||
* @param string $expectedexception The exception to be expected.
|
||||
*/
|
||||
public function test_get_complete_user_data($field, $value, $success) {
|
||||
public function test_get_complete_user_data($field, $value, $success, $allowaccountssameemail = 0, $expectedexception = '') {
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Set config settings we need for our environment.
|
||||
set_config('allowaccountssameemail', $allowaccountssameemail);
|
||||
|
||||
// Generate the user data.
|
||||
$generator = $this->getDataGenerator();
|
||||
$userdata = [
|
||||
|
@ -4335,6 +4361,11 @@ class core_moodlelib_testcase extends advanced_testcase {
|
|||
];
|
||||
$user = $generator->create_user($userdata);
|
||||
|
||||
if ($allowaccountssameemail) {
|
||||
// Create another user with the same email address.
|
||||
$generator->create_user(['email' => 's1@example.com']);
|
||||
}
|
||||
|
||||
// Since the data provider can't know what user ID to use, do a special handling for ID field tests.
|
||||
if ($field === 'id') {
|
||||
if ($value) {
|
||||
|
@ -4345,7 +4376,15 @@ class core_moodlelib_testcase extends advanced_testcase {
|
|||
$value = $user->id + 1;
|
||||
}
|
||||
}
|
||||
$fetcheduser = get_complete_user_data($field, $value);
|
||||
|
||||
// When an exception is expected.
|
||||
$throwexception = false;
|
||||
if ($expectedexception) {
|
||||
$this->expectException($expectedexception);
|
||||
$throwexception = true;
|
||||
}
|
||||
|
||||
$fetcheduser = get_complete_user_data($field, $value, null, $throwexception);
|
||||
if ($success) {
|
||||
$this->assertEquals($user->id, $fetcheduser->id);
|
||||
$this->assertEquals($user->username, $fetcheduser->username);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue