From 5862fe2607eaf0287ac4ab3201ac991663cfc6f5 Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Sat, 29 Jul 2023 16:29:09 +0800 Subject: [PATCH] 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. --- mod/lti/tests/generator/lib.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mod/lti/tests/generator/lib.php b/mod/lti/tests/generator/lib.php index 1a521ca7936..5525de65e32 100644 --- a/mod/lti/tests/generator/lib.php +++ b/mod/lti/tests/generator/lib.php @@ -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); } }