mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-72125 testing: Set a default idnumber when creating activities
The activity generator currently requires an idnumber when creating activities, but this is not a requirement when creating the same activity through the UI. The requirement comes because we want to provide a way to refer to activities in subsequent steps. This commit modifies the behaviour such that the generator uses the name of the activity as the default idnumber. This has two main benefits: 1. it simplfies generation of activities; and 2. it makes the language used when writing behat tests much more natural. With this change, steps will refer to the activity by its idnumber/title in all cases, rather than sometimes by an idnumber which bears no relevance to the title.
This commit is contained in:
parent
daf9b24b6a
commit
7cd408501b
1 changed files with 12 additions and 1 deletions
|
@ -120,7 +120,7 @@ class behat_core_generator extends behat_generator_base {
|
||||||
'activities' => [
|
'activities' => [
|
||||||
'singular' => 'activity',
|
'singular' => 'activity',
|
||||||
'datagenerator' => 'activity',
|
'datagenerator' => 'activity',
|
||||||
'required' => ['activity', 'idnumber', 'course'],
|
'required' => ['activity', 'course'],
|
||||||
'switchids' => ['course' => 'course', 'gradecategory' => 'gradecat', 'grouping' => 'groupingid'],
|
'switchids' => ['course' => 'course', 'gradecategory' => 'gradecat', 'grouping' => 'groupingid'],
|
||||||
],
|
],
|
||||||
'blocks' => [
|
'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.
|
// We split $data in the activity $record and the course module $options.
|
||||||
$cmoptions = array();
|
$cmoptions = array();
|
||||||
$cmcolumns = $DB->get_columns('course_modules');
|
$cmcolumns = $DB->get_columns('course_modules');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue