diff --git a/src/LtiNamesRolesProvisioningService.php b/src/LtiNamesRolesProvisioningService.php index afad6d3a..02aa13c9 100644 --- a/src/LtiNamesRolesProvisioningService.php +++ b/src/LtiNamesRolesProvisioningService.php @@ -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); diff --git a/tests/LtiNamesRolesProvisioningServiceTest.php b/tests/LtiNamesRolesProvisioningServiceTest.php index cc0c24d5..b68037d1 100644 --- a/tests/LtiNamesRolesProvisioningServiceTest.php +++ b/tests/LtiNamesRolesProvisioningServiceTest.php @@ -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); + } }