|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace League\Tactician\Bundle\Tests\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use League\Tactician\Bundle\DependencyInjection\TacticianExtension; |
|
6
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; |
|
8
|
|
|
|
|
9
|
|
|
class TacticianExtensionTest extends AbstractExtensionTestCase |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Return an array of container extensions you need to be registered for each test (usually just the container |
|
13
|
|
|
* extension you are testing. |
|
14
|
|
|
* |
|
15
|
|
|
* @return ExtensionInterface[] |
|
16
|
|
|
*/ |
|
17
|
|
|
protected function getContainerExtensions() |
|
18
|
|
|
{ |
|
19
|
|
|
return [ |
|
20
|
|
|
new TacticianExtension() |
|
21
|
|
|
]; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testLoadSecurityConfiguration() |
|
25
|
|
|
{ |
|
26
|
|
|
$securitySettings = ['Some\Command' => ['ROLE_USER'], 'Some\Other\Command' => ['ROLE_ADMIN']]; |
|
27
|
|
|
|
|
28
|
|
|
$this->load([ |
|
29
|
|
|
'commandbus' => [ |
|
30
|
|
|
'default' => [ |
|
31
|
|
|
'middleware' => [ |
|
32
|
|
|
'tactician.middleware.security', |
|
33
|
|
|
'tactician.middleware.command_handler', |
|
34
|
|
|
] |
|
35
|
|
|
] |
|
36
|
|
|
], |
|
37
|
|
|
'security' => $securitySettings |
|
38
|
|
|
]); |
|
39
|
|
|
|
|
40
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument('tactician.middleware.security_voter', 1, $securitySettings); |
|
41
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithTag('tactician.middleware.security_voter', 'security.voter'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testDefaultSecurityConfigurationIsAllowNothing() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->load([ |
|
47
|
|
|
'commandbus' => [ |
|
48
|
|
|
'default' => [ |
|
49
|
|
|
'middleware' => [ |
|
50
|
|
|
'tactician.middleware.security', |
|
51
|
|
|
'tactician.middleware.command_handler', |
|
52
|
|
|
] |
|
53
|
|
|
] |
|
54
|
|
|
] |
|
55
|
|
|
]); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument('tactician.middleware.security_voter', 1, []); |
|
58
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithTag('tactician.middleware.security_voter', 'security.voter'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testVoterIsNotLoadedWithoutSecurityMiddleware() |
|
62
|
|
|
{ |
|
63
|
|
|
$this->load(); |
|
64
|
|
|
|
|
65
|
|
|
$this->assertContainerBuilderNotHasService('tactician.middleware.security_voter'); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|