/** * @return void */ public function setUp() { $this->viewHelperVariableContainer = $this->createMock(\TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer::class); $this->viewHelperVariableContainer->expects($this->any())->method('exists')->will($this->returnCallback(array($this, 'viewHelperVariableContainerExistsCallback'))); $this->viewHelperVariableContainer->expects($this->any())->method('get')->will($this->returnCallback(array($this, 'viewHelperVariableContainerGetCallback'))); $this->templateVariableContainer = $this->createMock(TemplateVariableContainer::class); $this->uriBuilder = $this->createMock(\Neos\Flow\Mvc\Routing\UriBuilder::class); $this->uriBuilder->expects($this->any())->method('reset')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setArguments')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setSection')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setFormat')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setCreateAbsoluteUri')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setAddQueryString')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setArgumentsToBeExcludedFromQueryString')->will($this->returnValue($this->uriBuilder)); // BACKPORTER TOKEN #1 $httpRequest = \Neos\Flow\Http\Request::create(new \Neos\Flow\Http\Uri('http://localhost/foo')); $this->request = $this->getMockBuilder(\Neos\Flow\Mvc\ActionRequest::class)->setConstructorArgs(array($httpRequest))->getMock(); $this->request->expects($this->any())->method('isMainRequest')->will($this->returnValue(true)); $this->controllerContext = $this->getMockBuilder(\Neos\Flow\Mvc\Controller\ControllerContext::class)->disableOriginalConstructor()->getMock(); $this->controllerContext->expects($this->any())->method('getUriBuilder')->will($this->returnValue($this->uriBuilder)); $this->controllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->request)); $this->tagBuilder = $this->createMock(TagBuilder::class); $this->arguments = array(); $this->renderingContext = new \Neos\FluidAdaptor\Core\Rendering\RenderingContext(new StandaloneView(), []); $this->renderingContext->setVariableProvider($this->templateVariableContainer); $this->renderingContext->setViewHelperVariableContainer($this->viewHelperVariableContainer); $this->renderingContext->setControllerContext($this->controllerContext); }
/** * @test */ public function updateCredentialsIgnoresAnythingOtherThanPostRequests() { $arguments = []; $arguments['__authentication']['TYPO3']['Flow']['Security']['Authentication']['Token']['PasswordToken']['password'] = '******'; $this->mockHttpRequest->expects($this->atLeastOnce())->method('getMethod')->will($this->returnValue('POST')); $this->mockActionRequest->expects($this->atLeastOnce())->method('getInternalArguments')->will($this->returnValue($arguments)); $this->token->updateCredentials($this->mockActionRequest); $this->assertEquals(['password' => 'verysecurepassword'], $this->token->getCredentials()); $secondToken = new PasswordToken(); $secondMockActionRequest = $this->getMockBuilder(ActionRequest::class)->disableOriginalConstructor()->getMock(); $secondMockHttpRequest = $this->getMockBuilder(Http\Request::class)->disableOriginalConstructor()->getMock(); $secondMockActionRequest->expects($this->any())->method('getHttpRequest')->will($this->returnValue($secondMockHttpRequest)); $secondMockHttpRequest->expects($this->atLeastOnce())->method('getMethod')->will($this->returnValue('GET')); $secondToken->updateCredentials($secondMockActionRequest); $this->assertEquals(['password' => ''], $secondToken->getCredentials()); }
/** * @test */ public function buildAddsActionNameFromRootRequestIfRequestIsOfTypeSubRequest() { $expectedArguments = ['@action' => 'RootRequestActionName']; $this->mockMainRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('RootRequestActionName')); $this->mockMainRequest->expects($this->any())->method('getArguments')->will($this->returnValue([])); $this->uriBuilder->setRequest($this->mockSubRequest); $this->uriBuilder->build(); $this->assertEquals($expectedArguments, $this->uriBuilder->getLastArguments()); }
/** * @test */ public function handleMergesInternalArgumentsWithRoutingMatchResults() { $this->mockHttpRequest->expects($this->any())->method('getArguments')->will($this->returnValue(['__internalArgument1' => 'request', '__internalArgument2' => 'request', '__internalArgument3' => 'request'])); $this->mockHttpRequest->expects(self::any())->method('getContent')->willReturn('requestBody'); $this->mockPropertyMapper->expects($this->any())->method('convert')->will($this->returnValue(['__internalArgument2' => 'requestBody', '__internalArgument3' => 'requestBody'])); $this->mockComponentContext->expects($this->atLeastOnce())->method('getParameter')->with(RoutingComponent::class, 'matchResults')->will($this->returnValue(['__internalArgument3' => 'routing'])); $this->mockActionRequest->expects($this->once())->method('setArguments')->with(['__internalArgument1' => 'request', '__internalArgument2' => 'requestBody', '__internalArgument3' => 'routing']); $this->dispatchComponent->handle($this->mockComponentContext); }
/** * @test */ public function tokenCanBeCastToString() { $arguments = []; $arguments['__authentication']['TYPO3']['Flow']['Security']['Authentication']['Token']['UsernamePassword']['username'] = '******'; $arguments['__authentication']['TYPO3']['Flow']['Security']['Authentication']['Token']['UsernamePassword']['password'] = '******'; $this->mockHttpRequest->expects($this->atLeastOnce())->method('getMethod')->will($this->returnValue('POST')); $this->mockActionRequest->expects($this->atLeastOnce())->method('getInternalArguments')->will($this->returnValue($arguments)); $this->token->updateCredentials($this->mockActionRequest); $this->assertEquals('Username: "******"', (string) $this->token); }
/** * @test */ public function matchRequestReturnsFalseIfAuthorizationChecksAreDisabled() { $httpRequest = Request::create(new Uri('http://localhost'), 'POST'); $this->mockActionRequest->expects($this->any())->method('getHttpRequest')->will($this->returnValue($httpRequest)); $mockAuthenticationManager = $this->getMockBuilder(AuthenticationManagerInterface::class)->disableOriginalConstructor()->getMock(); $mockAuthenticationManager->expects($this->any())->method('isAuthenticated')->will($this->returnValue(true)); $mockSecurityContext = $this->createMock(Security\Context::class); $mockSecurityContext->expects($this->atLeastOnce())->method('areAuthorizationChecksDisabled')->will($this->returnValue(true)); $mockCsrfProtectionPattern = $this->getAccessibleMock(Security\RequestPattern\CsrfProtection::class, ['dummy']); $mockCsrfProtectionPattern->_set('authenticationManager', $mockAuthenticationManager); $mockCsrfProtectionPattern->_set('systemLogger', $this->mockSystemLogger); $mockCsrfProtectionPattern->_set('securityContext', $mockSecurityContext); $this->assertFalse($mockCsrfProtectionPattern->matchRequest($this->mockActionRequest)); }
/** * @test */ public function evaluateIgnoresPackagePropertyIfAResourcePathIsGiven() { $this->mockTsRuntime->expects($this->any())->method('evaluate')->will($this->returnCallback(function ($evaluatePath, $that) { $relativePath = str_replace('resourceUri/test/', '', $evaluatePath); switch ($relativePath) { case 'path': return 'resource://Some.Package/Public/SomeResource'; case 'package': return 'Specified.Package'; } return null; })); $this->mockActionRequest->expects($this->any())->method('getControllerPackageKey')->will($this->returnValue('Current.Package')); $this->mockResourceManager->expects($this->atLeastOnce())->method('getPublicPackageResourceUri')->will($this->returnValue('Static/Resources/Packages/Some.Package/SomeResource')); $this->assertSame('Static/Resources/Packages/Some.Package/SomeResource', $this->resourceUriImplementation->evaluate()); }
/** * @test * @expectedException \Neos\Flow\Mvc\Exception\RequiredArgumentMissingException */ public function mapRequestArgumentsToControllerArgumentsThrowsExceptionIfRequiredArgumentWasNotSet() { $mockPropertyMapper = $this->getMockBuilder(PropertyMapper::class)->disableOriginalConstructor()->setMethods(['convert'])->getMock(); $mockPropertyMapper->expects($this->atLeastOnce())->method('convert')->will($this->returnArgument(0)); $controllerArguments = new Arguments(); $controllerArguments->addNewArgument('foo', 'string', true); $controllerArguments->addNewArgument('baz', 'string', true); foreach ($controllerArguments as $controllerArgument) { $this->inject($controllerArgument, 'propertyMapper', $mockPropertyMapper); } $controller = $this->getAccessibleMock(AbstractController::class, ['processRequest']); $controller->_call('initializeController', $this->mockActionRequest, $this->mockHttpResponse); $controller->_set('arguments', $controllerArguments); $this->mockActionRequest->expects($this->at(0))->method('hasArgument')->with('foo')->will($this->returnValue(true)); $this->mockActionRequest->expects($this->at(1))->method('getArgument')->with('foo')->will($this->returnValue('bar')); $this->mockActionRequest->expects($this->at(2))->method('hasArgument')->with('baz')->will($this->returnValue(false)); $controller->_call('mapRequestArgumentsToControllerArguments'); }
/** * @test */ public function processRequestInjectsSettingsToView() { $this->actionController = $this->getAccessibleMock(ActionController::class, ['resolveActionMethodName', 'initializeActionMethodArguments', 'initializeActionMethodValidators', 'resolveView', 'callActionMethod']); $this->inject($this->actionController, 'objectManager', $this->mockObjectManager); $this->inject($this->actionController, 'controllerContext', $this->mockControllerContext); $mockSettings = ['foo', 'bar']; $this->inject($this->actionController, 'settings', $mockSettings); $mockMvcPropertyMappingConfigurationService = $this->createMock(Mvc\Controller\MvcPropertyMappingConfigurationService::class); $this->inject($this->actionController, 'mvcPropertyMappingConfigurationService', $mockMvcPropertyMappingConfigurationService); $mockHttpRequest = $this->getMockBuilder(Http\Request::class)->disableOriginalConstructor()->getMock(); $mockHttpRequest->expects($this->any())->method('getNegotiatedMediaType')->will($this->returnValue('*/*')); $this->mockRequest->expects($this->any())->method('getHttpRequest')->will($this->returnValue($mockHttpRequest)); $mockResponse = $this->createMock(Http\Response::class); $mockView = $this->createMock(Mvc\View\ViewInterface::class); $mockView->expects($this->once())->method('assign')->with('settings', $mockSettings); $this->actionController->expects($this->once())->method('resolveView')->will($this->returnValue($mockView)); $this->actionController->processRequest($this->mockRequest, $mockResponse); }
public function setUp() { $this->viewConfigurationManager = new ViewConfigurationManager(); // eel evaluator $eelEvaluator = new CompilingEvaluator(); $this->inject($this->viewConfigurationManager, 'eelEvaluator', $eelEvaluator); // a dummy configuration manager is prepared $this->mockConfigurationManager = $this->getMockBuilder(ConfigurationManager::class)->disableOriginalConstructor()->getMock(); $this->inject($this->viewConfigurationManager, 'configurationManager', $this->mockConfigurationManager); // caching is deactivated $this->mockCache = $this->getMockBuilder(VariableFrontend::class)->disableOriginalConstructor()->getMock(); $this->mockCache->expects($this->any())->method('get')->will($this->returnValue(false)); $this->inject($this->viewConfigurationManager, 'cache', $this->mockCache); // a dummy request is prepared $this->mockActionRequest = $this->getMockBuilder(ActionRequest::class)->disableOriginalConstructor()->getMock(); $this->mockActionRequest->expects($this->any())->method('getControllerPackageKey')->will($this->returnValue('Neos.Flow')); $this->mockActionRequest->expects($this->any())->method('getControllerSubpackageKey')->will($this->returnValue('')); $this->mockActionRequest->expects($this->any())->method('getControllerName')->will($this->returnValue('Standard')); $this->mockActionRequest->expects($this->any())->method('getControllerActionName')->will($this->returnValue('index')); $this->mockActionRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html')); $this->mockActionRequest->expects($this->any())->method('getParentRequest')->will($this->returnValue(null)); }
/** * @test * @expectedException \Neos\Flow\Security\Exception\AccessDeniedException */ public function dispatchRethrowsAccessDeniedException() { $this->mockActionRequest->expects($this->any())->method('isDispatched')->will($this->returnValue(true)); $this->mockFirewall->expects($this->once())->method('blockIllegalRequests')->will($this->throwException(new AccessDeniedException())); $this->dispatcher->dispatch($this->mockActionRequest, $this->mockHttpResponse); }