1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Palmtree\CanonicalUrlBundle\Tests\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Palmtree\CanonicalUrlBundle\DependencyInjection\Configuration; |
6
|
|
|
use Palmtree\CanonicalUrlBundle\Tests\AbstractTest; |
7
|
|
|
use Symfony\Component\Config\Definition\Processor; |
8
|
|
|
|
9
|
|
|
class ConfigurationTest extends AbstractTest |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Some basic tests to make sure the configuration is correctly processed in |
13
|
|
|
* the standard case. |
14
|
|
|
*/ |
15
|
|
|
public function testProcessSimpleCase() |
16
|
|
|
{ |
17
|
|
|
$configs = [ |
18
|
|
|
[ |
19
|
|
|
'site_url' => 'https://example.org', |
20
|
|
|
'redirect' => true, |
21
|
|
|
'redirect_code' => 302, |
22
|
|
|
'trailing_slash' => true, |
23
|
|
|
], |
24
|
|
|
[ |
25
|
|
|
'trailing_slash' => false, |
26
|
|
|
], |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
$config = $this->process($configs); |
30
|
|
|
|
31
|
|
|
$this->assertArrayHasKey('site_url', $config); |
32
|
|
|
$this->assertTrue($config['redirect']); |
33
|
|
|
$this->assertFalse($config['trailing_slash']); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testInvalidSiteUrl() |
37
|
|
|
{ |
38
|
|
|
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class); |
39
|
|
|
|
40
|
|
|
$configs = [ |
41
|
|
|
[ |
42
|
|
|
'site_url' => false, |
43
|
|
|
], |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
$this->process($configs); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testInvalidRedirectCode() |
50
|
|
|
{ |
51
|
|
|
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class); |
52
|
|
|
|
53
|
|
|
$configs = [ |
54
|
|
|
[ |
55
|
|
|
'redirect_code' => 404, |
56
|
|
|
], |
57
|
|
|
]; |
58
|
|
|
|
59
|
|
|
$this->process($configs); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testInvalidRedirect() |
63
|
|
|
{ |
64
|
|
|
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class); |
65
|
|
|
$configs = [ |
66
|
|
|
[ |
67
|
|
|
'redirect' => 9, |
68
|
|
|
], |
69
|
|
|
]; |
70
|
|
|
|
71
|
|
|
$this->process($configs); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Processes an array of configurations and returns a compiled version. |
76
|
|
|
* |
77
|
|
|
* @param array $configs An array of raw configurations |
78
|
|
|
* |
79
|
|
|
* @return array A normalized array |
80
|
|
|
*/ |
81
|
|
|
protected function process($configs) |
82
|
|
|
{ |
83
|
|
|
$processor = new Processor(); |
84
|
|
|
|
85
|
|
|
return $processor->processConfiguration(new Configuration(), $configs); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|