Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding options to getMembers #110

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/LtiNamesRolesProvisioningService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ public function getScope(): array
return [LtiConstants::NRPS_SCOPE_MEMBERSHIP_READONLY];
}

public function getMembers(): array
/**
* @param array $options An array of options that can be passed with the context_membership_url such as rlid, since, etc.
*/
public function getMembers(array $options = []): array
{
$url = $this->getServiceData()['context_memberships_url'];
if (!empty($options)) {
$url .= '?'.http_build_query($options);
}
$request = new ServiceRequest(
ServiceRequest::METHOD_GET,
$this->getServiceData()['context_memberships_url'],
$url,
ServiceRequest::TYPE_GET_MEMBERSHIPS
);
$request->setAccept(static::CONTENTTYPE_MEMBERSHIPCONTAINER);
Expand Down
18 changes: 18 additions & 0 deletions tests/LtiNamesRolesProvisioningServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,22 @@ public function testItGetsMembers()

$this->assertEquals($expected, $result);
}

public function testItGetsMembersForResourceLink()
{
$expected = ['members'];

$nrps = new LtiNamesRolesProvisioningService($this->connector, $this->registration, [
'context_memberships_url' => 'url',
]);
$this->connector->shouldReceive('getAll')
->withArgs(function ($registration, $scope, $request, $key) {
return $request->getUrl() === 'url?rlid=resource-link-id' && $key === 'members';
})
->once()->andReturn($expected);

$result = $nrps->getMembers(['rlid' => 'resource-link-id']);

$this->assertEquals($expected, $result);
}
}