forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-80693 core_user: search() fails if no standard identify fields
- Loading branch information
1 parent
810554e
commit 975daef
Showing
2 changed files
with
50 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
/** | ||
* Test core_user class. | ||
* | ||
* @covers \core_user | ||
* @package core | ||
* @copyright 2013 Rajesh Taneja <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
|
@@ -283,6 +284,36 @@ public function test_search() { | |
$this->assertCount(1, $result); | ||
} | ||
|
||
/** | ||
* The search function had a bug where it failed if you have no identify fields (or only custom | ||
* ones). | ||
*/ | ||
public function test_search_no_identity_fields(): void { | ||
self::init_search_tests(); | ||
|
||
// Set no user identity fields. | ||
set_config('showuseridentity', ''); | ||
|
||
// Set up course for test with teacher in. | ||
$generator = $this->getDataGenerator(); | ||
$course = $generator->create_course(); | ||
$teacher = $generator->create_user(['firstname' => 'Alberto', 'lastname' => 'Unwin', | ||
'email' => '[email protected]']); | ||
$generator->enrol_user($teacher->id, $course->id, 'teacher'); | ||
|
||
// Admin user has site-wide permissions, this uses one variant of the query. | ||
$this->setAdminUser(); | ||
$result = \core_user::search('Al'); | ||
$this->assertCount(1, $result); | ||
$this->assertEquals('Alberto', $result[0]->firstname); | ||
|
||
// Teacher has course-wide permissions, this uses another variant. | ||
$this->setUser($teacher); | ||
$result = \core_user::search('Al'); | ||
$this->assertCount(1, $result); | ||
$this->assertEquals('Alberto', $result[0]->firstname); | ||
} | ||
|
||
/** | ||
* Tests the search() function with limits on the number to return. | ||
*/ | ||
|