| Línea 22... |
Línea 22... |
| 22 |
* @package core
|
22 |
* @package core
|
| 23 |
* @category test
|
23 |
* @category test
|
| 24 |
* @copyright 2012 The Open University
|
24 |
* @copyright 2012 The Open University
|
| 25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 26 |
*/
|
26 |
*/
|
| 27 |
class datalib_test extends \advanced_testcase {
|
27 |
final class datalib_test extends \advanced_testcase {
|
| 28 |
protected function normalise_sql($sort) {
|
28 |
protected function normalise_sql($sort) {
|
| 29 |
return preg_replace('~\s+~', ' ', $sort);
|
29 |
return preg_replace('~\s+~', ' ', $sort);
|
| 30 |
}
|
30 |
}
|
| Línea 31... |
Línea 31... |
| 31 |
|
31 |
|
| Línea 172... |
Línea 172... |
| 172 |
|
172 |
|
| Línea 173... |
Línea 173... |
| 173 |
$CFG->showuseridentity = '';
|
173 |
$CFG->showuseridentity = '';
|
| 174 |
|
174 |
|
| 175 |
list($sort, $params) = users_order_by_sql('', 'search', \context_system::instance());
|
175 |
list($sort, $params) = users_order_by_sql('', 'search', \context_system::instance());
|
| 176 |
$this->assert_same_sql('CASE WHEN
|
176 |
$this->assert_same_sql('CASE WHEN
|
| 177 |
' . $DB->sql_fullname() . ' = :usersortexact1 OR
|
177 |
' . $DB->sql_fullname() . ' = :usersortexact OR
|
| 178 |
LOWER(firstname) = LOWER(:usersortexact2) OR
|
178 |
LOWER(firstname) = LOWER(:usersortfield0) OR
|
| 179 |
LOWER(lastname) = LOWER(:usersortexact3)
|
179 |
LOWER(lastname) = LOWER(:usersortfield1)
|
| 180 |
THEN 0 ELSE 1 END, lastname, firstname, id', $sort);
|
- |
|
| 181 |
$this->assertEquals(array('usersortexact1' => 'search', 'usersortexact2' => 'search',
|
180 |
THEN 0 ELSE 1 END, lastname, firstname, id', $sort);
|
| Línea 182... |
Línea 181... |
| 182 |
'usersortexact3' => 'search'), $params);
|
181 |
$this->assertEquals(['usersortexact' => 'search', 'usersortfield0' => 'search', 'usersortfield1' => 'search'], $params);
|
| 183 |
}
|
182 |
}
|
| 184 |
|
183 |
|
| Línea 189... |
Línea 188... |
| 189 |
$CFG->showuseridentity = 'email,idnumber';
|
188 |
$CFG->showuseridentity = 'email,idnumber';
|
| 190 |
$this->setAdminUser();
|
189 |
$this->setAdminUser();
|
| Línea 191... |
Línea 190... |
| 191 |
|
190 |
|
| 192 |
list($sort, $params) = users_order_by_sql('u', 'search', \context_system::instance());
|
191 |
list($sort, $params) = users_order_by_sql('u', 'search', \context_system::instance());
|
| 193 |
$this->assert_same_sql('CASE WHEN
|
192 |
$this->assert_same_sql('CASE WHEN
|
| 194 |
' . $DB->sql_fullname('u.firstname', 'u.lastname') . ' = :usersortexact1 OR
|
193 |
' . $DB->sql_fullname('u.firstname', 'u.lastname') . ' = :usersortexact OR
|
| 195 |
LOWER(u.firstname) = LOWER(:usersortexact2) OR
|
194 |
LOWER(u.firstname) = LOWER(:usersortfield0) OR
|
| 196 |
LOWER(u.lastname) = LOWER(:usersortexact3) OR
|
195 |
LOWER(u.lastname) = LOWER(:usersortfield1) OR
|
| 197 |
LOWER(u.email) = LOWER(:usersortexact4) OR
|
196 |
LOWER(u.email) = LOWER(:usersortfield2) OR
|
| 198 |
LOWER(u.idnumber) = LOWER(:usersortexact5)
|
197 |
LOWER(u.idnumber) = LOWER(:usersortfield3)
|
| 199 |
THEN 0 ELSE 1 END, u.lastname, u.firstname, u.id', $sort);
|
198 |
THEN 0 ELSE 1 END, u.lastname, u.firstname, u.id', $sort);
|
| 200 |
$this->assertEquals(array('usersortexact1' => 'search', 'usersortexact2' => 'search',
|
199 |
$this->assertEquals(['usersortexact' => 'search', 'usersortfield0' => 'search',
|
| 201 |
'usersortexact3' => 'search', 'usersortexact4' => 'search', 'usersortexact5' => 'search'), $params);
|
200 |
'usersortfield1' => 'search', 'usersortfield2' => 'search', 'usersortfield3' => 'search'], $params);
|
| Línea 202... |
Línea 201... |
| 202 |
}
|
201 |
}
|
| 203 |
|
202 |
|
| 204 |
public function test_users_order_by_sql_search_with_custom_fields(): void {
|
203 |
public function test_users_order_by_sql_search_with_custom_fields(): void {
|
| Línea 209... |
Línea 208... |
| 209 |
$this->setAdminUser();
|
208 |
$this->setAdminUser();
|
| Línea 210... |
Línea 209... |
| 210 |
|
209 |
|
| 211 |
list($sort, $params) =
|
210 |
list($sort, $params) =
|
| 212 |
users_order_by_sql('u', 'search', \context_system::instance(), ['profile_field_customfield' => 'x.customfield']);
|
211 |
users_order_by_sql('u', 'search', \context_system::instance(), ['profile_field_customfield' => 'x.customfield']);
|
| 213 |
$this->assert_same_sql('CASE WHEN
|
212 |
$this->assert_same_sql('CASE WHEN
|
| 214 |
' . $DB->sql_fullname('u.firstname', 'u.lastname') . ' = :usersortexact1 OR
|
213 |
' . $DB->sql_fullname('u.firstname', 'u.lastname') . ' = :usersortexact OR
|
| 215 |
LOWER(u.firstname) = LOWER(:usersortexact2) OR
|
214 |
LOWER(u.firstname) = LOWER(:usersortfield0) OR
|
| 216 |
LOWER(u.lastname) = LOWER(:usersortexact3) OR
|
215 |
LOWER(u.lastname) = LOWER(:usersortfield1) OR
|
| 217 |
LOWER(x.customfield) = LOWER(:usersortexact4)
|
216 |
LOWER(x.customfield) = LOWER(:usersortfield2)
|
| 218 |
THEN 0 ELSE 1 END, u.lastname, u.firstname, u.id', $sort);
|
217 |
THEN 0 ELSE 1 END, u.lastname, u.firstname, u.id', $sort);
|
| 219 |
$this->assertEquals(array('usersortexact1' => 'search', 'usersortexact2' => 'search',
|
218 |
$this->assertEquals(['usersortexact' => 'search', 'usersortfield0' => 'search',
|
| 220 |
'usersortexact3' => 'search', 'usersortexact4' => 'search'), $params);
|
219 |
'usersortfield1' => 'search', 'usersortfield2' => 'search'], $params);
|
| Línea 221... |
Línea 220... |
| 221 |
}
|
220 |
}
|
| 222 |
|
221 |
|
| 223 |
public function test_get_admin(): void {
|
222 |
public function test_get_admin(): void {
|
| Línea 904... |
Línea 903... |
| 904 |
/**
|
903 |
/**
|
| 905 |
* Data provider for test_get_safe_orderby().
|
904 |
* Data provider for test_get_safe_orderby().
|
| 906 |
*
|
905 |
*
|
| 907 |
* @return array
|
906 |
* @return array
|
| 908 |
*/
|
907 |
*/
|
| 909 |
public function get_safe_orderby_provider(): array {
|
908 |
public static function get_safe_orderby_provider(): array {
|
| 910 |
$orderbymap = [
|
909 |
$orderbymap = [
|
| 911 |
'courseid' => 'c.id',
|
910 |
'courseid' => 'c.id',
|
| 912 |
'somecustomvalue' => 'c.startdate, c.shortname',
|
911 |
'somecustomvalue' => 'c.startdate, c.shortname',
|
| 913 |
'default' => 'c.fullname',
|
912 |
'default' => 'c.fullname',
|
| 914 |
];
|
913 |
];
|
| Línea 992... |
Línea 991... |
| 992 |
/**
|
991 |
/**
|
| 993 |
* Data provider for test_get_safe_orderby_multiple().
|
992 |
* Data provider for test_get_safe_orderby_multiple().
|
| 994 |
*
|
993 |
*
|
| 995 |
* @return array
|
994 |
* @return array
|
| 996 |
*/
|
995 |
*/
|
| 997 |
public function get_safe_orderby_multiple_provider(): array {
|
996 |
public static function get_safe_orderby_multiple_provider(): array {
|
| 998 |
$orderbymap = [
|
997 |
$orderbymap = [
|
| 999 |
'courseid' => 'c.id',
|
998 |
'courseid' => 'c.id',
|
| 1000 |
'firstname' => 'u.firstname',
|
999 |
'firstname' => 'u.firstname',
|
| 1001 |
'default' => 'c.startdate',
|
1000 |
'default' => 'c.startdate',
|
| 1002 |
];
|
1001 |
];
|