Merge branch 'MDL-86017-main' of https://github.com/mijiaa/moodle
This commit is contained in:
@@ -468,7 +468,7 @@ function folder_cm_info_view(cm_info $cm) {
|
||||
// Restore folder object from customdata.
|
||||
// Note the field 'customdata' is not empty IF AND ONLY IF we display contens inline.
|
||||
// Otherwise the content is default.
|
||||
$folder = $cm->customdata;
|
||||
$folder = (object) $cm->get_custom_data();
|
||||
$folder->id = (int)$cm->instance;
|
||||
$folder->course = (int)$cm->course;
|
||||
$folder->display = FOLDER_DISPLAY_INLINE;
|
||||
|
||||
@@ -403,4 +403,56 @@ final class lib_test extends \advanced_testcase {
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that folder_cm_info_view handles custom data correctly after override_customdata() changes it from object to array.
|
||||
* @covers ::folder_cm_info_view()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_folder_cm_info_view(): void {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$folderinline = $this->getDataGenerator()->create_module('folder', ['course' => $course->id,
|
||||
'name' => 'testfolder', 'display' => FOLDER_DISPLAY_INLINE]);
|
||||
|
||||
$cm = get_fast_modinfo($course)->get_cm($folderinline->cmid);
|
||||
$this->assertIsObject($cm->customdata);
|
||||
$cm->override_customdata('showexpanded', 1);
|
||||
$cm->override_customdata('showdownloadfolder', 1);
|
||||
$cm->override_customdata('forcedownload', 1);
|
||||
|
||||
$expecteddata = [
|
||||
'showexpanded' => 1,
|
||||
'showdownloadfolder' => 1,
|
||||
'forcedownload' => 1,
|
||||
];
|
||||
$this->assertIsArray($cm->get_custom_data());
|
||||
$this->assertEquals($expecteddata, $cm->get_custom_data());
|
||||
|
||||
// Add a test file to the folder activity.
|
||||
$context = context_module::instance($cm->id);
|
||||
$fs = get_file_storage();
|
||||
$filerecord = [
|
||||
'contextid' => $context->id,
|
||||
'component' => 'mod_folder',
|
||||
'filearea' => 'content',
|
||||
'itemid' => 0,
|
||||
'filepath' => '/',
|
||||
'filename' => 'testfile.txt',
|
||||
];
|
||||
$fs->create_file_from_string($filerecord, 'Test file content');
|
||||
|
||||
// Verify content after custom data overrides.
|
||||
// The download option should be present when showdownloadfolder=1 and the folder has a file.
|
||||
folder_cm_info_view($cm);
|
||||
$content = $cm->content;
|
||||
$this->assertStringContainsString($cm->get_formatted_name(['escape' => false]), $content);
|
||||
$this->assertStringContainsString('mod/folder/download_folder.php', $content);
|
||||
|
||||
// The download option should not be present when showdownloadfolder=0 and the folder has a file.
|
||||
$cm->override_customdata('showdownloadfolder', 0);
|
||||
folder_cm_info_view($cm);
|
||||
$contentnodownload = $cm->content;
|
||||
$this->assertStringNotContainsString('mod/folder/download_folder.php', $contentnodownload);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user