Skip to content

Commit

Permalink
PM-46460 bugfix: handle grouping IDs properly
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-kialo committed Aug 27, 2024
1 parent e5394ef commit e2a7b41
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 5 deletions.
2 changes: 1 addition & 1 deletion classes/lti_flow.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static function init_resource_link(
string $deploymentid,
string $moodleuserid,
string $discussionurl,
?int $groupid = null,
?string $groupid = null,
?string $groupname = null
): LtiMessageInterface {
$context = context_module::instance($coursemoduleid);
Expand Down
77 changes: 73 additions & 4 deletions tests/classes/lti_flow_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ final class lti_flow_test extends \advanced_testcase {
*/
private $course;

/**
* Current course module (created in setUp).
*
* @var \stdClass
*/
private $cm;

/**
* Current module (created in setUp).
*
Expand Down Expand Up @@ -167,7 +174,8 @@ protected function setUp(): void {

// Creates a Kialo activity.
$this->module = $this->getDataGenerator()->create_module('kialo', ['course' => $this->course->id]);
$this->cmid = get_coursemodule_from_instance("kialo", $this->module->id)->id;
$this->cm = get_coursemodule_from_instance("kialo", $this->module->id);
$this->cmid = $this->cm->id;
}

protected function tearDown(): void {
Expand Down Expand Up @@ -392,6 +400,11 @@ public function test_init_resource_link_with_groups(): void {
'userid' => $this->user->id,
]);

$groupinfo = (object) [
'groupid' => $group->id,
'groupname' => $group->name,
];

// Construct the initial LTI message sent to Kialo when the user clicks on the activity.
$deploymentid = "random-string-123";
$discussionurl = "random-discussion-url.com";
Expand All @@ -401,8 +414,8 @@ public function test_init_resource_link_with_groups(): void {
$deploymentid,
$this->user->id,
$discussionurl,
$group->id,
$group->name
$groupinfo->groupid,
$groupinfo->groupname
);
$this->assertNotNull($message);

Expand All @@ -412,10 +425,66 @@ public function test_init_resource_link_with_groups(): void {
$token = $this->assert_jwt_signed_by_platform($params['lti_message_hint']);

// Group information is passed via custom claims.
$this->assertEquals($token->claims()->get("https://purl.imsglobal.org/spec/lti/claim/custom"), [
$this->assertEquals([
"kialoGroupId" => $group->id,
"kialoGroupName" => $group->name,
], $token->claims()->get("https://purl.imsglobal.org/spec/lti/claim/custom"));
}

/**
* Tests the initial LTI flow step with groups.
*
* @covers \mod_kialo\lti_flow::init_resource_link
*/
public function test_init_resource_link_with_grouping(): void {
// Given one student in a group.
$this->getDataGenerator()->enrol_user($this->user->id, $this->course->id, "student");
$group = $this->getDataGenerator()->create_group([
'courseid' => $this->course->id,
'name' => 'Group 1',
]);
$grouping = $this->getDataGenerator()->create_grouping([
'courseid' => $this->course->id,
'name' => 'Grouping 1',
]);
$this->getDataGenerator()->create_grouping_group([
'groupingid' => $grouping->id,
'groupid' => $group->id,
]);
$this->getDataGenerator()->create_group_member([
'groupid' => $group->id,
'userid' => $this->user->id,
]);

$groupinfo = (object) [
'groupid' => "grouping-{$grouping->id}",
'groupname' => $grouping->name,
];

// Construct the initial LTI message sent to Kialo when the user clicks on the activity.
$deploymentid = "random-string-123";
$discussionurl = "random-discussion-url.com";
$message = lti_flow::init_resource_link(
$this->course->id,
$this->cmid,
$deploymentid,
$this->user->id,
$discussionurl,
$groupinfo->groupid,
$groupinfo->groupname
);
$this->assertNotNull($message);

$params = $message->getParameters()->jsonSerialize();

// The message hint is a JWT Token that contains the LTI details.
$token = $this->assert_jwt_signed_by_platform($params['lti_message_hint']);

// Group information is passed via custom claims.
$this->assertEquals([
"kialoGroupId" => "grouping-{$grouping->id}",
"kialoGroupName" => $grouping->name,
], $token->claims()->get("https://purl.imsglobal.org/spec/lti/claim/custom"));
}

/**
Expand Down

0 comments on commit e2a7b41

Please sign in to comment.