public function getRolesReturnsTheCorrectRoles()
{
$everybodyRole = new Policy\Role('Neos.Flow:Everybody');
$authenticatedUserRole = new Policy\Role('Neos.Flow:AuthenticatedUser');
$testRole = new Policy\Role('Acme.Demo:TestRole');
$mockAuthenticationManager = $this->createMock(AuthenticationManagerInterface::class);
$mockAuthenticationManager->expects($this->atLeastOnce())->method('isAuthenticated')->will($this->returnValue(true));
$mockPolicyService = $this->getAccessibleMock(Policy\PolicyService::class, ['getRole', 'initializeRolesFromPolicy']);
$mockPolicyService->expects($this->atLeastOnce())->method('getRole')->will($this->returnCallback(function ($roleIdentifier) use($everybodyRole, $authenticatedUserRole) {
switch ($roleIdentifier) {
case 'Neos.Flow:Everybody':
return $everybodyRole;
case 'Neos.Flow:AuthenticatedUser':
return $authenticatedUserRole;
}
}));
$account = $this->getAccessibleMock(Account::class, ['dummy']);
$account->_set('policyService', $mockPolicyService);
$account->setRoles([$testRole]);
$mockToken = $this->createMock(TokenInterface::class);
$mockToken->expects($this->atLeastOnce())->method('isAuthenticated')->will($this->returnValue(true));
$mockToken->expects($this->atLeastOnce())->method('getAccount')->will($this->returnValue($account));
$securityContext = $this->getAccessibleMock(Context::class, ['initialize', 'getAccount']);
$securityContext->expects($this->any())->method('getAccount')->will($this->returnValue($account));
$securityContext->_set('activeTokens', [$mockToken]);
$securityContext->_set('policyService', $mockPolicyService);
$securityContext->_set('authenticationManager', $mockAuthenticationManager);
$expectedResult = ['Neos.Flow:Everybody' => $everybodyRole, 'Neos.Flow:AuthenticatedUser' => $authenticatedUserRole, 'Acme.Demo:TestRole' => $testRole];
$this->assertEquals($expectedResult, $securityContext->getRoles());
}