|
1
|
|
|
<?php namespace Modules\Tests; |
|
2
|
|
|
|
|
3
|
|
|
use Modules\Media\Image\Thumbnail; |
|
4
|
|
|
|
|
5
|
|
|
class ThumbnailTest extends \PHPUnit_Framework_TestCase |
|
6
|
|
|
{ |
|
7
|
|
|
/** @test */ |
|
8
|
|
|
public function it_creates_thumbnail_class() |
|
9
|
|
|
{ |
|
10
|
|
|
$thumbnail = Thumbnail::make($this->getBlogThumbnailConfig()); |
|
11
|
|
|
|
|
12
|
|
|
$this->assertInstanceOf('Modules\Media\Image\Thumbnail', $thumbnail); |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
/** @test */ |
|
16
|
|
|
public function it_gets_thumbnail_name() |
|
17
|
|
|
{ |
|
18
|
|
|
$thumbnail = Thumbnail::make($this->getBlogThumbnailConfig()); |
|
19
|
|
|
|
|
20
|
|
|
$this->assertEquals('blogThumb', $thumbnail->name()); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** @test */ |
|
24
|
|
|
public function it_gets_thumbnail_filters() |
|
25
|
|
|
{ |
|
26
|
|
|
$thumbnail = Thumbnail::make($this->getBlogThumbnailConfig()); |
|
27
|
|
|
|
|
28
|
|
|
$expected = [ |
|
29
|
|
|
'resize' => [ |
|
30
|
|
|
'width' => 150, |
|
31
|
|
|
'height' => 250, |
|
32
|
|
|
], |
|
33
|
|
|
'fit' => [ |
|
34
|
|
|
'width' => 550, |
|
35
|
|
|
'height' => 650, |
|
36
|
|
|
], |
|
37
|
|
|
]; |
|
38
|
|
|
$this->assertEquals($expected, $thumbnail->filters()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** @test */ |
|
42
|
|
|
public function it_gets_thumbnail_width() |
|
43
|
|
|
{ |
|
44
|
|
|
$thumbnail = Thumbnail::make($this->getBlogThumbnailConfig()); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertSame(150, $thumbnail->width()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** @test */ |
|
50
|
|
|
public function it_gets_thumbnail_height() |
|
51
|
|
|
{ |
|
52
|
|
|
$thumbnail = Thumbnail::make($this->getBlogThumbnailConfig()); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertSame(250, $thumbnail->height()); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** @test */ |
|
58
|
|
|
public function it_gets_thumbnail_size() |
|
59
|
|
|
{ |
|
60
|
|
|
$thumbnail = Thumbnail::make($this->getBlogThumbnailConfig()); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertSame('150x250', $thumbnail->size()); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** @test */ |
|
66
|
|
|
public function it_gets_multiple_thumbnails() |
|
67
|
|
|
{ |
|
68
|
|
|
$thumbnails = Thumbnail::makeMultiple($this->getMediaThumbnails()); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertCount(2, $thumbnails); |
|
71
|
|
|
$this->assertEquals('smallThumb', $thumbnails[0]->name()); |
|
72
|
|
|
$this->assertEquals('mediumThumb', $thumbnails[1]->name()); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
private function getBlogThumbnailConfig() |
|
76
|
|
|
{ |
|
77
|
|
|
return [ |
|
78
|
|
|
'blogThumb' => [ |
|
79
|
|
|
'resize' => [ |
|
80
|
|
|
'width' => 150, |
|
81
|
|
|
'height' => 250, |
|
82
|
|
|
], |
|
83
|
|
|
'fit' => [ |
|
84
|
|
|
'width' => 550, |
|
85
|
|
|
'height' => 650, |
|
86
|
|
|
], |
|
87
|
|
|
], |
|
88
|
|
|
]; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
private function getMediaThumbnails() |
|
92
|
|
|
{ |
|
93
|
|
|
return [ |
|
94
|
|
|
'smallThumb' => [ |
|
95
|
|
|
'resize' => [ |
|
96
|
|
|
'width' => 50, |
|
97
|
|
|
'height' => null, |
|
98
|
|
|
'callback' => function ($constraint) { |
|
99
|
|
|
$constraint->aspectRatio(); |
|
100
|
|
|
$constraint->upsize(); |
|
101
|
|
|
}, |
|
102
|
|
|
], |
|
103
|
|
|
], |
|
104
|
|
|
'mediumThumb' => [ |
|
105
|
|
|
'resize' => [ |
|
106
|
|
|
'width' => 180, |
|
107
|
|
|
'height' => null, |
|
108
|
|
|
'callback' => function ($constraint) { |
|
109
|
|
|
$constraint->aspectRatio(); |
|
110
|
|
|
$constraint->upsize(); |
|
111
|
|
|
}, |
|
112
|
|
|
], |
|
113
|
|
|
], |
|
114
|
|
|
]; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|