MDL-75913 behat: Private files data generator
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user