Skip to content

Commit

Permalink
Merge pull request #110 from dcaswel/getMembersForResourceLink
Browse files Browse the repository at this point in the history
Adding options to getMembers
  • Loading branch information
dbhynds authored Nov 20, 2023
2 parents a1aaa68 + 79bb16b commit 3ddfb3e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
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);
}
}

0 comments on commit 3ddfb3e

Please sign in to comment.