|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Compiler; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\AddSecurityVotersPass; |
| 16 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 17 | +use Symfony\Component\DependencyInjection\Reference; |
| 18 | + |
| 19 | +class AddSecurityVotersPassTest extends TestCase |
| 20 | +{ |
| 21 | + public function testThatSecurityVotersAreProcessedInPriorityOrder() |
| 22 | + { |
| 23 | + $container = new ContainerBuilder(); |
| 24 | + $container |
| 25 | + ->register('security.access.decision_manager', 'Symfony\Component\Security\Core\Authorization\AccessDecisionManager') |
| 26 | + ->addArgument(array()) |
| 27 | + ; |
| 28 | + $container |
| 29 | + ->register('no_prio_service') |
| 30 | + ->addTag('security.voter') |
| 31 | + ; |
| 32 | + $container |
| 33 | + ->register('lowest_prio_service') |
| 34 | + ->addTag('security.voter', array('priority' => 100)) |
| 35 | + ; |
| 36 | + $container |
| 37 | + ->register('highest_prio_service') |
| 38 | + ->addTag('security.voter', array('priority' => 200)) |
| 39 | + ; |
| 40 | + $container |
| 41 | + ->register('zero_prio_service') |
| 42 | + ->addTag('security.voter', array('priority' => 0)) |
| 43 | + ; |
| 44 | + $compilerPass = new AddSecurityVotersPass(); |
| 45 | + $compilerPass->process($container); |
| 46 | + |
| 47 | + $this->assertEquals( |
| 48 | + array( |
| 49 | + new Reference('highest_prio_service'), |
| 50 | + new Reference('lowest_prio_service'), <
63B5
/td> |
| 51 | + new Reference('no_prio_service'), |
| 52 | + new Reference('zero_prio_service'), |
| 53 | + ), |
| 54 | + $container->getDefinition('security.access.decision_manager')->getArgument(0) |
| 55 | + ); |
| 56 | + } |
| 57 | +} |
0 commit comments