Skip to content

Commit 18c31d6

Browse files
authored
Merge pull request 1EdTech#59 from JanHolger/patch-2
Fix invalid request when specifying no custom params
2 parents 731813c + ffe4aae commit 18c31d6

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/LtiDeepLinkResource.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ public function toArray()
111111
'presentation' => [
112112
'documentTarget' => $this->target,
113113
],
114-
'custom' => $this->custom_params,
115114
];
115+
if (!empty($this->custom_params)) {
116+
$resource['custom'] = $this->custom_params;
117+
}
116118
if ($this->lineitem !== null) {
117119
$resource['lineItem'] = [
118120
'scoreMaximum' => $this->lineitem->getScoreMaximum(),

tests/LtiDeepLinkResourceTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,16 @@ public function testItCastsToArray()
147147
'presentation' => [
148148
'documentTarget' => 'iframe',
149149
],
150-
'custom' => [],
151150
'lineItem' => [
152151
'scoreMaximum' => 80,
153152
'label' => 'lineitem_label',
154153
],
155154
];
156155
$lineitem = Mockery::mock(LtiLineitem::class);
157156
$lineitem->shouldReceive('getScoreMaximum')
158-
->once()->andReturn($expected['lineItem']['scoreMaximum']);
157+
->twice()->andReturn($expected['lineItem']['scoreMaximum']);
159158
$lineitem->shouldReceive('getLabel')
160-
->once()->andReturn($expected['lineItem']['label']);
159+
->twice()->andReturn($expected['lineItem']['label']);
161160

162161
$this->deepLinkResource->setTitle($expected['title']);
163162
$this->deepLinkResource->setText($expected['text']);
@@ -167,5 +166,11 @@ public function testItCastsToArray()
167166
$result = $this->deepLinkResource->toArray();
168167

169168
$this->assertEquals($expected, $result);
169+
170+
// Test again with custom params
171+
$expected['custom'] = ['a_key' => 'a_value'];
172+
$this->deepLinkResource->setCustomParams(['a_key' => 'a_value']);
173+
$result = $this->deepLinkResource->toArray();
174+
$this->assertEquals($expected, $result);
170175
}
171176
}

0 commit comments

Comments
 (0)