Inheritance: extends ArrayObject
コード例 #1
0
 /**
  * @test
  */
 public function processRequestResetsCommandMethodArguments()
 {
     $mockRequest = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->getMock();
     $mockResponse = $this->getMockBuilder(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'));
 }
コード例 #2
0
 /**
  * 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 ForwardException
  * @see redirect()
  * @api
  */
 protected function forward($actionName, $controllerName = null, $packageKey = null, array $arguments = [])
 {
     $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);
         $nextRequest->setControllerSubpackageKey($subpackageKey);
     }
     $regularArguments = [];
     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 ForwardException();
     $forwardException->setNextRequest($nextRequest);
     throw $forwardException;
 }
コード例 #3
0
 /**
  * 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 = [])
 {
     $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 ActionRequest $request
  * @param Arguments $controllerArguments
  * @return void
  */
 public function initializePropertyMappingConfigurationFromRequest(ActionRequest $request, 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);
     }
 }
 /**
  * Helper which initializes the property mapping configuration and returns arguments
  *
  * @param array $trustedProperties
  * @return Mvc\Controller\Arguments
  */
 protected function initializePropertyMappingConfiguration(array $trustedProperties)
 {
     $request = $this->getMockBuilder(Mvc\ActionRequest::class)->setMethods(['getInternalArgument'])->disableOriginalConstructor()->getMock();
     $request->expects($this->any())->method('getInternalArgument')->with('__trustedProperties')->will($this->returnValue('fooTrustedProperties'));
     $arguments = new Mvc\Controller\Arguments();
     $mockHashService = $this->getMockBuilder(HashService::class)->setMethods(['validateAndStripHmac'])->getMock();
     $mockHashService->expects($this->once())->method('validateAndStripHmac')->with('fooTrustedProperties')->will($this->returnValue(serialize($trustedProperties)));
     $arguments->addNewArgument('foo', 'something');
     $this->inject($arguments->getArgument('foo'), 'propertyMappingConfiguration', new PropertyMappingConfiguration());
     $requestHashService = new Mvc\Controller\MvcPropertyMappingConfigurationService();
     $this->inject($requestHashService, 'hashService', $mockHashService);
     $requestHashService->initializePropertyMappingConfigurationFromRequest($request, $arguments);
     return $arguments;
 }
コード例 #6
0
 /**
  * @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');
 }
コード例 #7
0
 /**
  * @test
  */
 public function addingAnArgumentUsesStringAsDataTypeDefault()
 {
     $arguments = new Arguments();
     $argument = $arguments->addNewArgument('someArgumentName');
     $this->assertEquals('string', $argument->getDataType());
 }