MDL-78597 mod_lti: add instance creation to behat creatable entities
This allows behat tests which have already created either a site or course tool type, to then link it to an activity instance using a generator. This depends on the ability to name match a type.
This commit is contained in:
@@ -50,7 +50,28 @@ class behat_mod_lti_generator extends behat_generator_base {
|
||||
'datagenerator' => 'course_tool_types',
|
||||
'required' => ['baseurl', 'course'],
|
||||
'switchids' => ['course' => 'course']
|
||||
]
|
||||
],
|
||||
'tool instances' => [
|
||||
'singular' => 'instance',
|
||||
'datagenerator' => 'instance',
|
||||
'required' => ['course', 'tool'],
|
||||
'switchids' => ['course' => 'course', 'tool' => 'typeid']
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the switchid ['tool' => 'typeid'] for finding a tool by name.
|
||||
*
|
||||
* @param string $name the name of the tool.
|
||||
* @return int the id of the tool type identified by the name $name.
|
||||
*/
|
||||
protected function get_tool_id(string $name): int {
|
||||
global $DB;
|
||||
|
||||
if (!$id = $DB->get_field('lti_types', 'id', ['name' => $name])) {
|
||||
throw new coding_exception('The specified tool with name "' . $name . '" does not exist');
|
||||
}
|
||||
return (int) $id;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user