|
1 <?php |
|
2 |
|
3 namespace JMS\SecurityExtraBundle\Tests\DependencyInjection\Compiler; |
|
4 |
|
5 use Symfony\Component\DependencyInjection\Definition; |
|
6 use JMS\SecurityExtraBundle\DependencyInjection\Compiler\AddAfterInvocationProvidersPass; |
|
7 use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
8 |
|
9 class AddAfterInvocationProvidersPassTest extends \PHPUnit_Framework_TestCase |
|
10 { |
|
11 public function testProcessStopsWhenNoAfterInvocationManager() |
|
12 { |
|
13 $container = $this->getContainer(); |
|
14 $container |
|
15 ->expects($this->once()) |
|
16 ->method('hasDefinition') |
|
17 ->with($this->equalTo('security.access.after_invocation_manager')) |
|
18 ->will($this->returnValue(false)) |
|
19 ; |
|
20 $container |
|
21 ->expects($this->never()) |
|
22 ->method('findTaggedServiceIds') |
|
23 ; |
|
24 |
|
25 $this->process($container); |
|
26 } |
|
27 |
|
28 public function testProcessRemovesAclProviderIfAclIsNotActive() |
|
29 { |
|
30 $container = new ContainerBuilder(); |
|
31 $container->setDefinition('security.access.after_invocation_manager', $manager = new Definition()); |
|
32 |
|
33 $container |
|
34 ->register('security.access.after_invocation.acl_provider') |
|
35 ->addTag('security.after_invocation.provider') |
|
36 ; |
|
37 |
|
38 $this->assertEquals(array(), $manager->getArguments()); |
|
39 $this->process($container); |
|
40 $this->assertEquals(array(array()), $manager->getArguments()); |
|
41 } |
|
42 |
|
43 public function testProcess() |
|
44 { |
|
45 $container = new ContainerBuilder(); |
|
46 |
|
47 $container->setDefinition('security.access.after_invocation_manager', $manager = new Definition()); |
|
48 |
|
49 $provider1 = new Definition(); |
|
50 $provider1->addTag('security.after_invocation.provider'); |
|
51 $container->setDefinition('provider1', $provider1); |
|
52 |
|
53 $provider2 = new Definition(); |
|
54 $provider2->addTag('security.after_invocation.provider'); |
|
55 $container->setDefinition('provider2', $provider2); |
|
56 |
|
57 $this->process($container); |
|
58 |
|
59 $arguments = $manager->getArguments(); |
|
60 $this->assertEquals(2, count($providers = $arguments[0])); |
|
61 $this->assertEquals('provider1', (string) $providers[0]); |
|
62 $this->assertEquals('provider2', (string) $providers[1]); |
|
63 } |
|
64 |
|
65 protected function process(ContainerBuilder $container) |
|
66 { |
|
67 $pass = new AddAfterInvocationProvidersPass(); |
|
68 $pass->process($container); |
|
69 } |
|
70 |
|
71 protected function getContainer() |
|
72 { |
|
73 return $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); |
|
74 } |
|
75 } |