diff --git a/src/LtiDeepLinkResource.php b/src/LtiDeepLinkResource.php index ee646e50..49e27b5a 100644 --- a/src/LtiDeepLinkResource.php +++ b/src/LtiDeepLinkResource.php @@ -8,100 +8,126 @@ class LtiDeepLinkResource private $title; private $text; private $url; - private $lineitem; + private $line_item; + private $icon; + private $thumbnail; private $custom_params = []; private $target = 'iframe'; - public static function new() + public static function new(): LtiDeepLinkResource { return new LtiDeepLinkResource(); } - public function getType() + public function getType(): string { return $this->type; } - public function setType($value) + public function setType(string $value): LtiDeepLinkResource { $this->type = $value; return $this; } - public function getTitle() + public function getTitle(): ?string { return $this->title; } - public function setTitle($value) + public function setTitle(?string $value): LtiDeepLinkResource { $this->title = $value; return $this; } - public function getText() + public function getText(): ?string { return $this->text; } - public function setText($value) + public function setText(?string $value): LtiDeepLinkResource { $this->text = $value; return $this; } - public function getUrl() + public function getUrl(): ?string { return $this->url; } - public function setUrl($value) + public function setUrl(?string $value): LtiDeepLinkResource { $this->url = $value; return $this; } - public function getLineitem() + public function getLineItem(): ?LtiLineitem { - return $this->lineitem; + return $this->line_item; } - public function setLineitem(LtiLineitem $value) + public function setLineItem(?LtiLineitem $value): LtiDeepLinkResource { - $this->lineitem = $value; + $this->line_item = $value; return $this; } - public function getCustomParams() + public function setIcon(?LtiDeepLinkResourceIcon $icon): LtiDeepLinkResource + { + $this->icon = $icon; + + return $this; + } + + public function getIcon(): ?LtiDeepLinkResourceIcon + { + return $this->icon; + } + + public function setThumbnail(?LtiDeepLinkResourceIcon $thumbnail): LtiDeepLinkResource + { + $this->thumbnail = $thumbnail; + + return $this; + } + + public function getThumbnail(): ?LtiDeepLinkResourceIcon + { + return $this->thumbnail; + } + + public function getCustomParams(): array { return $this->custom_params; } - public function setCustomParams($value) + public function setCustomParams(array $value): LtiDeepLinkResource { $this->custom_params = $value; return $this; } - public function getTarget() + public function getTarget(): string { return $this->target; } - public function setTarget($value) + public function setTarget(string $value): LtiDeepLinkResource { $this->target = $value; return $this; } - public function toArray() + public function toArray(): array { $resource = [ 'type' => $this->type, @@ -115,10 +141,16 @@ public function toArray() if (!empty($this->custom_params)) { $resource['custom'] = $this->custom_params; } - if ($this->lineitem !== null) { + if (isset($this->icon)) { + $resource['icon'] = $this->icon->toArray(); + } + if (isset($this->thumbnail)) { + $resource['thumbnail'] = $this->thumbnail->toArray(); + } + if ($this->line_item !== null) { $resource['lineItem'] = [ - 'scoreMaximum' => $this->lineitem->getScoreMaximum(), - 'label' => $this->lineitem->getLabel(), + 'scoreMaximum' => $this->line_item->getScoreMaximum(), + 'label' => $this->line_item->getLabel(), ]; } diff --git a/src/LtiDeepLinkResourceIcon.php b/src/LtiDeepLinkResourceIcon.php new file mode 100644 index 00000000..f037910b --- /dev/null +++ b/src/LtiDeepLinkResourceIcon.php @@ -0,0 +1,67 @@ +url = $url; + $this->width = $width; + $this->height = $height; + } + + public static function new(string $url, int $width, int $height): LtiDeepLinkResourceIcon + { + return new LtiDeepLinkResourceIcon($url, $width, $height); + } + + public function setUrl(string $url): LtiDeepLinkResourceIcon + { + $this->url = $url; + + return $this; + } + + public function getUrl(): string + { + return $this->url; + } + + public function setWidth(int $width): LtiDeepLinkResourceIcon + { + $this->width = $width; + + return $this; + } + + public function getWidth(): int + { + return $this->width; + } + + public function setHeight(int $height): LtiDeepLinkResourceIcon + { + $this->height = $height; + + return $this; + } + + public function getHeight(): int + { + return $this->height; + } + + public function toArray(): array + { + return [ + 'url' => $this->url, + 'width' => $this->width, + 'height' => $this->height, + ]; + } +} diff --git a/tests/LtiDeepLinkResourceIconTest.php b/tests/LtiDeepLinkResourceIconTest.php new file mode 100644 index 00000000..a538968b --- /dev/null +++ b/tests/LtiDeepLinkResourceIconTest.php @@ -0,0 +1,91 @@ +imageUrl = 'https://example.com/image.png'; + $this->deepLinkResourceIcon = new LtiDeepLinkResourceIcon($this->imageUrl, 1, 2); + } + + public function testItInstantiates() + { + $this->assertInstanceOf(LtiDeepLinkResourceIcon::class, $this->deepLinkResourceIcon); + } + + public function testItCreatesANewInstance() + { + $deepLinkResource = LtiDeepLinkResourceIcon::new($this->imageUrl, 100, 200); + + $this->assertInstanceOf(LtiDeepLinkResourceIcon::class, $deepLinkResource); + } + + public function testItGetsUrl() + { + $result = $this->deepLinkResourceIcon->getUrl(); + + $this->assertEquals($this->imageUrl, $result); + } + + public function testItSetsUrl() + { + $expected = 'expected'; + + $this->deepLinkResourceIcon->setUrl($expected); + + $this->assertEquals($expected, $this->deepLinkResourceIcon->getUrl()); + } + + public function testItGetsWidth() + { + $result = $this->deepLinkResourceIcon->getWidth(); + + $this->assertEquals(1, $result); + } + + public function testItSetsWidth() + { + $expected = 300; + + $this->deepLinkResourceIcon->setWidth($expected); + + $this->assertEquals($expected, $this->deepLinkResourceIcon->getWidth()); + } + + public function testItGetsHeight() + { + $result = $this->deepLinkResourceIcon->getHeight(); + + $this->assertEquals(2, $result); + } + + public function testItSetsHeight() + { + $expected = 400; + + $this->deepLinkResourceIcon->setHeight($expected); + + $this->assertEquals($expected, $this->deepLinkResourceIcon->getHeight()); + } + + public function testItCastsToArray() + { + $expected = [ + 'url' => $this->imageUrl, + 'width' => 100, + 'height' => 200, + ]; + + $this->deepLinkResourceIcon->setUrl($expected['url']); + $this->deepLinkResourceIcon->setWidth($expected['width']); + $this->deepLinkResourceIcon->setHeight($expected['height']); + + $result = $this->deepLinkResourceIcon->toArray(); + + $this->assertEquals($expected, $result); + } +} diff --git a/tests/LtiDeepLinkResourceTest.php b/tests/LtiDeepLinkResourceTest.php index f2f39f61..d82cc608 100644 --- a/tests/LtiDeepLinkResourceTest.php +++ b/tests/LtiDeepLinkResourceTest.php @@ -4,12 +4,14 @@ use Mockery; use Packback\Lti1p3\LtiDeepLinkResource; +use Packback\Lti1p3\LtiDeepLinkResourceIcon; use Packback\Lti1p3\LtiLineitem; class LtiDeepLinkResourceTest extends TestCase { public function setUp(): void { + $this->imageUrl = 'https://example.com/image.png'; $this->deepLinkResource = new LtiDeepLinkResource(); } @@ -91,7 +93,7 @@ public function testItSetsUrl() public function testItGetsLineitem() { - $result = $this->deepLinkResource->getLineitem(); + $result = $this->deepLinkResource->getLineItem(); $this->assertNull($result); } @@ -100,9 +102,41 @@ public function testItSetsLineitem() { $expected = Mockery::mock(LtiLineitem::class); - $this->deepLinkResource->setLineitem($expected); + $this->deepLinkResource->setLineItem($expected); - $this->assertEquals($expected, $this->deepLinkResource->getLineitem()); + $this->assertEquals($expected, $this->deepLinkResource->getLineItem()); + } + + public function testItGetsIcon() + { + $result = $this->deepLinkResource->getIcon(); + + $this->assertNull($result); + } + + public function testItSetsIcon() + { + $expected = Mockery::mock(LtiDeepLinkResourceIcon::class); + + $this->deepLinkResource->setIcon($expected); + + $this->assertEquals($expected, $this->deepLinkResource->getIcon()); + } + + public function testItGetsThumbnail() + { + $result = $this->deepLinkResource->getThumbnail(); + + $this->assertNull($result); + } + + public function testItSetsThumbnail() + { + $expected = Mockery::mock(LtiDeepLinkResourceIcon::class); + + $this->deepLinkResource->setThumbnail($expected); + + $this->assertEquals($expected, $this->deepLinkResource->getThumbnail()); } public function testItGetsCustomParams() @@ -114,7 +148,7 @@ public function testItGetsCustomParams() public function testItSetsCustomParams() { - $expected = 'expected'; + $expected = ['a_key' => 'a_value']; $this->deepLinkResource->setCustomParams($expected); @@ -139,11 +173,23 @@ public function testItSetsTarget() public function testItCastsToArray() { + $icon = LtiDeepLinkResourceIcon::new($this->imageUrl, 100, 200); + $expected = [ 'type' => 'ltiResourceLink', 'title' => 'a_title', 'text' => 'a_text', 'url' => 'a_url', + 'icon' => [ + 'url' => $icon->getUrl(), + 'width' => $icon->getWidth(), + 'height' => $icon->getHeight(), + ], + 'thumbnail' => [ + 'url' => $icon->getUrl(), + 'width' => $icon->getWidth(), + 'height' => $icon->getHeight(), + ], 'presentation' => [ 'documentTarget' => 'iframe', ], @@ -152,6 +198,7 @@ public function testItCastsToArray() 'label' => 'lineitem_label', ], ]; + $lineitem = Mockery::mock(LtiLineitem::class); $lineitem->shouldReceive('getScoreMaximum') ->twice()->andReturn($expected['lineItem']['scoreMaximum']); @@ -161,7 +208,9 @@ public function testItCastsToArray() $this->deepLinkResource->setTitle($expected['title']); $this->deepLinkResource->setText($expected['text']); $this->deepLinkResource->setUrl($expected['url']); - $this->deepLinkResource->setLineitem($lineitem); + $this->deepLinkResource->setIcon($icon); + $this->deepLinkResource->setThumbnail($icon); + $this->deepLinkResource->setLineItem($lineitem); $result = $this->deepLinkResource->toArray();