/**
  * @test
  */
 public function testGetCurrentConfigurationNameReturnsRequestParameterIfActionIsSave()
 {
     $request = new Request();
     $request->setControllerActionName('save');
     $request->setArguments(array('configurationName' => 'foobar'));
     $instance = $this->getMockForAbstractClass('FluidTYPO3\\Fluidbackend\\Controller\\AbstractBackendController');
     $this->inject($instance, 'request', $request);
     $result = $this->callInaccessibleMethod($instance, 'getCurrentConfigurationName');
     $this->assertEquals('foobar', $result);
 }
 /**
  * Test for forwardIfFormParamsDoNotMatch()
  *
  * @param array $arguments
  * @param array $settings
  * @param bool $forwardActive
  * @return void
  * @dataProvider forwardIfFormParamsDoNotMatchReturnsVoidDataProvider
  * @test
  */
 public function forwardIfFormParamsDoNotMatchReturnsVoid($arguments, $settings, $forwardActive)
 {
     $request = new Request();
     $request->setArguments($arguments);
     $this->generalValidatorMock->_set('request', $request);
     $this->generalValidatorMock->_set('settings', $settings);
     try {
         // if forward() is called, an exception will be thrown
         $this->generalValidatorMock->_callRef('forwardIfFormParamsDoNotMatch');
     } catch (\Exception $exception) {
         return;
     }
     $this->assertFalse($forwardActive);
 }
Ejemplo n.º 3
0
 /**
  * @return \TYPO3\CMS\Core\Messaging\FlashMessageQueue
  * @api
  */
 public function getFlashMessageQueue()
 {
     if (!$this->flashMessageQueue instanceof \TYPO3\CMS\Core\Messaging\FlashMessageQueue) {
         $this->flashMessageQueue = $this->flashMessageService->getMessageQueueByIdentifier('extbase.flashmessages.' . $this->extensionService->getPluginNamespace($this->request->getControllerExtensionName(), $this->request->getPluginName()));
     }
     return $this->flashMessageQueue;
 }
 /**
  * @test
  */
 public function renderSetsExtbaseControllerActionNameInRequest()
 {
     $this->addMockViewToSubject();
     $this->request->expects($this->once())->method('setControllerActionName')->with('foo');
     $configuration = array('extbase.' => array('controllerActionName' => 'foo'));
     $this->subject->render($configuration);
 }
Ejemplo n.º 5
0
 /**
  * Maps arguments delivered by the request object to the local controller arguments.
  *
  * @throws Exception\RequiredArgumentMissingException
  * @return void
  */
 protected function mapRequestArgumentsToControllerArguments()
 {
     if ($this->configurationManager->isFeatureEnabled('rewrittenPropertyMapper')) {
         foreach ($this->arguments as $argument) {
             $argumentName = $argument->getName();
             if ($this->request->hasArgument($argumentName)) {
                 $argument->setValue($this->request->getArgument($argumentName));
             } elseif ($argument->isRequired()) {
                 throw new \TYPO3\CMS\Extbase\Mvc\Controller\Exception\RequiredArgumentMissingException('Required argument "' . $argumentName . '" is not set for ' . $this->request->getControllerObjectName() . '->' . $this->request->getControllerActionName() . '.', 1298012500);
             }
         }
     } else {
         // @deprecated since Extbase 1.4, will be removed two versions after Extbase 6.1
         $optionalPropertyNames = array();
         $allPropertyNames = $this->arguments->getArgumentNames();
         foreach ($allPropertyNames as $propertyName) {
             if ($this->arguments[$propertyName]->isRequired() === FALSE) {
                 $optionalPropertyNames[] = $propertyName;
             }
         }
         /** @var $validator ArgumentsValidator */
         $validator = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ArgumentsValidator');
         $this->deprecatedPropertyMapper->mapAndValidate($allPropertyNames, $this->request->getArguments(), $this->arguments, $optionalPropertyNames, $validator);
         $this->argumentsMappingResults = $this->deprecatedPropertyMapper->getMappingResults();
     }
 }
Ejemplo n.º 6
0
 /**
  * @param null $hashVars
  * @return string
  */
 private function getCacheID($hashVars = null)
 {
     $additionalHashVars = array('pid' => $GLOBALS['TSFE']->id, 'lang' => $GLOBALS['TSFE']->sys_language_uid, 'uid' => $this->_configurationManager->getContentObject()->data['uid']);
     if (!is_null($GLOBALS['TSFE']->fe_user->user)) {
         $additionalHashVars[] = $GLOBALS['TSFE']->fe_user->user['ses_id'];
     }
     $additionalHashVars = array_merge($additionalHashVars, $this->_request->getArguments());
     $hashVars = array_merge($additionalHashVars, $hashVars);
     $hashString = join('|', array_values($hashVars)) . join('|', array_keys($hashVars));
     return md5($hashString);
 }
Ejemplo n.º 7
0
 /**
  * @param string $identifier Queue-identifier
  * @return \TYPO3\CMS\Core\Messaging\FlashMessageQueue
  * @api
  */
 public function getFlashMessageQueue($identifier = null)
 {
     if ($identifier === null) {
         if ($this->flashMessageQueueDefaultIdentifier === null) {
             // cache the default-identifier for performance-reasons
             $this->flashMessageQueueDefaultIdentifier = 'extbase.flashmessages.' . $this->extensionService->getPluginNamespace($this->request->getControllerExtensionName(), $this->request->getPluginName());
         }
         $identifier = $this->flashMessageQueueDefaultIdentifier;
     }
     return $this->flashMessageService->getMessageQueueByIdentifier($identifier);
 }
 /**
  * Add support for variable argument lists using a wildcard property name '*'.
  * This is required for a file multiupload, as you can't guess how many files
  * will be uploaded when rendering the form (and generating the
  * trustedPropertiesToken) on the server.
  *
  * You can use it like this:
  * If you write a formfield viewhelper, you have to register all the properties
  * that should be mapped when processing the input on the server. To allow
  * the mapping of some properties of all submitted elements, insert a wildcard
  * in the path at the position where new keys will appear. This class will
  * enable the mapping of all arguments that are assigned to this path.
  *
  * So, if you have this line in your viewhelper:
  *		$this->registerFieldNameForFormTokenGeneration('my_plugin[my_object][object_storage_property][*][foo]');
  * and request arguments like this:
  *		array( 'my_object' => array( 'object_storage_property' => array(
  *			0 => array( 'foo' => 13 ),
  *			1 => array( 'foo' => 42 ),
  *			2 => array( 'foo' => false )
  *		)))
  * the PropertyMapper won't complain about missing permissions to "map
  * attribute my_object.object_storage_property.0".
  *
  * This is different from simply using $propertyMappingConfiguration->allowAllProperties()
  * because:
  * - You don't have to post that line into each of your controllers
  * - You can control which sub-properties to map
  * - You don't override assigned settings for specific keys: if there is a
  *   configuration for my_object.object_storage_property.42, it won't be
  *   changed to the wildcard value.
  *
  * @param \TYPO3\CMS\Extbase\Mvc\Request $request
  * @param \TYPO3\CMS\Extbase\Mvc\Controller\Arguments $controllerArguments
  * @return void
  */
 public function initializePropertyMappingConfigurationFromRequest(\TYPO3\CMS\Extbase\Mvc\Request $request, \TYPO3\CMS\Extbase\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();
         //
         // Extended from parent class - begin
         //
         if (is_array($propertyConfiguration)) {
             foreach (HelhumArrayUtility::getPathsToKey($propertyConfiguration, '*') as $path) {
                 $configurationTemplate = ExtbaseArrayUtility::getValueByPath($propertyConfiguration, $path . '.*');
                 $propertyConfiguration = ExtbaseArrayUtility::unsetValueByPath($propertyConfiguration, $path . '.*');
                 if ($request->hasArgument($propertyName) && is_array($request->getArgument($propertyName))) {
                     $rawArgument = ExtbaseArrayUtility::getValueByPath($request->getArgument($propertyName), $path);
                     $subPropertyConfiguration = ExtbaseArrayUtility::getValueByPath($propertyConfiguration, $path);
                     foreach ($rawArgument as $index => $_) {
                         if (!is_int($index) || array_key_exists($index, $subPropertyConfiguration)) {
                             continue;
                         }
                         $propertyConfiguration = ExtbaseArrayUtility::setValueByPath($propertyConfiguration, $path . '.' . $index, $configurationTemplate);
                     }
                 }
             }
         }
         //
         // Extended from parent class - end
         //
         $this->modifyPropertyMappingConfiguration($propertyConfiguration, $propertyMappingConfiguration);
     }
 }
Ejemplo n.º 9
0
 /**
  * Test for render()
  *
  * @param array $settings
  * @param array $fieldProperties
  * @param array $additionalAttributes
  * @param mixed $iteration
  * @param array $expectedResult
  * @return void
  * @dataProvider renderReturnsArrayDataProvider
  * @test
  */
 public function renderReturnsArray($settings, $fieldProperties, $additionalAttributes, $iteration, $expectedResult)
 {
     $field = new Field();
     foreach ($fieldProperties as $propertyName => $propertyValue) {
         $field->_setProperty($propertyName, $propertyValue);
     }
     $this->abstractValidationViewHelperMock->_set('settings', $settings);
     $this->abstractValidationViewHelperMock->_set('extensionName', 'powermail');
     $controllerContext = new ControllerContext();
     $request = new Request();
     $request->setControllerExtensionName('powermail');
     $controllerContext->setRequest($request);
     $this->abstractValidationViewHelperMock->_set('controllerContext', $controllerContext);
     $result = $this->abstractValidationViewHelperMock->_callRef('render', $field, $additionalAttributes, $iteration);
     $this->assertSame($expectedResult, $result);
 }
Ejemplo n.º 10
0
 /**
  * Builds a TypoLink configuration array from the current settings
  *
  * @return array typolink configuration array
  * @see TSref/typolink
  */
 protected function buildTypolinkConfiguration()
 {
     $typolinkConfiguration = array();
     $typolinkConfiguration['parameter'] = $this->targetPageUid !== null ? $this->targetPageUid : $GLOBALS['TSFE']->id;
     if ($this->targetPageType !== 0) {
         $typolinkConfiguration['parameter'] .= ',' . $this->targetPageType;
     } elseif ($this->format !== '') {
         $targetPageType = $this->extensionService->getTargetPageTypeByFormat($this->request->getControllerExtensionName(), $this->format);
         $typolinkConfiguration['parameter'] .= ',' . $targetPageType;
     }
     if (!empty($this->arguments)) {
         $arguments = $this->convertDomainObjectsToIdentityArrays($this->arguments);
         $this->lastArguments = $arguments;
         $typolinkConfiguration['additionalParams'] = GeneralUtility::implodeArrayForUrl(null, $arguments);
     }
     if ($this->addQueryString === true) {
         $typolinkConfiguration['addQueryString'] = 1;
         if (!empty($this->argumentsToBeExcludedFromQueryString)) {
             $typolinkConfiguration['addQueryString.'] = array('exclude' => implode(',', $this->argumentsToBeExcludedFromQueryString));
         }
         if ($this->addQueryStringMethod) {
             $typolinkConfiguration['addQueryString.']['method'] = $this->addQueryStringMethod;
         }
     }
     if ($this->noCache === true) {
         $typolinkConfiguration['no_cache'] = 1;
     } elseif ($this->useCacheHash) {
         $typolinkConfiguration['useCacheHash'] = 1;
     }
     if ($this->section !== '') {
         $typolinkConfiguration['section'] = $this->section;
     }
     if ($this->linkAccessRestrictedPages === true) {
         $typolinkConfiguration['linkAccessRestrictedPages'] = 1;
     }
     return $typolinkConfiguration;
 }
Ejemplo n.º 11
0
 /**
  * Checks honeypot fields
  *
  * @param Request $request The request to be checked
  *
  * @return boolean
  */
 protected function checkHoneyPotFields(Request $request)
 {
     if (!$request->hasArgument('author') || strlen($request->getArgument('author')) > 0) {
         return FALSE;
     }
     if (!$request->hasArgument('link') || strlen($request->getArgument('link')) > 0) {
         return FALSE;
     }
     if (!$request->hasArgument('text') || strlen($request->getArgument('text')) > 0) {
         return FALSE;
     }
     if (!$request->hasArgument('timestamp') || $request->getArgument('timestamp') !== '1368283172') {
         return FALSE;
     }
     return TRUE;
 }
 /**
  * Initialize the property mapping configuration in $controllerArguments if
  * the trusted properties are set inside the request.
  *
  * @param \TYPO3\CMS\Extbase\Mvc\Request $request
  * @param \TYPO3\CMS\Extbase\Mvc\Controller\Arguments $controllerArguments
  *
  * @return void
  */
 public function initializePropertyMappingConfigurationFromRequest(\TYPO3\CMS\Extbase\Mvc\Request $request, \TYPO3\CMS\Extbase\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);
     }
 }
Ejemplo n.º 13
0
 /**
  * Get Cart/Product From Request
  *
  * @param array $pluginSettings TypoScript Plugin Settings
  * @param Request $request Request
  * @param \Extcode\Cart\Domain\Model\Cart\TaxClass[] $taxClasses Tax Class Array
  *
  * @return \Extcode\Cart\Domain\Model\Cart\Product[]
  */
 public function getProductsFromRequest(array $pluginSettings, Request $request, array $taxClasses)
 {
     if (!$this->pluginSettings) {
         $this->pluginSettings = $pluginSettings;
     }
     if (!$this->taxClasses) {
         $this->taxClasses = $taxClasses;
     }
     $multiple = 1;
     if ($this->pluginSettings['multiple']) {
         $argumentName = $this->pluginSettings['multiple'];
         if ($request->hasArgument($argumentName)) {
             $multiple = intval($request->getArgument($argumentName));
         }
     }
     $products = [];
     $preCartProductSets = [];
     if ($multiple == 1) {
         $preCartProductSets[1] = $this->parserUtility->getPreCartProductSet($pluginSettings, $request);
     } else {
         // TODO: iterate over request
     }
     foreach ($preCartProductSets as $preCartProductSetKey => $preCartProductSetValue) {
         if ($preCartProductSetValue['contentId']) {
             $products[$preCartProductSetKey] = $this->getCartProductFromCE($preCartProductSetValue);
         } elseif ($preCartProductSetValue['productId']) {
             $products[$preCartProductSetKey] = $this->getCartProductFromDatabase($preCartProductSetValue);
         }
     }
     return $products;
 }
Ejemplo n.º 14
0
 /**
  * @param array $pluginSettings
  * @param Request $request Request
  *
  * @return array
  */
 public function getPreCartProductSet(array $pluginSettings, Request $request)
 {
     if (!$this->pluginSettings) {
         $this->pluginSettings = $pluginSettings;
     }
     $productValueSet = [];
     if ($request->hasArgument('productId')) {
         $productValueSet['productId'] = intval($request->getArgument('productId'));
     }
     if ($request->hasArgument('tableId')) {
         $productValueSet['tableId'] = intval($request->getArgument('tableId'));
     }
     if ($request->hasArgument('repositoryId')) {
         $productValueSet['repositoryId'] = intval($request->getArgument('repositoryId'));
     }
     if ($request->hasArgument('contentId')) {
         $productValueSet['contentId'] = intval($request->getArgument('contentId'));
     }
     if ($request->hasArgument('quantity')) {
         $quantity = intval($request->getArgument('quantity'));
         $productValueSet['quantity'] = $quantity ? $quantity : 1;
     }
     if ($request->hasArgument('feVariants')) {
         $requestFeVariants = $request->getArgument('feVariants');
         if (is_array($requestFeVariants)) {
             foreach ($requestFeVariants as $requestFeVariantKey => $requestFeVariantValue) {
                 $productValueSet['feVariants'][$requestFeVariantKey] = $requestFeVariantValue;
             }
         }
     }
     if ($request->hasArgument('beVariants')) {
         $requestVariants = $request->getArgument('beVariants');
         if (is_array($requestVariants)) {
             foreach ($requestVariants as $requestVariantKey => $requestVariantValue) {
                 $productValueSet['beVariants'][$requestVariantKey] = intval($requestVariantValue);
             }
         }
     }
     return $productValueSet;
 }
 /**
  * Render
  *
  * @return string
  */
 public function render()
 {
     return $this->request->getArgument($this->arguments['key']);
 }
Ejemplo n.º 16
0
 /**
  * A special action which is called if the originally intended action could
  * not be called, for example if the arguments were not valid.
  *
  * The default implementation sets a flash message, request errors and forwards back
  * to the originating action. This is suitable for most actions dealing with form input.
  *
  * We clear the page cache by default on an error as well, as we need to make sure the
  * data is re-evaluated when the user changes something.
  *
  * @return string
  * @api
  */
 protected function errorAction()
 {
     $this->clearCacheOnError();
     $errorFlashMessage = $this->getErrorFlashMessage();
     if ($errorFlashMessage !== FALSE) {
         $errorFlashMessageObject = new \TYPO3\CMS\Core\Messaging\FlashMessage($errorFlashMessage, '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
         $this->controllerContext->getFlashMessageQueue()->enqueue($errorFlashMessageObject);
     }
     $referringRequest = $this->request->getReferringRequest();
     if ($referringRequest !== NULL) {
         $originalRequest = clone $this->request;
         $this->request->setOriginalRequest($originalRequest);
         $this->request->setOriginalRequestMappingResults($this->arguments->getValidationResults());
         $this->forward($referringRequest->getControllerActionName(), $referringRequest->getControllerName(), $referringRequest->getControllerExtensionName(), $referringRequest->getArguments());
     }
     $message = 'An error occurred while trying to call ' . get_class($this) . '->' . $this->actionMethodName . '().' . PHP_EOL;
     return $message;
 }
Ejemplo n.º 17
0
 /**
  * If information on the request before the current request was sent, this method forwards back
  * to the originating request. This effectively ends processing of the current request, so do not
  * call this method before you have finished the necessary business logic!
  *
  * @return void
  * @throws StopActionException
  */
 protected function forwardToReferringRequest()
 {
     $referringRequest = $this->request->getReferringRequest();
     if ($referringRequest !== null) {
         $originalRequest = clone $this->request;
         $this->request->setOriginalRequest($originalRequest);
         $this->request->setOriginalRequestMappingResults($this->arguments->getValidationResults());
         $this->forward($referringRequest->getControllerActionName(), $referringRequest->getControllerName(), $referringRequest->getControllerExtensionName(), $referringRequest->getArguments());
     }
 }
 /**
  * Gets a localized error message
  *
  * @return string
  */
 public function getErrorFlashMessage()
 {
     $controllerName = strtolower($this->request->getControllerName());
     $actionName = strtolower($this->request->getControllerActionName());
     return $this->translate('error.' . $controllerName . '.' . $actionName . '.' . $this->accessError, 't3events_reservation');
 }
 /**
  * @param \TYPO3\CMS\Extbase\Mvc\Request $request
  * @return string $text
  */
 public static function plainText($request)
 {
     define(NL, "\n");
     $text = 'Kontaktdaten:' . NL;
     if ($request->hasArgument('companyName')) {
         $text .= 'Firma: ' . $request->getArgument('companyName') . NL;
     }
     if ($request->hasArgument('firstName')) {
         $firstName = $request->getArgument('firstName') . ' ';
     } else {
         $firstName = '';
     }
     if ($request->hasArgument('lastName')) {
         $text .= 'Ansprechpartner: ' . $firstName . $request->getArgument('lastName') . NL . NL;
     }
     if ($request->hasArgument('address')) {
         $text .= $request->getArgument('address') . NL;
     }
     if ($request->hasArgument('zip')) {
         $text .= $request->getArgument('zip') . ' ';
     }
     if ($request->hasArgument('city')) {
         $text .= $request->getArgument('city') . NL;
     }
     if ($request->hasArgument('country')) {
         $text .= $request->getArgument('country') . NL . NL;
     }
     if ($request->hasArgument('email')) {
         $text .= 'E-Mail: ' . $request->getArgument('email') . NL;
     }
     if ($request->hasArgument('phone')) {
         $text .= 'Phone: ' . $request->getArgument('phone') . NL;
     }
     return $text;
 }