|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Zenstruck\RedirectBundle\Tests\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
|
6
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
|
7
|
|
|
use Zenstruck\RedirectBundle\DependencyInjection\ZenstruckRedirectExtension; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @author Kevin Bond <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class ZenstruckRedirectExtensionTest extends AbstractExtensionTestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @test |
|
16
|
|
|
*/ |
|
17
|
|
|
public function no_classes_set() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->expectException(InvalidConfigurationException::class); |
|
20
|
|
|
$this->expectExceptionMessage('A "redirect_class" or "not_found_class" must be set for "zenstruck_redirect".'); |
|
21
|
|
|
|
|
22
|
|
|
$this->load([]); |
|
23
|
|
|
$this->compile(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @test |
|
28
|
|
|
*/ |
|
29
|
|
|
public function redirect_class() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->load(['redirect_class' => 'Zenstruck\RedirectBundle\Tests\Fixture\Bundle\Entity\DummyRedirect']); |
|
32
|
|
|
$this->compile(); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertContainerBuilderHasService('zenstruck_redirect.redirect_manager'); |
|
35
|
|
|
$this->assertContainerBuilderHasAlias('zenstruck_redirect.entity_manager', 'doctrine.orm.default_entity_manager'); |
|
36
|
|
|
$this->assertContainerBuilderHasService('zenstruck_redirect.redirect_listener'); |
|
37
|
|
|
$this->assertContainerBuilderHasService('zenstruck_redirect.redirect.form.type'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @test |
|
42
|
|
|
*/ |
|
43
|
|
|
public function custom_model_manager_name() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->load([ |
|
46
|
|
|
'redirect_class' => 'Zenstruck\RedirectBundle\Tests\Fixture\Bundle\Entity\DummyRedirect', |
|
47
|
|
|
'model_manager_name' => 'foo', |
|
48
|
|
|
]); |
|
49
|
|
|
$this->compile(); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertContainerBuilderHasAlias('zenstruck_redirect.entity_manager', 'doctrine.orm.foo_entity_manager'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @test |
|
56
|
|
|
*/ |
|
57
|
|
|
public function not_found_class() |
|
58
|
|
|
{ |
|
59
|
|
|
$this->load(['not_found_class' => 'Zenstruck\RedirectBundle\Tests\Fixture\Bundle\Entity\DummyNotFound']); |
|
60
|
|
|
$this->compile(); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertContainerBuilderHasService('zenstruck_redirect.not_found_manager'); |
|
63
|
|
|
$this->assertContainerBuilderHasAlias('zenstruck_redirect.entity_manager', 'doctrine.orm.default_entity_manager'); |
|
64
|
|
|
$this->assertContainerBuilderHasService('zenstruck_redirect.not_found_listener'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @test |
|
69
|
|
|
*/ |
|
70
|
|
|
public function remove_not_found_subscriber() |
|
71
|
|
|
{ |
|
72
|
|
|
$this->load([ |
|
73
|
|
|
'not_found_class' => 'Zenstruck\RedirectBundle\Tests\Fixture\Bundle\Entity\DummyNotFound', |
|
74
|
|
|
'redirect_class' => 'Zenstruck\RedirectBundle\Tests\Fixture\Bundle\Entity\DummyRedirect', |
|
75
|
|
|
]); |
|
76
|
|
|
$this->compile(); |
|
77
|
|
|
|
|
78
|
|
|
$this->assertContainerBuilderHasService('zenstruck_redirect.remove_not_found_subscriber'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @test |
|
83
|
|
|
*/ |
|
84
|
|
|
public function disable_remove_not_found_subscriber() |
|
85
|
|
|
{ |
|
86
|
|
|
$this->load([ |
|
87
|
|
|
'not_found_class' => 'Zenstruck\RedirectBundle\Tests\Fixture\Bundle\Entity\DummyNotFound', |
|
88
|
|
|
'redirect_class' => 'Zenstruck\RedirectBundle\Tests\Fixture\Bundle\Entity\DummyRedirect', |
|
89
|
|
|
'remove_not_founds' => false, |
|
90
|
|
|
]); |
|
91
|
|
|
$this->compile(); |
|
92
|
|
|
|
|
93
|
|
|
$this->assertContainerBuilderNotHasService('zenstruck_redirect.remove_not_found_subscriber'); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @dataProvider invalidClassProvider |
|
98
|
|
|
* |
|
99
|
|
|
* @test |
|
100
|
|
|
*/ |
|
101
|
|
|
public function invalid_redirect_class($class) |
|
102
|
|
|
{ |
|
103
|
|
|
$this->expectException(InvalidConfigurationException::class); |
|
104
|
|
|
|
|
105
|
|
|
$this->load(['redirect_class' => $class]); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @dataProvider invalidClassProvider |
|
110
|
|
|
* |
|
111
|
|
|
* @test |
|
112
|
|
|
*/ |
|
113
|
|
|
public function invalid_not_found_class($class) |
|
114
|
|
|
{ |
|
115
|
|
|
$this->expectException(InvalidConfigurationException::class); |
|
116
|
|
|
|
|
117
|
|
|
$this->load(['not_found_class' => $class]); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function invalidClassProvider() |
|
121
|
|
|
{ |
|
122
|
|
|
return [ |
|
123
|
|
|
['Foo\Bar'], |
|
124
|
|
|
[static::class], |
|
125
|
|
|
]; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
protected function getContainerExtensions(): array |
|
129
|
|
|
{ |
|
130
|
|
|
return [new ZenstruckRedirectExtension()]; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|