14
14
use Symfony \Component \Security \Acl \Domain \RoleSecurityIdentity ;
15
15
use Symfony \Component \Security \Acl \Domain \UserSecurityIdentity ;
16
16
use Symfony \Component \Security \Acl \Domain \SecurityIdentityRetrievalStrategy ;
17
+ use Symfony \Component \Security \Core \Role \Role ;
17
18
18
19
class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
19
20
{
@@ -22,8 +23,6 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
22
23
*/
23
24
public function testGetSecurityIdentities ($ user , array $ roles , $ authenticationStatus , array $ sids )
24
25
{
25
- $ strategy = $ this ->getStrategy ($ roles , $ authenticationStatus );
26
-
27
26
if ('anonymous ' === $ authenticationStatus ) {
28
27
$ token = $ this ->getMockBuilder ('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken ' )
29
28
->disableOriginalConstructor ()
@@ -40,16 +39,20 @@ public function testGetSecurityIdentities($user, array $roles, $authenticationSt
40
39
}
41
40
42
41
if (method_exists ($ token , 'getRoleNames ' )) {
42
+ $ strategy = $ this ->getStrategy ($ roles , $ authenticationStatus , false );
43
+
43
44
$ token
44
45
->expects ($ this ->once ())
45
46
->method ('getRoleNames ' )
46
47
->will ($ this ->returnValue (array ('foo ' )))
47
48
;
48
49
} else {
50
+ $ strategy = $ this ->getStrategy ($ roles , $ authenticationStatus , true );
51
+
49
52
$ token
50
53
->expects ($ this ->once ())
51
54
->method ('getRoles ' )
52
- ->will ($ this ->returnValue (array ('foo ' )))
55
+ ->will ($ this ->returnValue (array (new Role ( 'foo ' ) )))
53
56
;
54
57
}
55
58
@@ -129,15 +132,32 @@ protected function getAccount($username, $class)
129
132
return $ account ;
130
133
}
131
134
132
- protected function getStrategy (array $ roles = array (), $ authenticationStatus = 'fullFledged ' )
135
+ protected function getStrategy (array $ roles = array (), $ authenticationStatus = 'fullFledged ' , $ isBC = false )
133
136
{
134
- $ roleHierarchy = $ this ->getMock ('Symfony\Component\Security\Core\Role\RoleHierarchyInterface ' );
135
- $ roleHierarchy
136
- ->expects ($ this ->once ())
137
- ->method ('getReachableRoles ' )
138
- ->with ($ this ->equalTo (array ('foo ' )))
139
- ->will ($ this ->returnValue ($ roles ))
140
- ;
137
+ $ roleHierarchyBuilder = $ this ->getMockBuilder ('Symfony\Component\Security\Core\Role\RoleHierarchyInterface ' )
138
+ ->disableProxyingToOriginalMethods ()
139
+ ->disableOriginalConstructor ();
140
+
141
+ if ($ isBC ) {
142
+ $ roleHierarchy = $ roleHierarchyBuilder ->setMethods (['getReachableRoles ' ])
143
+ ->getMockForAbstractClass ();
144
+
145
+ $ roleHierarchy
146
+ ->expects ($ this ->any ())
147
+ ->method ('getReachableRoles ' )
148
+ ->with ($ this ->equalTo ([new Role ('foo ' )]))
149
+ ->will ($ this ->returnValue ($ roles ));
150
+ } else {
151
+ $ roleHierarchy = $ roleHierarchyBuilder ->setMethods (['getReachableRoleNames ' ])
152
+ ->getMockForAbstractClass ();
153
+
154
+ $ roleHierarchy
155
+ ->expects ($ this ->any ())
156
+ ->method ('getReachableRoleNames ' )
157
+ ->with ($ this ->equalTo (['foo ' ]))
158
+ ->will ($ this ->returnValue ($ roles ));
159
+ }
160
+
141
161
142
162
$ trustResolver = $ this ->getMock ('Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface ' , array (), array ('' , '' ));
143
163
0 commit comments