|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ShlinkioTest\Shlink\Core\Config; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Shlinkio\Shlink\Core\Config\DeprecatedConfigParser; |
|
9
|
|
|
|
|
10
|
|
|
use function array_merge; |
|
11
|
|
|
|
|
12
|
|
|
class DeprecatedConfigParserTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private DeprecatedConfigParser $postProcessor; |
|
15
|
|
|
|
|
16
|
|
|
public function setUp(): void |
|
17
|
|
|
{ |
|
18
|
|
|
$this->postProcessor = new DeprecatedConfigParser(); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** @test */ |
|
22
|
|
|
public function returnsConfigAsIsIfNewValueIsDefined(): void |
|
23
|
|
|
{ |
|
24
|
|
|
$config = [ |
|
25
|
|
|
'not_found_redirects' => [ |
|
26
|
|
|
'invalid_short_url' => 'somewhere', |
|
27
|
|
|
], |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
$result = ($this->postProcessor)($config); |
|
31
|
|
|
|
|
32
|
|
|
$this->assertEquals($config, $result); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** @test */ |
|
36
|
|
|
public function doesNotProvideNewConfigIfOldOneIsDefinedButDisabled(): void |
|
37
|
|
|
{ |
|
38
|
|
|
$config = [ |
|
39
|
|
|
'url_shortener' => [ |
|
40
|
|
|
'not_found_short_url' => [ |
|
41
|
|
|
'enable_redirection' => false, |
|
42
|
|
|
'redirect_to' => 'somewhere', |
|
43
|
|
|
], |
|
44
|
|
|
], |
|
45
|
|
|
]; |
|
46
|
|
|
|
|
47
|
|
|
$result = ($this->postProcessor)($config); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertEquals($config, $result); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** @test */ |
|
53
|
|
|
public function mapsOldConfigToNewOneWhenOldOneIsEnabled(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$config = [ |
|
56
|
|
|
'url_shortener' => [ |
|
57
|
|
|
'not_found_short_url' => [ |
|
58
|
|
|
'enable_redirection' => true, |
|
59
|
|
|
'redirect_to' => 'somewhere', |
|
60
|
|
|
], |
|
61
|
|
|
], |
|
62
|
|
|
]; |
|
63
|
|
|
$expected = array_merge($config, [ |
|
64
|
|
|
'not_found_redirects' => [ |
|
65
|
|
|
'invalid_short_url' => 'somewhere', |
|
66
|
|
|
], |
|
67
|
|
|
]); |
|
68
|
|
|
|
|
69
|
|
|
$result = ($this->postProcessor)($config); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertEquals($expected, $result); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** @test */ |
|
75
|
|
|
public function definesNewConfigAsNullIfOldOneIsEnabledWithNoRedirectValue(): void |
|
76
|
|
|
{ |
|
77
|
|
|
$config = [ |
|
78
|
|
|
'url_shortener' => [ |
|
79
|
|
|
'not_found_short_url' => [ |
|
80
|
|
|
'enable_redirection' => true, |
|
81
|
|
|
], |
|
82
|
|
|
], |
|
83
|
|
|
]; |
|
84
|
|
|
$expected = array_merge($config, [ |
|
85
|
|
|
'not_found_redirects' => [ |
|
86
|
|
|
'invalid_short_url' => null, |
|
87
|
|
|
], |
|
88
|
|
|
]); |
|
89
|
|
|
|
|
90
|
|
|
$result = ($this->postProcessor)($config); |
|
91
|
|
|
|
|
92
|
|
|
$this->assertEquals($expected, $result); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** @test */ |
|
96
|
|
|
public function removesTheOldSecretKey(): void |
|
97
|
|
|
{ |
|
98
|
|
|
$config = [ |
|
99
|
|
|
'app_options' => [ |
|
100
|
|
|
'secret_key' => 'foobar', |
|
101
|
|
|
], |
|
102
|
|
|
]; |
|
103
|
|
|
$expected = [ |
|
104
|
|
|
'app_options' => [], |
|
105
|
|
|
]; |
|
106
|
|
|
|
|
107
|
|
|
$result = ($this->postProcessor)($config); |
|
108
|
|
|
|
|
109
|
|
|
$this->assertEquals($expected, $result); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|