Skip to content

Commit

Permalink
Merge pull request #133 from snake/fix-lineitem-put
Browse files Browse the repository at this point in the history
Fix lineitem put
  • Loading branch information
dbhynds authored Feb 13, 2024
2 parents 47291d9 + 9218341 commit b09f311
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/LtiAssignmentsGradesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function updateLineitem(LtiLineItem $lineitemToUpdate): LtiLineitem
{
$request = new ServiceRequest(
ServiceRequest::METHOD_PUT,
$this->getServiceData()['lineitem'],
$lineitemToUpdate->getId(),
ServiceRequest::TYPE_UPDATE_LINEITEM
);

Expand Down
14 changes: 7 additions & 7 deletions src/LtiMessageLaunch.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ class LtiMessageLaunch
/**
* Constructor.
*
* @param IDatabase $database Instance of the database interface used for looking up registrations and deployments
* @param ICache $cache Instance of the Cache interface used to loading and storing launches
* @param ICookie $cookie Instance of the Cookie interface used to set and read cookies
* @param ILtiServiceConnector $serviceConnector Instance of the LtiServiceConnector used to by LTI services to make API requests
* @param IDatabase $database Instance of the database interface used for looking up registrations and deployments
* @param ICache $cache Instance of the Cache interface used to loading and storing launches
* @param ICookie $cookie Instance of the Cookie interface used to set and read cookies
* @param ILtiServiceConnector $serviceConnector Instance of the LtiServiceConnector used to by LTI services to make API requests
*/
public function __construct(
IDatabase $database,
Expand Down Expand Up @@ -108,9 +108,9 @@ public static function new(
/**
* Load an LtiMessageLaunch from a Cache using a launch id.
*
* @param string $launch_id The launch id of the LtiMessageLaunch object that is being pulled from the cache
* @param string $launch_id The launch id of the LtiMessageLaunch object that is being pulled from the cache
* @param IDatabase $database Instance of the database interface used for looking up registrations and deployments
* @param ICache $cache Instance of the Cache interface used to loading and storing launches. If non is provided launch data will be store in $_SESSION.
* @param ICache $cache Instance of the Cache interface used to loading and storing launches. If non is provided launch data will be store in $_SESSION.
* @return LtiMessageLaunch A populated and validated LtiMessageLaunch
*
* @throws LtiException Will throw an LtiException if validation fails or launch cannot be found
Expand Down Expand Up @@ -148,7 +148,7 @@ public function initialize(array $request)
/**
* Validates all aspects of an incoming LTI message launch and caches the launch if successful.
*
* @param array|string $request An array of post request parameters. If not set will default to $_POST.
* @param array|string $request An array of post request parameters. If not set will default to $_POST.
* @return LtiMessageLaunch Will return $this if validation is successful
*
* @throws LtiException Will throw an LtiException if validation fails
Expand Down
2 changes: 1 addition & 1 deletion src/LtiNamesRolesProvisioningService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function getScope(): array
}

/**
* @param array $options An array of options that can be passed with the context_membership_url such as rlid, since, etc.
* @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
{
Expand Down
10 changes: 5 additions & 5 deletions src/LtiOidcLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class LtiOidcLogin
/**
* Constructor.
*
* @param IDatabase $database Instance of the Database interface used for looking up registrations and deployments
* @param ICache $cache instance of the Cache interface used to loading and storing launches
* @param ICookie $cookie instance of the Cookie interface used to set and read cookies
* @param IDatabase $database Instance of the Database interface used for looking up registrations and deployments
* @param ICache $cache instance of the Cache interface used to loading and storing launches
* @param ICookie $cookie instance of the Cookie interface used to set and read cookies
*/
public function __construct(IDatabase $database, ?ICache $cache = null, ?ICookie $cookie = null)
{
Expand Down Expand Up @@ -70,8 +70,8 @@ public function doOidcLoginRedirect($launchUrl, ?array $request = null)
/**
* Calculate the redirect location to return to based on an OIDC third party initiated login request.
*
* @param string $launchUrl URL to redirect back to after the OIDC login. This URL must match exactly a URL white listed in the platform.
* @param array $request An array of request parameters.
* @param string $launchUrl URL to redirect back to after the OIDC login. This URL must match exactly a URL white listed in the platform.
* @param array $request An array of request parameters.
* @return string returns the fully formed OIDC login URL
*/
public function getRedirectUrl(string $launchUrl, array $request): string
Expand Down
54 changes: 54 additions & 0 deletions tests/LtiAssignmentsGradesServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,58 @@ public function testItDeletesALineItem()

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

public function testItCreatesALineItem()
{
$serviceData = [
'scope' => [LtiConstants::AGS_SCOPE_LINEITEM],
'lineitems' => 'https://lms.example.com/context/2923/lineitems/',
];

$service = new LtiAssignmentsGradesService($this->connector, $this->registration, $serviceData);

$ltiLineitemData = [
'id' => 'https://lms.example.com/context/2923/lineitems/23',
];

$response = [
'body' => $ltiLineitemData,
];

$this->connector->shouldReceive('makeServiceRequest')
->once()->andReturn($response);

$expected = new LtiLineitem($ltiLineitemData);

$result = $service->createLineitem(new LtiLineitem($ltiLineitemData));

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

public function testItUpdatesALineItem()
{
$serviceData = [
'scope' => [LtiConstants::AGS_SCOPE_LINEITEM],
'lineitems' => 'https://lms.example.com/context/2923/lineitems/',
];

$service = new LtiAssignmentsGradesService($this->connector, $this->registration, $serviceData);

$ltiLineitemData = [
'id' => 'https://lms.example.com/context/2923/lineitems/23',
];

$response = [
'body' => $ltiLineitemData,
];

$this->connector->shouldReceive('makeServiceRequest')
->once()->andReturn($response);

$expected = new LtiLineitem($ltiLineitemData);

$result = $service->updateLineitem(new LtiLineitem($ltiLineitemData));

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

0 comments on commit b09f311

Please sign in to comment.