Skip to content

Commit

Permalink
Merge pull request 1EdTech#64 from JanHolger/add-icon-to-deep-link-re…
Browse files Browse the repository at this point in the history
…source

Add icon to deep link resource
  • Loading branch information
dbhynds authored Aug 8, 2022
2 parents 5ea5cd7 + 5f7904c commit 63b9903
Show file tree
Hide file tree
Showing 4 changed files with 266 additions and 27 deletions.
76 changes: 54 additions & 22 deletions src/LtiDeepLinkResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
];
}

Expand Down
67 changes: 67 additions & 0 deletions src/LtiDeepLinkResourceIcon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Packback\Lti1p3;

class LtiDeepLinkResourceIcon
{
private $url;
private $width;
private $height;

public function __construct(string $url, int $width, int $height)
{
$this->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,
];
}
}
91 changes: 91 additions & 0 deletions tests/LtiDeepLinkResourceIconTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace Tests;

use Packback\Lti1p3\LtiDeepLinkResourceIcon;

class LtiDeepLinkResourceIconTest extends TestCase
{
public function setUp(): void
{
$this->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);
}
}
Loading

0 comments on commit 63b9903

Please sign in to comment.