MDL-80843 reportbuilder: consistent user auth report entity data.

Tidy up unit tests for user report, removing some redundancy and
duplication.
This commit is contained in:
Paul Holden 2024-02-06 21:22:59 +00:00
parent e567c21d6e
commit d3557d9483
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164
3 changed files with 107 additions and 66 deletions

View File

@ -445,6 +445,7 @@ class user extends base {
'suspended' => new lang_string('suspended'),
'confirmed' => new lang_string('confirmed', 'admin'),
'username' => new lang_string('username'),
'auth' => new lang_string('authentication', 'moodle'),
'moodlenetprofile' => new lang_string('moodlenetprofile', 'user'),
'timecreated' => new lang_string('timecreated', 'core_reportbuilder'),
'timemodified' => new lang_string('timemodified', 'core_reportbuilder'),
@ -550,32 +551,6 @@ class user extends base {
))
->add_joins($this->get_joins());
// Authentication method filter.
$filters[] = (new filter(
select::class,
'auth',
new lang_string('authentication', 'moodle'),
$this->get_entity_name(),
"{$tablealias}.auth"
))
->add_joins($this->get_joins())
->set_options_callback(static function(): array {
$plugins = core_component::get_plugin_list('auth');
$enabled = get_string('pluginenabled', 'core_plugin');
$disabled = get_string('plugindisabled', 'core_plugin');
$authoptions = [$enabled => [], $disabled => []];
foreach ($plugins as $pluginname => $unused) {
$plugin = get_auth_plugin($pluginname);
if (is_enabled_auth($pluginname)) {
$authoptions[$enabled][$pluginname] = $plugin->get_title();
} else {
$authoptions[$disabled][$pluginname] = $plugin->get_title();
}
}
return $authoptions;
});
return $filters;
}
@ -598,6 +573,20 @@ class user extends base {
return $cached[$fieldname];
}
/**
* List of options for the field auth
*
* @return string[]
*/
public static function get_options_for_auth(): array {
$authlist = array_keys(core_component::get_plugin_list('auth'));
return array_map(
fn(string $auth) => get_auth_plugin($auth)->get_title(),
array_combine($authlist, $authlist),
);
}
/**
* List of options for the field country.
*
@ -610,7 +599,7 @@ class user extends base {
/**
* List of options for the field theme.
*
* @return array
* @return string[]
*/
public static function get_options_for_theme(): array {
return array_map(

View File

@ -55,7 +55,7 @@ class datasource_test extends advanced_testcase {
'All column' => [
[],
[],
30,
31,
],
'Include columns (picture, fullname, fullnamewithlink, fullnamewithpicture, fullnamewithpicturelink)' => [
['picture', 'fullname*'],
@ -65,7 +65,7 @@ class datasource_test extends advanced_testcase {
'Exclude columns (picture, fullname, fullnamewithlink, fullnamewithpicture, fullnamewithpicturelink)' => [
[],
['picture', 'fullname*'],
25,
26,
],
];
}

View File

@ -112,14 +112,15 @@ class users_test extends core_reportbuilder_testcase {
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:lastaccess']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:suspended']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:confirmed']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:auth']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:moodlenetprofile']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:timecreated']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:timemodified']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:lastip']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:theme']);
// Tags.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'tag:name']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'tag:namewithlink']);
// Cohort.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'cohort:name']);
@ -127,44 +128,87 @@ class users_test extends core_reportbuilder_testcase {
$content = $this->get_custom_report_content($report->get('id'));
$this->assertCount(2, $content);
[$adminrow, $userrow] = array_map('array_values', $content);
// Admin row.
[
$fullnamewithlink,
$fullnamewithpicture,
$fullnamewithpicturelink,
$picture,
$lastname,
$firstname,
] = array_values($content[0]);
$this->assertStringContainsString('Admin User', $adminrow[0]);
$this->assertStringContainsString('Admin User', $adminrow[1]);
$this->assertStringContainsString('Admin User', $adminrow[2]);
$this->assertNotEmpty($adminrow[3]);
$this->assertEquals('Admin', $adminrow[4]);
$this->assertEquals('User', $adminrow[5]);
$this->assertStringContainsString('Admin User', $fullnamewithlink);
$this->assertStringContainsString('Admin User', $fullnamewithpicture);
$this->assertStringContainsString('Admin User', $fullnamewithpicturelink);
$this->assertNotEmpty($picture);
$this->assertEquals('Admin', $lastname);
$this->assertEquals('User', $firstname);
$this->assertStringContainsString(fullname($user), $userrow[0]);
$this->assertStringContainsString(fullname($user), $userrow[1]);
$this->assertStringContainsString(fullname($user), $userrow[2]);
$this->assertNotEmpty($userrow[3]);
$this->assertEquals($user->firstname, $userrow[4]);
$this->assertEquals($user->lastname, $userrow[5]);
$this->assertEquals($user->city, $userrow[6]);
$this->assertEquals('United Kingdom', $userrow[7]);
$this->assertEquals($user->description, $userrow[8]);
$this->assertEquals($user->firstnamephonetic, $userrow[9]);
$this->assertEquals($user->lastnamephonetic, $userrow[10]);
$this->assertEquals($user->middlename, $userrow[11]);
$this->assertEquals($user->alternatename, $userrow[12]);
$this->assertEquals($user->idnumber, $userrow[13]);
$this->assertEquals($user->institution, $userrow[14]);
$this->assertEquals($user->department, $userrow[15]);
$this->assertEquals($user->phone1, $userrow[16]);
$this->assertEquals($user->phone2, $userrow[17]);
$this->assertEquals($user->address, $userrow[18]);
$this->assertEmpty($userrow[19]);
$this->assertEquals('No', $userrow[20]);
$this->assertEquals('Yes', $userrow[21]);
$this->assertEquals($user->moodlenetprofile, $userrow[22]);
$this->assertNotEmpty($userrow[23]);
$this->assertEquals('0.0.0.0', $userrow[24]);
$this->assertEquals('Boost', $userrow[25]);
$this->assertEquals('Horses', $userrow[26]);
$this->assertStringContainsString('Horses', $userrow[27]);
$this->assertEquals($cohort->name, $userrow[28]);
// User row.
[
$fullnamewithlink,
$fullnamewithpicture,
$fullnamewithpicturelink,
$picture,
$firstname,
$lastname,
$city,
$country,
$description,
$firstnamephonetic,
$lastnamephonetic,
$middlename,
$alternatename,
$idnumber,
$institution,
$department,
$phone1,
$phone2,
$address,
$lastaccess,
$suspended,
$confirmed,
$auth,
$moodlenetprofile,
$timecreated,
$timemodified,
$lastip,
$theme,
$tag,
$cohortname,
] = array_values($content[1]);
$this->assertStringContainsString(fullname($user), $fullnamewithlink);
$this->assertStringContainsString(fullname($user), $fullnamewithpicture);
$this->assertStringContainsString(fullname($user), $fullnamewithpicturelink);
$this->assertNotEmpty($picture);
$this->assertEquals($user->firstname, $firstname);
$this->assertEquals($user->lastname, $lastname);
$this->assertEquals($user->city, $city);
$this->assertEquals('United Kingdom', $country);
$this->assertEquals($user->description, $description);
$this->assertEquals($user->firstnamephonetic, $firstnamephonetic);
$this->assertEquals($user->lastnamephonetic, $lastnamephonetic);
$this->assertEquals($user->middlename, $middlename);
$this->assertEquals($user->alternatename, $alternatename);
$this->assertEquals($user->idnumber, $idnumber);
$this->assertEquals($user->institution, $institution);
$this->assertEquals($user->department, $department);
$this->assertEquals($user->phone1, $phone1);
$this->assertEquals($user->phone2, $phone2);
$this->assertEquals($user->address, $address);
$this->assertEmpty($lastaccess);
$this->assertEquals('No', $suspended);
$this->assertEquals('Yes', $confirmed);
$this->assertEquals('Manual accounts', $auth);
$this->assertEquals($user->moodlenetprofile, $moodlenetprofile);
$this->assertNotEmpty($timecreated);
$this->assertNotEmpty($timemodified);
$this->assertEquals('0.0.0.0', $lastip);
$this->assertEquals('Boost', $theme);
$this->assertEquals('Horses', $tag);
$this->assertEquals($cohort->name, $cohortname);
}
/**
@ -368,6 +412,14 @@ class users_test extends core_reportbuilder_testcase {
'user:timecreated_from' => 1619823600,
'user:timecreated_to' => 1622502000,
], false],
'Filter timemodified' => ['user:timemodified', [
'user:timemodified_operator' => date::DATE_RANGE,
'user:timemodified_from' => 1622502000,
], true],
'Filter timemodified (no match)' => ['user:timemodified', [
'user:timemodified_operator' => date::DATE_RANGE,
'user:timemodified_to' => 1622502000,
], false],
'Filter lastaccess' => ['user:lastaccess', [
'user:lastaccess_operator' => date::DATE_EMPTY,
], true],