@@ -65,6 +65,48 @@ public function testStrategies($strategy, $voters, $allowIfAllAbstainDecisions,
65
65
$ this ->assertSame ($ expected , $ manager ->decide ($ token , array ('ROLE_FOO ' )));
66
66
}
67
67
68
+ /**
69
+ * @dataProvider getStrategiesWith2RolesTests
70
+ */
71
+ public function testStrategiesWith2Roles ($ token , $ strategy , $ voter , $ expected )
72
+ {
73
+ $ manager = new AccessDecisionManager (array ($ voter ), $ strategy );
74
+
75
+ $ this ->assertSame ($ expected , $ manager ->decide ($ token , array ('ROLE_FOO ' , 'ROLE_BAR ' )));
76
+ }
77
+
78
+ public function getStrategiesWith2RolesTests ()
79
+ {
80
+ $ token = $ this ->getMock ('Symfony\Component\Security\Core\Authentication\Token\TokenInterface ' );
81
+
82
+ return array (
83
+ array ($ token , 'affirmative ' , $ this ->getVoter (VoterInterface::ACCESS_DENIED ), false ),
84
+ array ($ token , 'affirmative ' , $ this ->getVoter (VoterInterface::ACCESS_GRANTED ), true ),
85
+
86
+ array ($ token , 'consensus ' , $ this ->getVoter (VoterInterface::ACCESS_DENIED ), false ),
87
+ array ($ token , 'consensus ' , $ this ->getVoter (VoterInterface::ACCESS_GRANTED ), true ),
88
+
89
+ array ($ token , 'unanimous ' , $ this ->getVoterFor2Roles ($ token , VoterInterface::ACCESS_DENIED , VoterInterface::ACCESS_DENIED ), false ),
90
+ array ($ token , 'unanimous ' , $ this ->getVoterFor2Roles ($ token , VoterInterface::ACCESS_DENIED , VoterInterface::ACCESS_GRANTED ), false ),
91
+ array ($ token , 'unanimous ' , $ this ->getVoterFor2Roles ($ token , VoterInterface::ACCESS_GRANTED , VoterInterface::ACCESS_DENIED ), false ),
92
+ array ($ token , 'unanimous ' , $ this ->getVoterFor2Roles ($ token , VoterInterface::ACCESS_GRANTED , VoterInterface::ACCESS_GRANTED ), true ),
93
+ );
94
+ }
95
+
96
+ protected function getVoterFor2Roles ($ token , $ vote1 , $ vote2 )
97
+ {
98
+ $ voter = $ this ->getMock ('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface ' );
99
+ $ voter ->expects ($ this ->exactly (2 ))
100
+ ->method ('vote ' )
101
+ ->will ($ this ->returnValueMap (array (
102
+ array ($ token , null , array ("ROLE_FOO " ),$ vote1 ),
103
+ array ($ token , null , array ("ROLE_BAR " ),$ vote2 ),
104
+ )))
105
+ ;
106
+
107
+ return $ voter ;
108
+ }
109
+
68
110
public function getStrategyTests ()
69
111
{
70
112
return array (
0 commit comments