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

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

    public function getRolesReturnsTheEverybodyRoleEvenIfNoTokenIsAuthenticated()
    {
        $mockAuthenticationManager = $this->createMock(AuthenticationManagerInterface::class);
        $mockAuthenticationManager->expects($this->atLeastOnce())->method('isAuthenticated')->will($this->returnValue(false));
        $everybodyRole = new Policy\Role('Neos.Flow:Everybody');
        $anonymousRole = new Policy\Role('Neos.Flow:Anonymous');
        $mockPolicyService = $this->getAccessibleMock(Policy\PolicyService::class, ['getRole']);
        $mockPolicyService->expects($this->any())->method('getRole')->will($this->returnValueMap([['Neos.Flow:Anonymous', $anonymousRole], ['Neos.Flow: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:Everybody']);
        $this->assertEquals('Neos.Flow:Everybody', $result['Neos.Flow:Everybody']->getIdentifier());
    }
ContextTest