|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LauLamanApps\IzettleApi\Tests\Unit\Api; |
|
6
|
|
|
|
|
7
|
|
|
use LauLamanApps\IzettleApi\API\Image; |
|
8
|
|
|
use LauLamanApps\IzettleApi\API\ImageCollection; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
final class ImageCollectionTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
/** @test */ |
|
14
|
|
|
public function imageCollection() |
|
15
|
|
|
{ |
|
16
|
|
|
$image1 = $this->getImageWithUuid('a.jpg'); |
|
17
|
|
|
$image2 = $this->getImageWithUuid('b.png'); |
|
18
|
|
|
$image3 = $this->getImageWithUuid('c.gif'); |
|
19
|
|
|
|
|
20
|
|
|
$imageCollection = new ImageCollection([$image1, $image2, $image3]); |
|
21
|
|
|
$imageCollection->add($image3);// add image 3 again it should only end up once in the collection |
|
22
|
|
|
|
|
23
|
|
|
//-- Check if collection contains all 3 images |
|
24
|
|
|
$collection = $imageCollection->getAll(); |
|
25
|
|
|
self::assertEquals(3, count($collection)); |
|
26
|
|
|
self::assertEquals($image1, $collection[$image1->getFilename()]); |
|
27
|
|
|
self::assertEquals($image2, $collection[$image2->getFilename()]); |
|
28
|
|
|
self::assertEquals($image3, $collection[$image3->getFilename()]); |
|
29
|
|
|
|
|
30
|
|
|
$imageCollection->remove($image2); |
|
31
|
|
|
|
|
32
|
|
|
//-- Check if collection does not contains image 2 but does contain the others |
|
33
|
|
|
$collection = $imageCollection->getAll(); |
|
34
|
|
|
self::assertEquals(2, count($collection)); |
|
35
|
|
|
self::assertEquals($image1, $collection[$image1->getFilename()]); |
|
36
|
|
|
self::assertEquals($image3, $collection[$image3->getFilename()]); |
|
37
|
|
|
self::assertFalse(array_key_exists($image2->getFilename(), $collection)); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** @test */ |
|
41
|
|
|
public function get() |
|
42
|
|
|
{ |
|
43
|
|
|
$filename = 'test.jpg'; |
|
44
|
|
|
$imageCollection = new ImageCollection([$this->getImageWithUuid($filename)]); |
|
45
|
|
|
|
|
46
|
|
|
$image = $imageCollection->get($filename); |
|
47
|
|
|
self::assertSame($filename, $image->getFilename()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
private function getImageWithUuid(string $filename): Image |
|
51
|
|
|
{ |
|
52
|
|
|
return new Image($filename); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|