AddSecurityVotersPassTest.php 1.9 KB

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