MDL-62640 enrol_lti: Adjust code for slashargument removal

This commit is contained in:
meirzamoodle 2024-09-10 14:09:51 +07:00
parent 4d2ad0bff7
commit 979db77a63
2 changed files with 6 additions and 62 deletions

View File

@ -450,58 +450,26 @@ class helper {
/**
* Returns the url to the cartridge representing the tool.
*
* If you have slash arguments enabled, this will be a nice url ending in cartridge.xml.
* If not it will be a php page with some parameters passed.
*
* @param \stdClass $tool The lti tool
* @return string The url to the cartridge representing the tool
* @since Moodle 3.2
*/
public static function get_cartridge_url($tool) {
global $CFG;
$url = null;
$id = $tool->id;
$token = self::generate_cartridge_token($tool->id);
if ($CFG->slasharguments) {
$url = new \moodle_url('/enrol/lti/cartridge.php/' . $id . '/' . $token . '/cartridge.xml');
} else {
$url = new \moodle_url('/enrol/lti/cartridge.php',
array(
'id' => $id,
'token' => $token
)
);
}
return $url;
return new \moodle_url('/enrol/lti/cartridge.php/' . $id . '/' . $token . '/cartridge.xml');
}
/**
* Returns the url to the tool proxy registration url.
*
* If you have slash arguments enabled, this will be a nice url ending in cartridge.xml.
* If not it will be a php page with some parameters passed.
*
* @param \stdClass $tool The lti tool
* @return string The url to the cartridge representing the tool
*/
public static function get_proxy_url($tool) {
global $CFG;
$url = null;
$id = $tool->id;
$token = self::generate_proxy_token($tool->id);
if ($CFG->slasharguments) {
$url = new \moodle_url('/enrol/lti/proxy.php/' . $id . '/' . $token . '/');
} else {
$url = new \moodle_url('/enrol/lti/proxy.php',
array(
'id' => $id,
'token' => $token
)
);
}
return $url;
return new \moodle_url('/enrol/lti/proxy.php/' . $id . '/' . $token . '/');
}
/**

View File

@ -22,6 +22,8 @@ namespace enrol_lti;
* @package enrol_lti
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @covers \enrol_lti\helper
*/
class helper_test extends \advanced_testcase {
@ -260,12 +262,6 @@ class helper_test extends \advanced_testcase {
* Test getting the cartridge url of a tool.
*/
public function test_get_cartridge_url(): void {
global $CFG;
$slasharguments = $CFG->slasharguments;
$CFG->slasharguments = false;
$course1 = $this->getDataGenerator()->create_course();
$data = new \stdClass();
$data->courseid = $course1->id;
@ -273,29 +269,16 @@ class helper_test extends \advanced_testcase {
$id = $tool1->id;
$token = \enrol_lti\helper::generate_cartridge_token($id);
$launchurl = \enrol_lti\helper::get_cartridge_url($tool1);
$this->assertEquals('https://www.example.com/moodle/enrol/lti/cartridge.php?id=' . $id . '&amp;token=' . $token,
$launchurl->out());
$CFG->slasharguments = true;
/** @var \moodle_url $launchurl */
$launchurl = \enrol_lti\helper::get_cartridge_url($tool1);
$this->assertEquals('https://www.example.com/moodle/enrol/lti/cartridge.php/' . $id . '/' . $token . '/cartridge.xml',
$launchurl->out());
$CFG->slasharguments = $slasharguments;
}
/**
* Test getting the cartridge url of a tool.
*/
public function test_get_proxy_url(): void {
global $CFG;
$slasharguments = $CFG->slasharguments;
$CFG->slasharguments = false;
$course1 = $this->getDataGenerator()->create_course();
$data = new \stdClass();
$data->courseid = $course1->id;
@ -303,17 +286,10 @@ class helper_test extends \advanced_testcase {
$id = $tool1->id;
$token = \enrol_lti\helper::generate_proxy_token($id);
$launchurl = \enrol_lti\helper::get_proxy_url($tool1);
$this->assertEquals('https://www.example.com/moodle/enrol/lti/proxy.php?id=' . $id . '&amp;token=' . $token,
$launchurl->out());
$CFG->slasharguments = true;
/** @var \moodle_url $launchurl */
$launchurl = \enrol_lti\helper::get_proxy_url($tool1);
$this->assertEquals('https://www.example.com/moodle/enrol/lti/proxy.php/' . $id . '/' . $token . '/',
$launchurl->out());
$CFG->slasharguments = $slasharguments;
}
/**