Skip to content

Commit 29660f6

Browse files
committed
Fix automated tests
1 parent 517bc76 commit 29660f6

6 files changed

Lines changed: 29 additions & 14 deletions

File tree

classes/external/get_users.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,29 @@ public static function execute(string $query, string $capability): array {
5959
self::validate_context($context);
6060
require_capability('report/customsql:definequeries', $context);
6161

62-
$extrafields = get_extra_user_fields($context);
62+
if (class_exists('\core_user\fields')) {
63+
$extrafields = \core_user\fields::for_identity($context, false)->get_required_fields();
64+
$fields = \core_user\fields::for_identity($context,
65+
false)->with_userpic()->get_sql('u', false, '', '', false)->selects;
66+
} else {
67+
$extrafields = get_extra_user_fields($context);
68+
$fields = \user_picture::fields('u', $extrafields);
69+
}
6370

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

7075
$users = $DB->get_records_sql("
71-
SELECT " . implode(', ', $fields) . "
76+
SELECT $fields
7277
FROM {user} u
7378
7479
JOIN (
7580
7681
SELECT id
7782
FROM {user} u
78-
{$withcapabilityjoin->joins}
79-
WHERE {$withcapabilityjoin->wheres}
83+
$withcapabilityjoin->joins
84+
WHERE $withcapabilityjoin->wheres
8085
8186
UNION
8287

classes/privacy/provider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ public static function delete_data_for_users(request\approved_userlist $userlist
229229
*/
230230
protected static function you_or_somebody_else($userid, $user) {
231231
if ($userid == $user->id) {
232-
return get_string('privacy_you', 'mod_bookingsystem');
232+
return get_string('privacy_you', 'report_customsql');
233233
} else {
234-
return get_string('privacy_somebodyelse', 'mod_bookingsystem');
234+
return get_string('privacy_somebodyelse', 'report_customsql');
235235
}
236236
}
237237
}

edit_form.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,18 @@ public function definition() {
120120
if (!$user) {
121121
return false;
122122
}
123+
124+
if (class_exists('\core_user\fields')) {
125+
$extrafields = \core_user\fields::for_identity(\context_system::instance(),
126+
false)->get_required_fields();
127+
} else {
128+
$extrafields = get_extra_user_fields(context_system::instance());
129+
}
130+
123131
return $OUTPUT->render_from_template(
124132
'report_customsql/form-user-selector-suggestion',
125133
\report_customsql\external\get_users::prepare_result_object(
126-
$user, get_extra_user_fields(context_system::instance()))
134+
$user, $extrafields)
127135
);
128136
}
129137
];

templates/form-user-selector-suggestion.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
* identity concatenated list of identity fields.
3333
3434
Example context (json):
35-
{ "id": "1",
35+
{
36+
"id": "1",
3637
"fullname": "Admin User",
3738
"hasidentity": true,
3839
"identity": "admin@example.com, 0144114141",

templates/form_report_information.mustache

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131
* usermodified Last modified by.
3232
3333
Example context (json):
34-
{ "timecreated": "Wednesday, 5 May 2021",
34+
{
35+
"timecreated": "Wednesday, 5 May 2021",
3536
"timemodified": "Wednesday, 5 May 2021",
36-
"usermodified": "Admin User",
37+
"usermodified": "Admin User"
3738
}
3839
}}
3940
<div class="report-customsql-infomation">

tests/behat/report_customsql.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ Feature: Ad-hoc database queries report
218218

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

0 commit comments

Comments
 (0)