Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #21679 [SecurityBundle] fix priority ordering of security voters …
…(xabbuh) This PR was merged into the 2.7 branch. Discussion ---------- [SecurityBundle] fix priority ordering of security voters | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21660 | License | MIT | Doc PR | Could be updated in the `3.2` branch to make use of the `PriorityTaggedServiceTrait `. Commits ------- dcd19f3 fix priority ordering of security voters
- Loading branch information
Showing
2 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...ny/Bundle/SecurityBundle/Tests/DependencyInjection/Compiler/AddSecurityVotersPassTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\AddSecurityVotersPass; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
class AddSecurityVotersPassTest extends TestCase | ||
{ | ||
public function testThatSecurityVotersAreProcessedInPriorityOrder() | ||
{ | ||
$container = new ContainerBuilder(); | ||
$container | ||
->register('security.access.decision_manager', 'Symfony\Component\Security\Core\Authorization\AccessDecisionManager') | ||
->addArgument(array()) | ||
; | ||
$container | ||
->register('no_prio_service') | ||
->addTag('security.voter') | ||
; | ||
$container | ||
->register('lowest_prio_service') | ||
->addTag('security.voter', array('priority' => 100)) | ||
; | ||
$container | ||
->register('highest_prio_service') | ||
->addTag('security.voter', array('priority' => 200)) | ||
; | ||
$container | ||
->register('zero_prio_service') | ||
->addTag('security.voter', array('priority' => 0)) | ||
; | ||
$compilerPass = new AddSecurityVotersPass(); | ||
$compilerPass->process($container); | ||
|
||
$this->assertEquals( | ||
array( | ||
new Reference('highest_prio_service'), | ||
new Reference('lowest_prio_service'), | ||
new Reference('no_prio_service'), | ||
new Reference('zero_prio_service'), | ||
), | ||
$container->getDefinition('security.access.decision_manager')->getArgument(0) | ||
); | ||
} | ||
} |