mirror of
https://github.com/moodle/moodle.git
synced 2025-03-19 23:20:09 +01:00
Merge branch 'MDL-70921-master' of git://github.com/marinaglancy/moodle
This commit is contained in:
commit
1285a8d868
@ -2139,12 +2139,9 @@ abstract class repository implements cacheable_object {
|
||||
* @param array $value
|
||||
* @return bool
|
||||
*/
|
||||
public function filter(&$value) {
|
||||
public function filter($value) {
|
||||
$accepted_types = optional_param_array('accepted_types', '', PARAM_RAW);
|
||||
if (isset($value['children'])) {
|
||||
if (!empty($value['children'])) {
|
||||
$value['children'] = array_filter($value['children'], array($this, 'filter'));
|
||||
}
|
||||
return true; // always return directories
|
||||
} else {
|
||||
if ($accepted_types == '*' or empty($accepted_types)
|
||||
|
@ -596,4 +596,45 @@ class core_repositorylib_testcase extends advanced_testcase {
|
||||
delete_user($user);
|
||||
$this->assertEquals(0, $DB->count_records('repository_instances', array('contextid' => $usercontext->id)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create test file in user private files
|
||||
*
|
||||
* @param string $filepath file path
|
||||
* @param string $filename file name
|
||||
*/
|
||||
private function create_user_private_file(string $filepath, string $filename): void {
|
||||
global $USER;
|
||||
|
||||
$filerecord = [];
|
||||
$filerecord['contextid'] = context_user::instance($USER->id)->id;
|
||||
$filerecord['component'] = 'user';
|
||||
$filerecord['filearea'] = 'private';
|
||||
$filerecord['itemid'] = 0;
|
||||
$filerecord['filepath'] = $filepath;
|
||||
$filerecord['filename'] = $filename;
|
||||
$filerecord['userid'] = $USER->id;
|
||||
|
||||
$fs = get_file_storage();
|
||||
$fs->create_file_from_string($filerecord, hash("md5", $filepath . $filename));
|
||||
}
|
||||
|
||||
public function test_listing_and_filter() {
|
||||
$this->resetAfterTest(true);
|
||||
$this->setUser($this->getDataGenerator()->create_user());
|
||||
$repoid = $this->getDataGenerator()->create_repository('user')->id;
|
||||
$this->create_user_private_file('/', 'image1.jpg');
|
||||
$this->create_user_private_file('/', 'file1.txt');
|
||||
$this->create_user_private_file('/folder/', 'image2.jpg');
|
||||
$this->create_user_private_file('/folder/', 'file2.txt');
|
||||
$this->create_user_private_file('/ftexts/', 'file3.txt');
|
||||
|
||||
// Listing without filters returns 4 records (2 files and 2 directories).
|
||||
$repo = repository::get_repository_by_id($repoid, context_system::instance());
|
||||
$this->assertCount(4, $repo->get_listing()['list']);
|
||||
|
||||
// Listing with filters returns 3 records (1 files and 2 directories).
|
||||
$_POST['accepted_types'] = ['.jpg'];
|
||||
$this->assertCount(3, $repo->get_listing()['list']);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user