1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace ParamProcessor\Tests\Integration; |
6
|
|
|
|
7
|
|
|
use ParamProcessor\ParamDefinitionFactory; |
8
|
|
|
use ParamProcessor\ParameterTypes; |
9
|
|
|
use ParamProcessor\ProcessingResult; |
10
|
|
|
use ParamProcessor\Processor; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
|
13
|
|
|
class DimensionTypeTest extends TestCase { |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @dataProvider widthProvider |
17
|
|
|
*/ |
18
|
|
|
public function testWidth( string $input, string $expected ) { |
19
|
|
|
$parameters = $this->process( |
20
|
|
|
[ |
21
|
|
|
'width' => [ |
22
|
|
|
'type' => ParameterTypes::DIMENSION, |
23
|
|
|
'message' => 'test-message' |
24
|
|
|
] |
25
|
|
|
], |
26
|
|
|
[ |
27
|
|
|
'width' => $input, |
28
|
|
|
] |
29
|
|
|
)->getParameterArray(); |
30
|
|
|
|
31
|
|
|
$this->assertSame( $expected, $parameters['width'] ); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function widthProvider() { |
35
|
|
|
yield [ '10', '10px' ]; |
36
|
|
|
yield [ '10px', '10px' ]; |
37
|
|
|
yield [ '10%', '10%' ]; |
38
|
|
|
yield [ '10em', '10em' ]; |
39
|
|
|
yield [ '10ex', '10ex' ]; |
40
|
|
|
yield [ 'auto', 'auto' ]; |
41
|
|
|
yield [ ' 10 ', '10px' ]; |
42
|
|
|
yield [ ' 1 ', '1px' ]; |
43
|
|
|
yield [ '1 px', '1 px' ]; |
44
|
|
|
yield [ '1 ex', '1 ex' ]; |
45
|
|
|
// TODO: make sure unit is after the value |
46
|
|
|
// TODO: make sure only the unit is present |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
private function process( array $definitionArrays, array $userInput ): ProcessingResult { |
50
|
|
|
$processor = Processor::newDefault(); |
51
|
|
|
|
52
|
|
|
$processor->setParameters( $userInput ); |
53
|
|
|
$processor->setParameterDefinitions( |
54
|
|
|
ParamDefinitionFactory::newDefault()->newDefinitionsFromArrays( $definitionArrays ) |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
return $processor->processParameters(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @dataProvider heightProvider |
62
|
|
|
*/ |
63
|
|
|
public function testHeight( string $input, string $expected ) { |
64
|
|
|
$parameters = $this->process( |
65
|
|
|
[ |
66
|
|
|
'height' => [ |
67
|
|
|
'type' => ParameterTypes::DIMENSION, |
68
|
|
|
'message' => 'test-message' |
69
|
|
|
] |
70
|
|
|
], |
71
|
|
|
[ |
72
|
|
|
'height' => $input, |
73
|
|
|
] |
74
|
|
|
)->getParameterArray(); |
75
|
|
|
|
76
|
|
|
$this->assertSame( $expected, $parameters['height'] ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function heightProvider() { |
80
|
|
|
yield [ '10', '10px' ]; |
81
|
|
|
yield [ '10px', '10px' ]; |
82
|
|
|
yield [ '10em', '10em' ]; |
83
|
|
|
yield [ '10ex', '10ex' ]; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
} |
87
|
|
|
|