Skip to content

Commit

Permalink
Fix automated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Jul 7, 2021
1 parent 517bc76 commit a6e426a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
13 changes: 9 additions & 4 deletions classes/external/get_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,21 @@ public static function execute(string $query, string $capability): array {
self::validate_context($context);
require_capability('report/customsql:definequeries', $context);

$extrafields = get_extra_user_fields($context);
if (class_exists('\core_user\fields')) {
$extrafields = \core_user\fields::for_identity($context, false)->get_required_fields();
$fields = \core_user\fields::for_identity($context, false)->with_userpic()->get_sql('u')->selects;
} else {
$extrafields = get_extra_user_fields($context);
$fields = array_merge(['u.id'], preg_split('~\s*,\s*~',
implode(', ', \user_picture::fields('u')), $extrafields));
}

$fields = array_merge(['u.id'], preg_split('~\s*,\s*~',
\user_picture::fields('u')), $extrafields);
$withcapabilityjoin = get_with_capability_join($context, $capability, 'u.id');
[$wherecondition, $whereparams] = users_search_sql($query, 'u', true, $extrafields);
[$sort, $sortparams] = users_order_by_sql('u', $query, $context);

$users = $DB->get_records_sql("
SELECT " . implode(', ', $fields) . "
SELECT $fields
FROM {user} u
JOIN (
Expand Down
4 changes: 2 additions & 2 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ public static function delete_data_for_users(request\approved_userlist $userlist
*/
protected static function you_or_somebody_else($userid, $user) {
if ($userid == $user->id) {
return get_string('privacy_you', 'mod_bookingsystem');
return get_string('privacy_you', 'report_customsql');
} else {
return get_string('privacy_somebodyelse', 'mod_bookingsystem');
return get_string('privacy_somebodyelse', 'report_customsql');
}
}
}
10 changes: 9 additions & 1 deletion edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,18 @@ public function definition() {
if (!$user) {
return false;
}

if (class_exists('\core_user\fields')) {
$extrafields = \core_user\fields::for_identity(\context_system::instance(),
false)->get_required_fields();
} else {
$extrafields = get_extra_user_fields(context_system::instance());
}

return $OUTPUT->render_from_template(
'report_customsql/form-user-selector-suggestion',
\report_customsql\external\get_users::prepare_result_object(
$user, get_extra_user_fields(context_system::instance()))
$user, $extrafields)
);
}
];
Expand Down
3 changes: 2 additions & 1 deletion templates/form-user-selector-suggestion.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
* identity concatenated list of identity fields.
Example context (json):
{ "id": "1",
{
"id": "1",
"fullname": "Admin User",
"hasidentity": true,
"identity": "[email protected], 0144114141",
Expand Down
5 changes: 3 additions & 2 deletions templates/form_report_information.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
* usermodified Last modified by.
Example context (json):
{ "timecreated": "Wednesday, 5 May 2021",
{
"timecreated": "Wednesday, 5 May 2021",
"timemodified": "Wednesday, 5 May 2021",
"usermodified": "Admin User",
"usermodified": "Admin User"
}
}}
<div class="report-customsql-infomation">
Expand Down
4 changes: 2 additions & 2 deletions tests/behat/report_customsql.feature
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ Feature: Ad-hoc database queries report

Scenario: View an Ad-hoc database query that returns data that confuses PHP CSV parsing
Given the following custom sql report exists:
| name | Test query |
| querysql | SELECT '\' AS Backslash, ',' AS Comma |
| name | Test query |
| querysql | SELECT CHR(92) AS Backslash, CHR(44) AS Comma |
When I log in as "admin"
And I view the "Test query" custom sql report
Then "\" row "Comma" column of "report_customsql_results" table should contain ","

0 comments on commit a6e426a

Please sign in to comment.