1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Maps\Tests\Unit\Presentation; |
4
|
|
|
|
5
|
|
|
use Maps\Presentation\ParameterExtractor; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers \Maps\Presentation\ParameterExtractor |
10
|
|
|
* |
11
|
|
|
* @licence GNU GPL v2+ |
12
|
|
|
* @author Jeroen De Dauw < [email protected] > |
13
|
|
|
*/ |
14
|
|
|
class ParameterExtractorTest extends TestCase { |
15
|
|
|
|
16
|
|
|
public function testGivenNoParameters_nullIsReturned() { |
17
|
|
|
$this->assertNull( ( new ParameterExtractor() )->extract( [ 'name' ], [] ) ); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testGivenWhenPrimaryNameIsPresent_itsValueIsReturned() { |
21
|
|
|
$this->assertSame( |
22
|
|
|
'value', |
23
|
|
|
( new ParameterExtractor() )->extract( |
24
|
|
|
[ 'name' ], |
25
|
|
|
[ 'foo' => 'bar', 'name' => 'value', 'baz' => 'bah' ] |
26
|
|
|
) |
27
|
|
|
); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testGivenAliasIsPresent_itsValueIsReturned() { |
31
|
|
|
$this->assertSame( |
32
|
|
|
'value', |
33
|
|
|
( new ParameterExtractor() )->extract( |
34
|
|
|
[ 'name', 'secondary', 'alias' ], |
35
|
|
|
[ 'foo' => 'bar', 'alias' => 'value', 'baz' => 'bah' ] |
36
|
|
|
) |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testWhenAliasAndPrimaryArePresent_thePrimariesValueIsReturned() { |
41
|
|
|
$this->assertSame( |
42
|
|
|
'value', |
43
|
|
|
( new ParameterExtractor() )->extract( |
44
|
|
|
[ 'name', 'secondary', 'alias' ], |
45
|
|
|
[ 'foo' => 'bar', 'alias' => 'wrong', 'name' => 'value' ] |
46
|
|
|
) |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testValueIsTrimmed() { |
51
|
|
|
$this->assertSame( |
52
|
|
|
'value', |
53
|
|
|
( new ParameterExtractor() )->extract( |
54
|
|
|
[ 'name' ], |
55
|
|
|
[ 'name' => " value\t " ] |
56
|
|
|
) |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testWhenUpperCaseIsUsedInTheName_itIsStillFound() { |
61
|
|
|
$this->assertSame( |
62
|
|
|
'value', |
63
|
|
|
( new ParameterExtractor() )->extract( |
64
|
|
|
[ 'name' ], |
65
|
|
|
[ 'nAmE' => 'value' ] |
66
|
|
|
) |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testNameHasSpacesAroundIt_itIsStillFound() { |
71
|
|
|
$this->assertSame( |
72
|
|
|
'value', |
73
|
|
|
( new ParameterExtractor() )->extract( |
74
|
|
|
[ 'name' ], |
75
|
|
|
[ ' name ' => 'value' ] |
76
|
|
|
) |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|