forked from 1EdTech/lti-1-3-php-library
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request 1EdTech#64 from JanHolger/add-icon-to-deep-link-re…
…source Add icon to deep link resource
- Loading branch information
Showing
4 changed files
with
266 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.