MDL-75913 behat: Private files data generator

This commit is contained in:
David Woloszyn
2023-06-19 16:38:42 +10:00
parent 0b80e3a887
commit bfcc39996f
@@ -287,6 +287,12 @@ class behat_core_generator extends behat_generator_base {
'required' => array('contextlevel', 'reference', 'contenttype', 'user', 'contentname'),
'switchids' => array('user' => 'userid')
],
'user private files' => [
'singular' => 'user private file',
'datagenerator' => 'user_private_files',
'required' => ['user', 'filepath', 'filename'],
'switchids' => ['user' => 'userid']
],
'badge external backpacks' => [
'singular' => 'badge external backpack',
'datagenerator' => 'badge_external_backpack',
@@ -1058,6 +1064,34 @@ class behat_core_generator extends behat_generator_base {
}
}
/**
* Create content in the given user's private files.
*
* @param array $data
* @return void
*/
protected function process_user_private_files(array $data) {
global $CFG;
$userid = $data['userid'];
$fs = get_file_storage();
$filepath = "{$CFG->dirroot}/{$data['filepath']}";
if (!file_exists($filepath)) {
throw new coding_exception("File '{$filepath}' does not exist");
}
$filerecord = [
'userid' => $userid,
'contextid' => context_user::instance($userid)->id,
'component' => 'user',
'filearea' => 'private',
'itemid' => 0,
'filepath' => '/',
'filename' => basename($filepath),
];
$fs->create_file_from_pathname($filerecord, $filepath);
}
/**
* Create a exetrnal backpack.
*