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

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

    public function initializeUpdatesAndSeparatesActiveAndInactiveTokensCorrectly()
    {
        $securityContext = $this->getAccessibleMock(Context::class, ['dummy']);
        $settings = [];
        $settings['security']['authentication']['authenticationStrategy'] = 'allTokens';
        $securityContext->injectSettings($settings);
        $matchingRequestPattern = $this->getMockBuilder(RequestPatternInterface::class)->setMockClassName('SomeRequestPattern')->getMock();
        $matchingRequestPattern->expects($this->any())->method('matchRequest')->will($this->returnValue(true));
        $notMatchingRequestPattern = $this->getMockBuilder(RequestPatternInterface::class)->setMockClassName('SomeOtherRequestPattern')->getMock();
        $notMatchingRequestPattern->expects($this->any())->method('matchRequest')->will($this->returnValue(false));
        $token1 = $this->createMock(TokenInterface::class);
        $token1->expects($this->once())->method('hasRequestPatterns')->will($this->returnValue(true));
        $token1->expects($this->once())->method('getRequestPatterns')->will($this->returnValue([$matchingRequestPattern]));
        $token1->expects($this->any())->method('getAuthenticationProviderName')->will($this->returnValue('token1Provider'));
        $token1->expects($this->any())->method('getAuthenticationStatus')->will($this->returnValue(TokenInterface::AUTHENTICATION_NEEDED));
        $token2 = $this->createMock(TokenInterface::class);
        $token2->expects($this->once())->method('hasRequestPatterns')->will($this->returnValue(false));
        $token2->expects($this->never())->method('getRequestPatterns');
        $token2->expects($this->any())->method('getAuthenticationProviderName')->will($this->returnValue('token2Provider'));
        $token2->expects($this->any())->method('getAuthenticationStatus')->will($this->returnValue(TokenInterface::AUTHENTICATION_NEEDED));
        $token3 = $this->createMock(TokenInterface::class);
        $token3->expects($this->once())->method('hasRequestPatterns')->will($this->returnValue(true));
        $token3->expects($this->once())->method('getRequestPatterns')->will($this->returnValue([$notMatchingRequestPattern]));
        $token3->expects($this->any())->method('getAuthenticationProviderName')->will($this->returnValue('token3Provider'));
        $token3->expects($this->any())->method('getAuthenticationStatus')->will($this->returnValue(TokenInterface::AUTHENTICATION_NEEDED));
        $token4 = $this->createMock(TokenInterface::class);
        $token4->expects($this->once())->method('hasRequestPatterns')->will($this->returnValue(true));
        $token4->expects($this->once())->method('getRequestPatterns')->will($this->returnValue([]));
        $token4->expects($this->any())->method('getAuthenticationProviderName')->will($this->returnValue('token4Provider'));
        $token4->expects($this->any())->method('getAuthenticationStatus')->will($this->returnValue(TokenInterface::AUTHENTICATION_NEEDED));
        $token5 = $this->createMock(TokenInterface::class);
        $token5->expects($this->once())->method('hasRequestPatterns')->will($this->returnValue(true));
        $token5->expects($this->once())->method('getRequestPatterns')->will($this->returnValue([$notMatchingRequestPattern, $matchingRequestPattern]));
        $token5->expects($this->any())->method('getAuthenticationProviderName')->will($this->returnValue('token5Provider'));
        $token5->expects($this->any())->method('getAuthenticationStatus')->will($this->returnValue(TokenInterface::AUTHENTICATION_NEEDED));
        $mockAuthenticationManager = $this->createMock(AuthenticationManagerInterface::class);
        $mockAuthenticationManager->expects($this->once())->method('getTokens')->will($this->returnValue([$token1, $token2, $token3, $token4, $token5]));
        $mockSession = $this->createMock(SessionInterface::class);
        $mockSessionManager = $this->createMock(SessionManagerInterface::class);
        $mockSessionManager->expects($this->any())->method('getCurrentSession')->will($this->returnValue($mockSession));
        $mockSecurityLogger = $this->createMock(SecurityLoggerInterface::class);
        $securityContext = $this->getAccessibleMock(Context::class, ['dummy']);
        $securityContext->injectSettings($settings);
        $securityContext->setRequest($this->mockActionRequest);
        $securityContext->injectAuthenticationManager($mockAuthenticationManager);
        $securityContext->_set('sessionManager', $mockSessionManager);
        $securityContext->_set('securityLogger', $mockSecurityLogger);
        $securityContext->_set('tokens', [$token1, $token3, $token4]);
        $securityContext->setRequest($this->mockActionRequest);
        $securityContext->_set('tokens', [$token1, $token3, $token4]);
        $securityContext->initialize();
        $this->assertEquals([$token1, $token2, $token4], array_values($securityContext->_get('activeTokens')));
        $this->assertEquals([$token3, $token5], array_values($securityContext->_get('inactiveTokens')));
    }
ContextTest