MDL-78597 mod_lti: add full field support to course_tool_types generator

This method is used by behat only, where only a single arg is received.
The method lti_add_type() expects two params: type and config, but will
only ever receive one. This means not all the fields can be set when
creating an lti type. This change:
- Removes the superfluous param which the method won't receive
- Improves the logic for handling type and type config data, making it
match what happens when creating types via mforms.
- Adds relative URL support to the baseurl field, allowing behat
features to create types using local tool fixtures.
- Sets sensible default for missing config data, allowing the created
tool type to be used in launches in places like behat.
This commit is contained in:
Jake Dallimore 2023-07-29 16:29:09 +08:00
parent 7d1cd36e89
commit 5862fe2607
No known key found for this signature in database

View File

@ -137,11 +137,10 @@ class mod_lti_generator extends testing_module_generator {
* Create a course tool type.
*
* @param array $type the type info.
* @param array|null $config the type configuration.
* @return void
* @throws coding_exception if any required fields are missing.
*/
public function create_course_tool_types(array $type, ?array $config = null): void {
public function create_course_tool_types(array $type): void {
global $SITE;
if (!isset($type['baseurl'])) {
@ -150,8 +149,18 @@ class mod_lti_generator extends testing_module_generator {
if (!isset($type['course']) || $type['course'] == $SITE->id) {
throw new coding_exception('Must specify a non-site course when creating a course tool type.');
}
$type['baseurl'] = (new moodle_url($type['baseurl']))->out(false); // Permits relative URLs in behat features.
$type['coursevisible'] = LTI_COURSEVISIBLE_ACTIVITYCHOOSER; // The default for course tools.
$type['state'] = LTI_TOOL_STATE_CONFIGURED; // The default for course tools.
lti_add_type((object) $type, (object) $config);
// Sensible defaults permitting the tool type to be used in a launch.
$type['lti_acceptgrades'] = $type['lti_acceptgrades'] ?? LTI_SETTING_ALWAYS;
$type['lti_sendname'] = $type['lti_sendname'] ?? LTI_SETTING_ALWAYS;
$type['lti_sendemailaddr'] = $type['lti_sendemailaddr'] ?? LTI_SETTING_ALWAYS;
['type' => $type, 'config' => $config] = $this->get_type_and_config_from_data($type);
lti_add_type(type: (object) $type, config: (object) $config);
}
}