/**
  * @test
  */
 public function processRequestResetsCommandMethodArguments()
 {
     $mockRequest = $this->getMockBuilder(\TYPO3\Flow\Cli\Request::class)->disableOriginalConstructor()->getMock();
     $mockResponse = $this->getMockBuilder(\TYPO3\Flow\Mvc\ResponseInterface::class)->getMock();
     $mockArguments = new Arguments();
     $mockArguments->addNewArgument('foo');
     $this->inject($this->commandController, 'arguments', $mockArguments);
     $this->assertCount(1, $this->commandController->_get('arguments'));
     $this->commandController->processRequest($mockRequest, $mockResponse);
     $this->assertCount(0, $this->commandController->_get('arguments'));
 }
 /**
  * Forwards the request to another action and / or controller.
  *
  * Request is directly transferred to the other action / controller
  *
  * @param string $actionName Name of the action to forward to
  * @param string $controllerName Unqualified object name of the controller to forward to. If not specified, the current controller is used.
  * @param string $packageKey Key of the package containing the controller to forward to. May also contain the sub package, concatenated with backslash (Vendor.Foo\Bar\Baz). If not specified, the current package is assumed.
  * @param array $arguments Arguments to pass to the target action
  * @return void
  * @throws \TYPO3\Flow\Mvc\Exception\ForwardException
  * @see redirect()
  * @api
  */
 protected function forward($actionName, $controllerName = null, $packageKey = null, array $arguments = array())
 {
     $nextRequest = clone $this->request;
     $nextRequest->setControllerActionName($actionName);
     if ($controllerName !== null) {
         $nextRequest->setControllerName($controllerName);
     }
     if ($packageKey !== null && strpos($packageKey, '\\') !== false) {
         list($packageKey, $subpackageKey) = explode('\\', $packageKey, 2);
     } else {
         $subpackageKey = null;
     }
     if ($packageKey !== null) {
         $nextRequest->setControllerPackageKey($packageKey);
     }
     if ($subpackageKey !== null) {
         $nextRequest->setControllerSubpackageKey($subpackageKey);
     }
     $regularArguments = array();
     foreach ($arguments as $argumentName => $argumentValue) {
         if (substr($argumentName, 0, 2) === '__') {
             $nextRequest->setArgument($argumentName, $argumentValue);
         } else {
             $regularArguments[$argumentName] = $argumentValue;
         }
     }
     $nextRequest->setArguments($this->persistenceManager->convertObjectsToIdentityArrays($regularArguments));
     $this->arguments->removeAll();
     $forwardException = new \TYPO3\Flow\Mvc\Exception\ForwardException();
     $forwardException->setNextRequest($nextRequest);
     throw $forwardException;
 }
 protected function setUp()
 {
     $this->service = new CacheControlService();
     $this->mockContentCacheAspect = $this->getMock('MOC\\Varnish\\Aspects\\ContentCacheAspect');
     $this->inject($this->service, 'contentCacheAspect', $this->mockContentCacheAspect);
     $this->mockLogger = $this->getMockBuilder('MOC\\Varnish\\Log\\LoggerInterface')->getMock();
     $this->inject($this->service, 'logger', $this->mockLogger);
     $this->contentCacheFrontend = new MetadataAwareStringFrontend('test', new TransientMemoryBackend(new ApplicationContext('Testing')));
     $this->contentCacheFrontend->initializeObject();
     $this->inject($this->service, 'contentCacheFrontend', $this->contentCacheFrontend);
     $this->mockTokenStorage = $this->getMock('MOC\\Varnish\\Service\\TokenStorage');
     $this->inject($this->service, 'tokenStorage', $this->mockTokenStorage);
     $this->mockRequest = $this->getMock('TYPO3\\Flow\\Mvc\\RequestInterface');
     $this->mockResponse = $this->getMock('TYPO3\\Flow\\Http\\Response');
     $this->mockController = $this->getMock('TYPO3\\Neos\\Controller\\Frontend\\NodeController');
     $this->mockControllerContext = $this->getMockBuilder('TYPO3\\Flow\\Mvc\\Controller\\ControllerContext')->disableOriginalConstructor()->getMock();
     $this->mockController->expects($this->any())->method('getControllerContext')->willReturn($this->mockControllerContext);
     $this->mockArguments = $this->getMockBuilder('TYPO3\\Flow\\Mvc\\Controller\\Arguments')->getMock();
     $this->mockControllerContext->expects($this->any())->method('getArguments')->willReturn($this->mockArguments);
     $this->mockArguments->expects($this->any())->method('hasArgument')->with('node')->willReturn(TRUE);
     $this->mockArgument = $this->getMockBuilder('TYPO3\\Flow\\Mvc\\Controller\\Argument')->disableOriginalConstructor()->getMock();
     $this->mockArguments->expects($this->any())->method('getArgument')->with('node')->willReturn($this->mockArgument);
     $this->mockNode = $this->getMock('TYPO3\\TYPO3CR\\Domain\\Model\\NodeInterface');
     $this->mockArgument->expects($this->any())->method('getValue')->willReturn($this->mockNode);
     $this->mockContext = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Service\\Context')->disableOriginalConstructor()->getMock();
     $this->mockNode->expects($this->any())->method('getContext')->willReturn($this->mockContext);
 }
 /**
  * Forwards the request to another command and / or CommandController.
  *
  * Request is directly transferred to the other command / controller
  * without the need for a new request.
  *
  * @param string $commandName
  * @param string $controllerObjectName
  * @param array $arguments
  * @return void
  * @throws StopActionException
  */
 protected function forward($commandName, $controllerObjectName = null, array $arguments = array())
 {
     $this->request->setDispatched(false);
     $this->request->setControllerCommandName($commandName);
     if ($controllerObjectName !== null) {
         $this->request->setControllerObjectName($controllerObjectName);
     }
     $this->request->setArguments($arguments);
     $this->arguments->removeAll();
     throw new StopActionException();
 }
 /**
  * Initialize the property mapping configuration in $controllerArguments if
  * the trusted properties are set inside the request.
  *
  * @param \TYPO3\Flow\Mvc\ActionRequest $request
  * @param \TYPO3\Flow\Mvc\Controller\Arguments $controllerArguments
  * @return void
  */
 public function initializePropertyMappingConfigurationFromRequest(\TYPO3\Flow\Mvc\ActionRequest $request, \TYPO3\Flow\Mvc\Controller\Arguments $controllerArguments)
 {
     $trustedPropertiesToken = $request->getInternalArgument('__trustedProperties');
     if (!is_string($trustedPropertiesToken)) {
         return;
     }
     $serializedTrustedProperties = $this->hashService->validateAndStripHmac($trustedPropertiesToken);
     $trustedProperties = unserialize($serializedTrustedProperties);
     foreach ($trustedProperties as $propertyName => $propertyConfiguration) {
         if (!$controllerArguments->hasArgument($propertyName)) {
             continue;
         }
         $propertyMappingConfiguration = $controllerArguments->getArgument($propertyName)->getPropertyMappingConfiguration();
         $this->modifyPropertyMappingConfiguration($propertyConfiguration, $propertyMappingConfiguration);
     }
 }
 /**
  * @test
  * @expectedException \TYPO3\Flow\Mvc\Exception\RequiredArgumentMissingException
  */
 public function mapRequestArgumentsToControllerArgumentsThrowsExceptionIfRequiredArgumentWasNotSet()
 {
     $mockPropertyMapper = $this->getMockBuilder(\TYPO3\Flow\Property\PropertyMapper::class)->disableOriginalConstructor()->setMethods(array('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(\TYPO3\Flow\Mvc\Controller\AbstractController::class, array('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 addingAnArgumentUsesStringAsDataTypeDefault()
 {
     $arguments = new Arguments();
     $argument = $arguments->addNewArgument('someArgumentName');
     $this->assertEquals('string', $argument->getDataType());
 }
 /**
  * @test
  */
 public function getValidationResultsShouldFetchAllValidationResltsFromArguments()
 {
     $error1 = new \TYPO3\Flow\Error\Error('Validation error', 1234);
     $error2 = new \TYPO3\Flow\Error\Error('Validation error 2', 1235);
     $results1 = new \TYPO3\Flow\Error\Result();
     $results1->addError($error1);
     $results2 = new \TYPO3\Flow\Error\Result();
     $results2->addError($error2);
     $argument1 = $this->getMock('TYPO3\\Flow\\Mvc\\Controller\\Argument', array('getValidationResults'), array('name1', 'string'));
     $argument1->expects($this->once())->method('getValidationResults')->will($this->returnValue($results1));
     $argument2 = $this->getMock('TYPO3\\Flow\\Mvc\\Controller\\Argument', array('getValidationResults'), array('name2', 'string'));
     $argument2->expects($this->once())->method('getValidationResults')->will($this->returnValue($results2));
     $arguments = new \TYPO3\Flow\Mvc\Controller\Arguments();
     $arguments->addArgument($argument1);
     $arguments->addArgument($argument2);
     $this->assertSame(array('name1' => array($error1), 'name2' => array($error2)), $arguments->getValidationResults()->getFlattenedErrors());
 }
 /**
  * @test
  * @expectedException TYPO3\Flow\Mvc\Exception\RequiredArgumentMissingException
  */
 public function mapRequestArgumentsToControllerArgumentsThrowsExceptionIfRequiredArgumentWasNotSet()
 {
     $httpRequest = HttpRequest::create(new Uri('http://localhost/'));
     $request = $httpRequest->createActionRequest();
     $response = new HttpResponse();
     $controllerArguments = new Arguments();
     $controllerArguments->addNewArgument('foo', 'string', TRUE);
     $controller = $this->getAccessibleMock('TYPO3\\Flow\\Mvc\\Controller\\AbstractController', array('processRequest'));
     $this->inject($controller, 'flashMessageContainer', new FlashMessageContainer());
     $controller->_call('initializeController', $request, $response);
     $controller->_set('arguments', $controllerArguments);
     $controller->_call('mapRequestArgumentsToControllerArguments');
 }
 /**
  * @test
  * @expectedException \TYPO3\Flow\Mvc\Exception\RequiredArgumentMissingException
  */
 public function mapRequestArgumentsToControllerArgumentsThrowsExceptionIfRequiredArgumentWasNotSet()
 {
     $mockPropertyMapper = $this->getMock('TYPO3\\Flow\\Property\\PropertyMapper', array('convert'), array(), '', FALSE);
     $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('TYPO3\\Flow\\Mvc\\Controller\\AbstractController', array('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');
 }