1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* responsive-images-css |
5
|
|
|
* |
6
|
|
|
* @category Jkphl |
7
|
|
|
* @package Jkphl\Respimgcss |
8
|
|
|
* @subpackage Jkphl\Respimgcss\Tests |
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
10
|
|
|
* @copyright Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl |
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/*********************************************************************************** |
15
|
|
|
* The MIT License (MIT) |
16
|
|
|
* |
17
|
|
|
* Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl |
18
|
|
|
* |
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
21
|
|
|
* the Software without restriction, including without limitation the rights to |
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
24
|
|
|
* subject to the following conditions: |
25
|
|
|
* |
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
27
|
|
|
* copies or substantial portions of the Software. |
28
|
|
|
* |
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
35
|
|
|
***********************************************************************************/ |
36
|
|
|
|
37
|
|
|
namespace Jkphl\Respimgcss\Tests\Application; |
38
|
|
|
|
39
|
|
|
use Jkphl\Respimgcss\Application\Factory\ImageCandidateFactory; |
40
|
|
|
use Jkphl\Respimgcss\Domain\Model\DensityImageCandidate; |
41
|
|
|
use Jkphl\Respimgcss\Domain\Model\WidthImageCandidate; |
42
|
|
|
use Jkphl\Respimgcss\Tests\AbstractTestBase; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Image candidate factory test |
46
|
|
|
* |
47
|
|
|
* @package Jkphl\Respimgcss |
48
|
|
|
* @subpackage Jkphl\Respimgcss\Tests |
49
|
|
|
*/ |
50
|
|
|
class ImageCandidateFactoryTest extends AbstractTestBase |
51
|
|
|
{ |
52
|
|
|
/** |
53
|
|
|
* Test the image candidate factory with an invalid image candidate string |
54
|
|
|
* |
55
|
|
|
* @expectedException \Jkphl\Respimgcss\Application\Exceptions\InvalidArgumentException |
56
|
|
|
* @expectedExceptionCode 1522500150 |
57
|
|
|
*/ |
58
|
|
|
public function testImageCandidateFactoryWithInvalidString() |
59
|
|
|
{ |
60
|
|
|
ImageCandidateFactory::createImageCandidateFromString('invalid image candidate string'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Test the image candidate factory with a pixel density based candidate |
65
|
|
|
*/ |
66
|
|
|
public function testImageCandidateFactoryWithPixelDensityString() |
67
|
|
|
{ |
68
|
|
|
$pixelDensityImageCandidate = ImageCandidateFactory::createImageCandidateFromString('image.jpg 1x'); |
69
|
|
|
$this->assertInstanceOf(DensityImageCandidate::class, $pixelDensityImageCandidate); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Test the image candidate factory with an undefined candidate notation |
74
|
|
|
*/ |
75
|
|
|
public function testImageCandidateFactoryWithImpliedPixelDensityString() |
76
|
|
|
{ |
77
|
|
|
$pixelDensityImageCandidate = ImageCandidateFactory::createImageCandidateFromString('image.jpg'); |
78
|
|
|
$this->assertInstanceOf(DensityImageCandidate::class, $pixelDensityImageCandidate); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Test the image candidate factory with a pixel density based candidate |
83
|
|
|
*/ |
84
|
|
|
public function testImageCandidateFactoryWithWidthString() |
85
|
|
|
{ |
86
|
|
|
$widthImageCandidate = ImageCandidateFactory::createImageCandidateFromString('image.jpg 1000w'); |
87
|
|
|
$this->assertInstanceOf(WidthImageCandidate::class, $widthImageCandidate); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Test the image candidate factory with an invalid image candidate file |
92
|
|
|
* |
93
|
|
|
* @expectedException \Jkphl\Respimgcss\Application\Exceptions\InvalidArgumentException |
94
|
|
|
* @expectedExceptionCode 1522502569 |
95
|
|
|
*/ |
96
|
|
|
public function testImageCandidateFactoryWithInvalidFile() |
97
|
|
|
{ |
98
|
|
|
ImageCandidateFactory::createImageCandidateFromFileAndDescriptor(''); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Test the image candidate factory with an invalid image candidate descriptor |
103
|
|
|
* |
104
|
|
|
* @expectedException \Jkphl\Respimgcss\Application\Exceptions\InvalidArgumentException |
105
|
|
|
* @expectedExceptionCode 1522502721 |
106
|
|
|
*/ |
107
|
|
|
public function testImageCandidateFactoryWithInvalidDescriptor() |
108
|
|
|
{ |
109
|
|
|
ImageCandidateFactory::createImageCandidateFromFileAndDescriptor('image.jpg', '124abc'); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Test the image candidate factory with a pixel density based file and descriptor |
114
|
|
|
*/ |
115
|
|
|
public function testImageCandidateFactoryWithPixelDensityDescriptor() |
116
|
|
|
{ |
117
|
|
|
$pixelDensityImageCandidate = ImageCandidateFactory::createImageCandidateFromFileAndDescriptor( |
118
|
|
|
'image.jpg', |
119
|
|
|
'1x' |
120
|
|
|
); |
121
|
|
|
$this->assertInstanceOf(DensityImageCandidate::class, $pixelDensityImageCandidate); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Test the image candidate factory with an undefined candidate descriptor |
126
|
|
|
*/ |
127
|
|
|
public function testImageCandidateFactoryWithImpliedPixelDensityDescriptor() |
128
|
|
|
{ |
129
|
|
|
$pixelDensityImageCandidate = ImageCandidateFactory::createImageCandidateFromFileAndDescriptor('image.jpg'); |
130
|
|
|
$this->assertInstanceOf(DensityImageCandidate::class, $pixelDensityImageCandidate); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Test the image candidate factory with a pixel density based candidate |
135
|
|
|
*/ |
136
|
|
|
public function testImageCandidateFactoryWithWidthDescriptor() |
137
|
|
|
{ |
138
|
|
|
$widthImageCandidate = ImageCandidateFactory::createImageCandidateFromFileAndDescriptor( |
139
|
|
|
'image.jpg', |
140
|
|
|
'1000w' |
141
|
|
|
); |
142
|
|
|
$this->assertInstanceOf(WidthImageCandidate::class, $widthImageCandidate); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|