mirror of
https://github.com/moodle/moodle.git
synced 2025-03-22 00:20:37 +01:00
Merge branch 'MDL-69187-401' of https://github.com/paulholden/moodle into MOODLE_401_STABLE
This commit is contained in:
commit
3a6c0872b9
@ -2068,9 +2068,12 @@ function get_mimetype_description($obj, $capitalise=false) {
|
||||
*/
|
||||
function file_get_typegroup($element, $groups) {
|
||||
static $cached = array();
|
||||
|
||||
// Turn groups into a list.
|
||||
if (!is_array($groups)) {
|
||||
$groups = array($groups);
|
||||
$groups = preg_split('/[\s,;:"\']+/', $groups, -1, PREG_SPLIT_NO_EMPTY);
|
||||
}
|
||||
|
||||
if (!array_key_exists($element, $cached)) {
|
||||
$cached[$element] = array();
|
||||
}
|
||||
|
@ -1985,6 +1985,42 @@ EOF;
|
||||
['noclean' => true, 'context' => $syscontext], $syscontext, 'core', 'some', 1);
|
||||
$this->assertSame($text, $result->some);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for file_get_typegroup to check that both arrays, and string values are accepted.
|
||||
*
|
||||
* @dataProvider file_get_typegroup_provider
|
||||
* @param string|array $group
|
||||
* @param string $expected
|
||||
*/
|
||||
public function test_file_get_typegroup(
|
||||
$group,
|
||||
string $expected
|
||||
): void {
|
||||
$result = file_get_typegroup('type', $group);
|
||||
$this->assertContains($expected, $result);
|
||||
}
|
||||
|
||||
public static function file_get_typegroup_provider(): array {
|
||||
return [
|
||||
'Array of values' => [
|
||||
['.html', '.htm'],
|
||||
'text/html',
|
||||
],
|
||||
'String of comma-separated values' => [
|
||||
'.html, .htm',
|
||||
'text/html',
|
||||
],
|
||||
'String of colon-separated values' => [
|
||||
'.html : .htm',
|
||||
'text/html',
|
||||
],
|
||||
'String of semi-colon-separated values' => [
|
||||
'.html ; .htm',
|
||||
'text/html',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user