Merge branch 'MDL-72125-master' of git://github.com/andrewnicols/moodle

This commit is contained in:
Ilya Tregubov 2021-07-19 13:03:46 +02:00
commit 494a9bb41f
50 changed files with 1269 additions and 1352 deletions

View file

@ -120,7 +120,7 @@ class behat_core_generator extends behat_generator_base {
'activities' => [
'singular' => 'activity',
'datagenerator' => 'activity',
'required' => ['activity', 'idnumber', 'course'],
'required' => ['activity', 'course'],
'switchids' => ['course' => 'course', 'gradecategory' => 'gradecat', 'grouping' => 'groupingid'],
],
'blocks' => [
@ -389,6 +389,17 @@ class behat_core_generator extends behat_generator_base {
}
}
if (!array_key_exists('idnumber', $data)) {
$data['idnumber'] = $data['name'];
if (strlen($data['name']) > 100) {
throw new Exception(
"Activity '{$activityname}' cannot be used as the default idnumber. " .
"The idnumber has a max length of 100 chars. " .
"Please manually specify an idnumber."
);
}
}
// We split $data in the activity $record and the course module $options.
$cmoptions = array();
$cmcolumns = $DB->get_columns('course_modules');

View file

@ -368,6 +368,25 @@ abstract class behat_generator_base {
return $id;
}
/**
* Gets the course cmid for the specified activity based on the activity's idnumber.
*
* Note: this does not check the module type, only the idnumber.
*
* @throws Exception
* @param string $idnumber
* @return int
*/
protected function get_activity_id(string $idnumber) {
global $DB;
if (!$id = $DB->get_field('course_modules', 'id', ['idnumber' => $idnumber])) {
throw new Exception('The specified activity with idnumber "' . $idnumber . '" could not be found.');
}
return $id;
}
/**
* Gets the group id from it's idnumber.
* @throws Exception

View file

@ -57,4 +57,33 @@ abstract class component_generator_base {
*/
public function reset() {
}
/**
* Set the current user during data generation.
*
* This should be avoided wherever possible, but in some situations underlying code will insert data as the current
* user.
*
* @param stdClass $user
*/
protected function set_user(?stdClass $user = null): void {
global $CFG, $DB;
if ($user === null) {
$user = (object) [
'id' => 0,
'mnethostid' => $CFG->mnet_localhost_id,
];
} else {
$user = clone($user);
unset($user->description);
unset($user->access);
unset($user->preference);
}
// Ensure session is empty, as it may contain caches and user-specific info.
\core\session\manager::init_empty_session();
\core\session\manager::set_user($user);
}
}

View file

@ -103,6 +103,9 @@ EOD;
* @return component_generator_base or rather an instance of the appropriate subclass.
*/
public function get_plugin_generator($component) {
// Note: This global is included so that generator have access to it.
// CFG is widely used in require statements.
global $CFG;
list($type, $plugin) = core_component::normalize_component($component);
$cleancomponent = $type . '_' . $plugin;
if ($cleancomponent != $component) {