diff --git a/lib/filelib.php b/lib/filelib.php index c6e3ccd9718..68f662f5a4f 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -855,7 +855,7 @@ function file_get_all_files_in_draftarea(int $draftitemid, string $filepath = '/ if (!empty($draftfiles)) { foreach ($draftfiles->list as $draftfile) { - if ($draftfile->type == 'file') { + if ($draftfile->type !== 'folder') { $files[] = $draftfile; } } diff --git a/lib/tests/filelib_test.php b/lib/tests/filelib_test.php index ff7fdf3256f..fc66dfe500b 100644 --- a/lib/tests/filelib_test.php +++ b/lib/tests/filelib_test.php @@ -1826,6 +1826,38 @@ EOF; $this->assertEquals($fifthrecord['filename'], $allfiles[4]->filename); } + /** + * Test that zip files in the draftarea are returned. + * @covers ::file_get_all_files_in_draftarea + */ + public function test_file_get_all_files_in_draftarea_zip_files(): void { + $this->resetAfterTest(); + $this->setAdminUser(); + + $zip1 = ['filename' => 'basezip.zip']; + $file = self::create_draft_file($zip1); + + $zip2 = [ + 'filename' => 'infolder.zip', + 'filepath' => '/assignment/', + 'itemid' => $file->get_itemid(), + ]; + $file = self::create_draft_file($zip2); + + $otherfile = [ + 'filename' => 'otherfile.txt', + 'filepath' => '/secondfolder/', + 'itemid' => $file->get_itemid(), + ]; + $file = self::create_draft_file($otherfile); + + $allfiles = file_get_all_files_in_draftarea($file->get_itemid()); + $this->assertCount(3, $allfiles); + $this->assertEquals($zip1['filename'], $allfiles[0]->filename); + $this->assertEquals($zip2['filename'], $allfiles[1]->filename); + $this->assertEquals($otherfile['filename'], $allfiles[2]->filename); + } + public function test_file_copy_file_to_file_area(): void { // Create two files in different draft areas but owned by the same user. global $USER;