Neos\Flow\Tests\Unit\Security\ContextTest::getRolesReturnsTheAuthenticatedUserRoleIfATokenIsAuthenticated PHP Метод

getRolesReturnsTheAuthenticatedUserRoleIfATokenIsAuthenticated() публичный Метод

    public function getRolesReturnsTheAuthenticatedUserRoleIfATokenIsAuthenticated()
    {
        $mockAuthenticationManager = $this->createMock(AuthenticationManagerInterface::class);
        $mockAuthenticationManager->expects($this->atLeastOnce())->method('isAuthenticated')->will($this->returnValue(true));
        $everybodyRole = new Policy\Role('Neos.Flow:Everybody');
        $authenticatedUserRole = new Policy\Role('Neos.Flow:AuthenticatedUser');
        $mockPolicyService = $this->getAccessibleMock(Policy\PolicyService::class, ['getRole']);
        $mockPolicyService->expects($this->any())->method('getRole')->will($this->returnValueMap([['Neos.Flow:AuthenticatedUser', $authenticatedUserRole], ['Everybody', $everybodyRole]]));
        $securityContext = $this->getAccessibleMock(Context::class, ['initialize']);
        $securityContext->_set('policyService', $mockPolicyService);
        $securityContext->_set('authenticationManager', $mockAuthenticationManager);
        $result = $securityContext->getRoles();
        $this->assertInstanceOf(Policy\Role::class, $result['Neos.Flow:AuthenticatedUser']);
        $this->assertEquals('Neos.Flow:AuthenticatedUser', (string) $result['Neos.Flow:AuthenticatedUser']);
    }
ContextTest