|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\Assert; |
15 | 15 | use PHPUnit\Framework\TestCase; |
16 | | -use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; |
17 | 16 | use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
18 | 17 | use Symfony\Component\Security\Core\Authorization\AccessDecisionManager; |
19 | 18 | use Symfony\Component\Security\Core\Authorization\Strategy\AccessDecisionStrategyInterface; |
|
22 | 21 |
|
23 | 22 | class AccessDecisionManagerTest extends TestCase |
24 | 23 | { |
25 | | - use ExpectDeprecationTrait; |
26 | | - |
27 | | - /** |
28 | | - * @group legacy |
29 | | - */ |
30 | | - public function testSetUnsupportedStrategy() |
31 | | - { |
32 | | - $this->expectException(\InvalidArgumentException::class); |
33 | | - new AccessDecisionManager([$this->getVoter(VoterInterface::ACCESS_GRANTED)], 'fooBar'); |
34 | | - } |
35 | | - |
36 | | - /** |
37 | | - * @group legacy |
38 | | - * |
39 | | - * @dataProvider getStrategyTests |
40 | | - */ |
41 | | - public function testStrategies($strategy, $voters, $allowIfAllAbstainDecisions, $allowIfEqualGrantedDeniedDecisions, $expected) |
42 | | - { |
43 | | - $token = $this->createMock(TokenInterface::class); |
44 | | - |
45 | | - $this->expectDeprecation('Since symfony/security-core 5.4: Passing the access decision strategy as a string is deprecated, pass an instance of "Symfony\Component\Security\Core\Authorization\Strategy\AccessDecisionStrategyInterface" instead.'); |
46 | | - $manager = new AccessDecisionManager($voters, $strategy, $allowIfAllAbstainDecisions, $allowIfEqualGrantedDeniedDecisions); |
47 | | - |
48 | | - $this->assertSame($expected, $manager->decide($token, ['ROLE_FOO'])); |
49 | | - } |
50 | | - |
51 | 24 | public function provideBadVoterResults(): array |
52 | 25 | { |
53 | 26 | return [ |
@@ -92,66 +65,6 @@ public function decide(\Traversable $results): bool |
92 | 65 | $this->assertTrue($manager->decide($token, ['ROLE_FOO'])); |
93 | 66 | } |
94 | 67 |
|
95 | | - public function getStrategyTests() |
96 | | - { |
97 | | - return [ |
98 | | - // affirmative |
99 | | - [AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(1, 0, 0), false, true, true], |
100 | | - [AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(1, 2, 0), false, true, true], |
101 | | - [AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(0, 1, 0), false, true, false], |
102 | | - [AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(0, 0, 1), false, true, false], |
103 | | - [AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(0, 0, 1), true, true, true], |
104 | | - |
105 | | - // consensus |
106 | | - [AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(1, 0, 0), false, true, true], |
107 | | - [AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(1, 2, 0), false, true, false], |
108 | | - [AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 1, 0), false, true, true], |
109 | | - |
110 | | - [AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(0, 0, 1), false, true, false], |
111 | | - |
112 | | - [AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(0, 0, 1), true, true, true], |
113 | | - |
114 | | - [AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 2, 0), false, true, true], |
115 | | - [AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 2, 1), false, true, true], |
116 | | - |
117 | | - [AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 2, 0), false, false, false], |
118 | | - [AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 2, 1), false, false, false], |
119 | | - |
120 | | - // unanimous |
121 | | - [AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(1, 0, 0), false, true, true], |
122 | | - [AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(1, 0, 1), false, true, true], |
123 | | - [AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(1, 1, 0), false, true, false], |
124 | | - |
125 | | - [AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(0, 0, 2), false, true, false], |
126 | | - [AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(0, 0, 2), true, true, true], |
127 | | - |
128 | | - // priority |
129 | | - [AccessDecisionManager::STRATEGY_PRIORITY, [ |
130 | | - $this->getVoter(VoterInterface::ACCESS_ABSTAIN), |
131 | | - $this->getVoter(VoterInterface::ACCESS_GRANTED), |
132 | | - $this->getVoter(VoterInterface::ACCESS_DENIED), |
133 | | - $this->getVoter(VoterInterface::ACCESS_DENIED), |
134 | | - ], true, true, true], |
135 | | - |
136 | | - [AccessDecisionManager::STRATEGY_PRIORITY, [ |
137 | | - $this->getVoter(VoterInterface::ACCESS_ABSTAIN), |
138 | | - $this->getVoter(VoterInterface::ACCESS_DENIED), |
139 | | - $this->getVoter(VoterInterface::ACCESS_GRANTED), |
140 | | - $this->getVoter(VoterInterface::ACCESS_GRANTED), |
141 | | - ], true, true, false], |
142 | | - |
143 | | - [AccessDecisionManager::STRATEGY_PRIORITY, [ |
144 | | - $this->getVoter(VoterInterface::ACCESS_ABSTAIN), |
145 | | - $this->getVoter(VoterInterface::ACCESS_ABSTAIN), |
146 | | - ], false, true, false], |
147 | | - |
148 | | - [AccessDecisionManager::STRATEGY_PRIORITY, [ |
149 | | - $this->getVoter(VoterInterface::ACCESS_ABSTAIN), |
150 | | - $this->getVoter(VoterInterface::ACCESS_ABSTAIN), |
151 | | - ], true, true, true], |
152 | | - ]; |
153 | | - } |
154 | | - |
155 | 68 | public function testCacheableVoters() |
156 | 69 | { |
157 | 70 | $token = $this->createMock(TokenInterface::class); |
|
0 commit comments