Skip to content

Commit 139bda1

Browse files
committed
Added new extensive unit tests
1 parent 477118c commit 139bda1

File tree

2 files changed

+106
-2
lines changed

2 files changed

+106
-2
lines changed

src/Image/ImageRepresentation.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
namespace le0daniel\Laravel\ImageEngine\Image;
44

55
use Carbon\Carbon;
6-
use Illuminate\Contracts\Filesystem\Filesystem;
7-
use Illuminate\Support\Facades\Storage;
86
use le0daniel\Laravel\ImageEngine\Utility\Arrays;
97
use le0daniel\Laravel\ImageEngine\Utility\Base64;
108
use le0daniel\Laravel\ImageEngine\Utility\Json;
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
3+
namespace le0daniel\Tests\Laravel\ImageEngine\Image;
4+
5+
use Carbon\Carbon;
6+
use le0daniel\Laravel\ImageEngine\Image\ImageRepresentation;
7+
use PHPUnit\Framework\TestCase;
8+
9+
final class ImageRepresentationTest extends TestCase
10+
{
11+
/** @dataProvider fromSerializedDataProvider */
12+
public function testFromSerialized($expectedSerialized, ImageRepresentation $image)
13+
{
14+
$serialized = $image->serialize();
15+
$this->assertSame($expectedSerialized, $serialized);
16+
$unserializedImage = ImageRepresentation::fromSerialized($serialized);
17+
18+
foreach (['filePath', 'size', 'expires', 'diskName'] as $attribute) {
19+
$this->assertEquals(
20+
$image->{$attribute},
21+
$unserializedImage->{$attribute}
22+
);
23+
}
24+
}
25+
26+
public function fromSerializedDataProvider()
27+
{
28+
return [
29+
'Simple image' => [
30+
'eyJwIjoiZmlsZSIsInMiOiJtZWRpdW0ifQ',
31+
ImageRepresentation::from('file', 'medium'),
32+
],
33+
'Image with expiry' => [
34+
'eyJwIjoiZmlsZSIsInMiOiJtZWRpdW0iLCJlIjoxMDB9',
35+
ImageRepresentation::from('file', 'medium', 100),
36+
],
37+
'Image with all attributes' => [
38+
'eyJkIjoiZGlzayIsInAiOiJmaWxlIiwicyI6Im1lZGl1bSIsImUiOjEwMH0',
39+
ImageRepresentation::from('file', 'medium', 100, 'disk'),
40+
],
41+
'Image with carbon time' => [
42+
'eyJkIjoiZGlzayIsInAiOiJmaWxlIiwicyI6Im1lZGl1bSIsImUiOjEwMH0',
43+
ImageRepresentation::from('file', 'medium', Carbon::createFromTimestamp(100), 'disk'),
44+
],
45+
'Image without expires' => [
46+
'eyJkIjoiZGlzayIsInAiOiJmaWxlIiwicyI6Im1lZGl1bSJ9',
47+
ImageRepresentation::from('file', 'medium', null, 'disk'),
48+
],
49+
];
50+
}
51+
52+
public function testIsConfidential()
53+
{
54+
$this->assertTrue(ImageRepresentation::from('file', 'medium', 100, 'disk')->isConfidential);
55+
$this->assertFalse(ImageRepresentation::from('file', 'medium')->isConfidential);
56+
}
57+
58+
public function testIsExpired()
59+
{
60+
$this->assertFalse(ImageRepresentation::from('file', 'medium', now()->addMinutes(100), 'disk')->isExpired);
61+
$this->assertFalse(ImageRepresentation::from('file', 'medium')->isExpired);
62+
$this->assertTrue(ImageRepresentation::from('file', 'medium', now()->subMinutes(100), 'disk')->isExpired);
63+
64+
}
65+
66+
public function testExpiresCarbon()
67+
{
68+
$this->assertInstanceOf(
69+
Carbon::class,
70+
ImageRepresentation::from('file', 'medium', 100, 'disk')->expiresCarbon
71+
);
72+
$this->assertNull(ImageRepresentation::from('file', 'medium')->expiresCarbon);
73+
}
74+
75+
public function testTimestamp()
76+
{
77+
$this->assertEquals(100,ImageRepresentation::from('file', 'medium', 100, 'disk')->timestamp);
78+
$this->assertNull(ImageRepresentation::from('file', 'medium')->timestamp);
79+
}
80+
81+
public function testExtensions()
82+
{
83+
$extensions = ['png', 'jpg', 'tiff', 'some'];
84+
foreach ($extensions as $extension) {
85+
$image = ImageRepresentation::from("file.$extension", 'medium');
86+
$this->assertEquals($extension, $image->extension);
87+
}
88+
}
89+
90+
// public function testCacheControlHeaders()
91+
// {
92+
// }
93+
94+
public function testFrom()
95+
{
96+
$this->assertInstanceOf(ImageRepresentation::class, ImageRepresentation::from('file', 'medium'));
97+
}
98+
99+
// public function testToArray()
100+
// {
101+
// }
102+
//
103+
// public function testSerialize()
104+
// {
105+
// }
106+
}

0 commit comments

Comments
 (0)