1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* responsive-images-css |
5
|
|
|
* |
6
|
|
|
* @category Jkphl |
7
|
|
|
* @package Jkphl\Respimgcss |
8
|
|
|
* @subpackage Jkphl\Respimgcss\Tests\Infrastructure |
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\SourceSizeFactory; |
40
|
|
|
use Jkphl\Respimgcss\Application\Model\SourceSize; |
41
|
|
|
use Jkphl\Respimgcss\Domain\Model\Css\WidthMediaCondition; |
42
|
|
|
use Jkphl\Respimgcss\Infrastructure\ViewportCalculatorServiceFactory; |
43
|
|
|
use Jkphl\Respimgcss\Tests\AbstractTestBase; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Source size factory tests |
47
|
|
|
* |
48
|
|
|
* @package Jkphl\Respimgcss |
49
|
|
|
* @subpackage Jkphl\Respimgcss\Tests\Infrastructure |
50
|
|
|
*/ |
51
|
|
|
class SourceSizeFactoryTest extends AbstractTestBase |
52
|
|
|
{ |
53
|
|
|
/** |
54
|
|
|
* Source size factory |
55
|
|
|
* |
56
|
|
|
* @var SourceSizeFactory |
57
|
|
|
*/ |
58
|
|
|
protected $sourceSizeFactory; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Test setup |
62
|
|
|
*/ |
63
|
|
|
protected function setUp()/* The :void return type declaration that should be here would cause a BC issue */ |
64
|
|
|
{ |
65
|
|
|
$this->sourceSizeFactory = new SourceSizeFactory(new ViewportCalculatorServiceFactory(), 16); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Test the source size factory with a viewport size value |
70
|
|
|
*/ |
71
|
|
|
public function testSourceSizeFactoryViewport() |
72
|
|
|
{ |
73
|
|
|
$this->assertInstanceOf(SourceSizeFactory::class, $this->sourceSizeFactory); |
74
|
|
|
|
75
|
|
|
$sourceSize = $this->sourceSizeFactory->createFromSourceSizeStr('((max-width: 500px) and (resolution: 1)) 100vw'); |
76
|
|
|
$this->assertInstanceOf(SourceSize::class, $sourceSize); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Test the source size factory with a calc() size value |
81
|
|
|
*/ |
82
|
|
|
public function testSourceSizeFactoryCalc() |
83
|
|
|
{ |
84
|
|
|
$this->assertInstanceOf(SourceSizeFactory::class, $this->sourceSizeFactory); |
85
|
|
|
|
86
|
|
|
$sourceSize = $this->sourceSizeFactory->createFromSourceSizeStr('(max-width: 500px) calc(40vw - 100px)'); |
87
|
|
|
$this->assertInstanceOf(SourceSize::class, $sourceSize); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Test the source size factory with an invalid string |
92
|
|
|
* |
93
|
|
|
* @expectedException \Jkphl\Respimgcss\Application\Exceptions\InvalidArgumentException |
94
|
|
|
* @expectedExceptionCode 1522685593 |
95
|
|
|
*/ |
96
|
|
|
public function testSourceSizeFactoryInvalid() |
97
|
|
|
{ |
98
|
|
|
$this->sourceSizeFactory->createFromSourceSizeStr(''); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Test the source size factory with an invalid string |
103
|
|
|
* |
104
|
|
|
* @expectedException \Jkphl\Respimgcss\Application\Exceptions\InvalidArgumentException |
105
|
|
|
* @expectedExceptionCode 1522685593 |
106
|
|
|
*/ |
107
|
|
|
public function testSourceSizeFactoryInvalidCalc1() |
108
|
|
|
{ |
109
|
|
|
$this->sourceSizeFactory->createFromSourceSizeStr(')'); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Test the source size factory with an invalid string |
114
|
|
|
* |
115
|
|
|
* @expectedException \Jkphl\Respimgcss\Application\Exceptions\InvalidArgumentException |
116
|
|
|
* @expectedExceptionCode 1522685593 |
117
|
|
|
*/ |
118
|
|
|
public function testSourceSizeFactoryInvalidCalc2() |
119
|
|
|
{ |
120
|
|
|
$this->sourceSizeFactory->createFromSourceSizeStr('calc())'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Test the source size factory with an invalid string |
125
|
|
|
*/ |
126
|
|
|
public function testSourceSizeFactoryInvalidWidthResolution() |
127
|
|
|
{ |
128
|
|
|
$sourceSize = $this->sourceSizeFactory->createFromSourceSizeStr('((min-width: 123abc) and (min-resolution: 123abc)) 100vw'); |
129
|
|
|
$this->assertInstanceOf(SourceSize::class, $sourceSize); |
130
|
|
|
$this->assertTrue(is_array($sourceSize->getMediaCondition()->getConditions())); |
131
|
|
|
$this->assertEquals([], $sourceSize->getMediaCondition()->getConditions()); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Test the source size factory with a calc based media condition value |
136
|
|
|
*/ |
137
|
|
|
public function testSourceSizeFactoryWidthCalc() |
138
|
|
|
{ |
139
|
|
|
$sourceSize = $this->sourceSizeFactory->createFromSourceSizeStr('(min-width: calc(33em - 100px)) 100vw'); |
140
|
|
|
$this->assertInstanceOf(SourceSize::class, $sourceSize); |
141
|
|
|
|
142
|
|
|
$sourceSizeMediaCondition = $sourceSize->getMediaCondition(); |
143
|
|
|
$this->assertTrue(is_array($sourceSizeMediaCondition->getConditions())); |
144
|
|
|
$this->assertEquals(1, count($sourceSizeMediaCondition->getConditions())); |
145
|
|
|
|
146
|
|
|
$mediaCondition = current($sourceSizeMediaCondition->getConditions()); |
147
|
|
|
$this->assertInstanceOf(WidthMediaCondition::class, $mediaCondition); |
148
|
|
|
$this->assertEquals(428, $mediaCondition->getValue()->getValue()); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Test the source size factory with an invalid calc based media condition value |
153
|
|
|
*/ |
154
|
|
|
public function testSourceSizeFactoryWidthInvalidCalc() |
155
|
|
|
{ |
156
|
|
|
$sourceSize = $this->sourceSizeFactory->createFromSourceSizeStr('(min-width: calc((33em - 100px) 100vw'); |
157
|
|
|
$this->assertInstanceOf(SourceSize::class, $sourceSize); |
158
|
|
|
$this->assertTrue(is_array($sourceSize->getMediaCondition()->getConditions())); |
159
|
|
|
$this->assertEquals([], $sourceSize->getMediaCondition()->getConditions()); |
160
|
|
|
} |
161
|
|
|
} |