[~FEATURE] Fluid (ViewHelpers): Adjusted AbstractFormViewHelper to be able to namespa...
authorJochen Rau <j.rau@web.de>
Mon, 10 Aug 2009 23:37:02 +0000 (23:37 +0000)
committerJochen Rau <j.rau@web.de>
Mon, 10 Aug 2009 23:37:02 +0000 (23:37 +0000)
14 files changed:
typo3/sysext/fluid/Classes/ViewHelpers/Form/AbstractFormViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Form/HiddenViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Form/SelectViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Form/TextareaViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Form/TextboxViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Form/UploadViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/FormViewHelper.php
typo3/sysext/fluid/Tests/ViewHelpers/BaseViewHelperTest_testcase.php
typo3/sysext/fluid/Tests/ViewHelpers/Form/AbstractFormViewHelperTest_testcase.php
typo3/sysext/fluid/Tests/ViewHelpers/Form/ErrorsViewHelperTest_testcase.php
typo3/sysext/fluid/Tests/ViewHelpers/Form/SelectViewHelperTest_testcase.php
typo3/sysext/fluid/Tests/ViewHelpers/FormViewHelperTest_testcase.php
typo3/sysext/fluid/Tests/ViewHelpers/ViewHelperBaseTestcase.php
typo3/sysext/fluid/ext_autoload.php

index 0621259..3b1cee4 100644 (file)
@@ -26,7 +26,7 @@
  * If you set the "property" attribute to the name of the property to resolve from the object, this class will
  * automatically set the name and value of a form element.
  *
- * @version $Id: AbstractFormViewHelper.php 2914 2009-07-28 18:26:38Z bwaidelich $
+ * @version $Id: AbstractFormViewHelper.php 2968 2009-08-03 10:45:13Z sebastian $
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  * @scope prototype
  */
@@ -49,138 +49,25 @@ abstract class Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper extends Tx_Fluid
        }
 
        /**
-        * Initialize arguments.
+        * Prefixes / namespaces the given name with the form field prefix
         *
-        * @return void
-        * @author Sebastian Kurfürst <sebastian@typo3.org>
-        * @api
-        */
-       public function initializeArguments() {
-               parent::initializeArguments();
-               $this->registerArgument('name', 'string', 'Name of input tag');
-               $this->registerArgument('value', 'mixed', 'Value of input tag');
-               $this->registerArgument('property', 'string', 'Name of Object Property. If used in conjunction with <f:form object="...">, "name" and "value" properties will be ignored.');
-       }
-
-       /**
-        * Get the name of this form element.
-        * Either returns arguments['name'], or the correct name for Object Access.
-        *
-        * @return string Name
-        * @author Sebastian Kurfürst <sebastian@typo3.org>
-        * @author Robert Lemke <robert@typo3.org>
-        * @author Karsten Dambekalns <karsten@typo3.org>
-        */
-       protected function getName() {
-               $name = ($this->isObjectAccessorMode()) ? $this->viewHelperVariableContainer->get('Tx_Fluid_ViewHelpers_FormViewHelper', 'formName') . '[' . $this->arguments['property'] . ']' : $this->arguments['name'];
-               if (is_object($this->arguments['value']) && NULL !== $this->persistenceManager->getBackend()->getIdentifierByObject($this->arguments['value'])
-                               && (!$this->persistenceManager->getBackend()->isNewObject($this->arguments['value']))) {
-                       $name .= '[uid]';
-               }
-               return $name;
-       }
-
-       /**
-        * Get the value of this form element.
-        * Either returns arguments['value'], or the correct value for Object Access.
-        *
-        * @return mixed Value
-        * @author Sebastian Kurfürst <sebastian@typo3.org>
-        * @author Robert Lemke <robert@typo3.org>
-        * @author Bastian Waidelich <bastian@typo3.org>
-        */
-       protected function getValue() {
-               $value = NULL;
-               if ($this->arguments->hasArgument('value')) {
-                       $value = $this->arguments['value'];
-               } elseif ($this->isObjectAccessorMode() && $this->viewHelperVariableContainer->exists('Tx_Fluid_ViewHelpers_FormViewHelper', 'formObject')) {
-                       $value = $this->getPropertyValue();
-               }
-               if (is_object($value)) {
-                       $identifier = $this->persistenceManager->getBackend()->getIdentifierByObject($value);
-                       if ($identifier !== NULL) {
-                               $value = $identifier;
-                       }
-               }
-               return $value;
-       }
-
-       /**
-        * Get the current property of the object bound to this form.
-        *
-        * @return mixed Value
-        * @author Bastian Waidelich <bastian@typo3.org>
-        */
-       protected function getPropertyValue() {
-               $formObject = $this->viewHelperVariableContainer->get('Tx_Fluid_ViewHelpers_FormViewHelper', 'formObject');
-               $propertyName = $this->arguments['property'];
-               if (is_array($formObject)) {
-                       return isset($formObject[$propertyName]) ? $formObject[$propertyName] : NULL;
-               }
-               return Tx_Extbase_Reflection_ObjectAccess::getProperty($formObject, $propertyName);
-       }
-
-       /**
-        * Internal method which checks if we should evaluate a domain object or just output arguments['name'] and arguments['value']
-        *
-        * @return boolean TRUE if we should evaluate the domain object, FALSE otherwise.
-        * @author Sebastian Kurfürst <sebastian@typo3.org>
-        */
-       protected function isObjectAccessorMode() {
-               return (($this->arguments['property'] !== NULL) && $this->viewHelperVariableContainer->exists('Tx_Fluid_ViewHelpers_FormViewHelper', 'formName')) ? TRUE : FALSE;
-       }
-
-
-       /**
-        * Add an CSS class if this view helper has errors
-        *
-        * @return void
-        * @author Christopher Hlubek <hlubek@networkteam.com>
-        * @author Bastian Waidelich <bastian@typo3.org>
+        * @param string $name field name to be prefixed
+        * @return string namespaced field name
         */
-       protected function setErrorClassAttribute() {
-               if ($this->arguments->hasArgument('class')) {
-                       $cssClass = $this->arguments['class'] . ' ';
-               } else {
-                       $cssClass = '';
-               }
-               $errors = $this->getErrorsForProperty();
-               if (count($errors) > 0) {
-                       if ($this->arguments->hasArgument('errorClass')) {
-                               $cssClass .= $this->arguments['errorClass'];
-                       } else {
-                               $cssClass .= 'f3-form-error';
-                       }
-                       $this->tag->addAttribute('class', $cssClass);
+       protected function prefixFieldName($fieldName) {
+               if ($fieldName === NULL || $fieldName === '') {
+                       return '';
                }
-       }
-
-       /**
-        * Get errors for the property and form name of this view helper
-        *
-        * @return array An array of Tx_Fluid_Error_Error objects
-        * @author Christopher Hlubek <hlubek@networkteam.com>
-        * @author Bastian Waidelich <bastian@typo3.org>
-        */
-       protected function getErrorsForProperty() {
-               if (!$this->arguments->hasArgument('property')) {
-                       return array();
+               $fieldNamePrefix = (string)$this->viewHelperVariableContainer->get('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix');
+               if ($fieldNamePrefix === '') {
+                       return $fieldName;
                }
-               $errors = $this->controllerContext->getRequest()->getErrors();
-               $formName = $this->viewHelperVariableContainer->get('Tx_Fluid_ViewHelpers_FormViewHelper', 'formName');
-               $propertyName = $this->arguments['property'];
-               $formErrors = array();
-               foreach ($errors as $error) {
-                       if ($error instanceof Tx_Extbase_Validation_PropertyError && $error->getPropertyName() === $formName) {
-                               $formErrors = $error->getErrors();
-                               foreach ($formErrors as $formError) {
-                                       if ($formError instanceof Tx_Extbase_Validation_PropertyError && $formError->getPropertyName() === $propertyName) {
-                                               return $formError->getErrors();
-                                       }
-                               }
-                       }
+               $fieldNameSegments = explode('[', $fieldName, 2);
+               $fieldName = $fieldNamePrefix . '[' . $fieldNameSegments[0] . ']';
+               if (count($fieldNameSegments) > 1) {
+                       $fieldName .= '[' . $fieldNameSegments[1];
                }
-               return array();
+               return $fieldName;
        }
 }
 
index fc89440..e9b0406 100644 (file)
@@ -39,7 +39,7 @@
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  * @scope prototype
  */
-class Tx_Fluid_ViewHelpers_Form_HiddenViewHelper extends Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper {
+class Tx_Fluid_ViewHelpers_Form_HiddenViewHelper extends Tx_Fluid_ViewHelpers_Form_AbstractFormFieldViewHelper {
 
        /**
         * @var string
index e48aabe..b983165 100644 (file)
@@ -64,7 +64,7 @@
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  * @scope prototype
  */
-class Tx_Fluid_ViewHelpers_Form_SelectViewHelper extends Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper {
+class Tx_Fluid_ViewHelpers_Form_SelectViewHelper extends Tx_Fluid_ViewHelpers_Form_AbstractFormFieldViewHelper {
 
        /**
         * @var string
index 5416b19..349be55 100644 (file)
@@ -37,7 +37,7 @@
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  * @scope prototype
  */
-class Tx_Fluid_ViewHelpers_Form_TextareaViewHelper extends Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper {
+class Tx_Fluid_ViewHelpers_Form_TextareaViewHelper extends Tx_Fluid_ViewHelpers_Form_AbstractFormFieldViewHelper {
 
        /**
         * @var string
index 6feff71..871979f 100644 (file)
@@ -36,7 +36,7 @@
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  * @scope prototype
  */
-class Tx_Fluid_ViewHelpers_Form_TextboxViewHelper extends Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper {
+class Tx_Fluid_ViewHelpers_Form_TextboxViewHelper extends Tx_Fluid_ViewHelpers_Form_AbstractFormFieldViewHelper {
 
        /**
         * @var string
index a9ad3e9..10f5630 100644 (file)
@@ -37,7 +37,7 @@
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  * @scope prototype
  */
-class Tx_Fluid_ViewHelpers_Form_UploadViewHelper extends Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper {
+class Tx_Fluid_ViewHelpers_Form_UploadViewHelper extends Tx_Fluid_ViewHelpers_Form_AbstractFormFieldViewHelper {
 
        /**
         * @var string
index ea7631d..51fead9 100644 (file)
@@ -70,7 +70,6 @@ class Tx_Fluid_ViewHelpers_FormViewHelper extends Tx_Fluid_ViewHelpers_Form_Abst
         * Initialize arguments.
         *
         * @return void
-        * @author Sebastian Kurfürst <sebastian@typo3.org>
         */
        public function initializeArguments() {
                $this->registerTagAttribute('enctype', 'string', 'MIME type with which the form is submitted');
@@ -94,11 +93,10 @@ class Tx_Fluid_ViewHelpers_FormViewHelper extends Tx_Fluid_ViewHelpers_Form_Abst
         * @param array $options typolink options
         * @param mixed $object Object to use for the form. Use in conjunction with the "property" attribute on the sub tags
         * @param integer $pageType Target page type
+        * @param string $fieldNamePrefix Prefix that will be added to all field names within this form. If not set the prefix will be tx_yourExtension_plugin
         * @return string rendered form
-        * @author Sebastian Kurfürst <sebastian@typo3.org>
-        * @author Bastian Waidelich <bastian@typo3.org>
         */
-       public function render($action = NULL, array $arguments = array(), $controller = NULL, $extensionName = NULL, $pluginName = NULL, $pageUid = NULL, array $options = array(), $object = NULL, $pageType = 0) {
+       public function render($action = NULL, array $arguments = array(), $controller = NULL, $extensionName = NULL, $pluginName = NULL, $pageUid = NULL, array $options = array(), $object = NULL, $pageType = 0, $prefix = NULL) {
                if ($pageUid === NULL) {
                        $pageUid = $GLOBALS['TSFE']->id;
                }
@@ -112,26 +110,18 @@ class Tx_Fluid_ViewHelpers_FormViewHelper extends Tx_Fluid_ViewHelpers_Form_Abst
                        $this->tag->addAttribute('method', 'post');
                }
 
-               if ($this->arguments['name']) {
-                       $this->viewHelperVariableContainer->add('Tx_Fluid_ViewHelpers_FormViewHelper', 'formName', $this->arguments['name']);
-               }
-               $hiddenIdentityFields = '';
-               if (!empty($object)) {
-                       $this->viewHelperVariableContainer->add('Tx_Fluid_ViewHelpers_FormViewHelper', 'formObject', $object);
-                       $hiddenIdentityFields = $this->renderHiddenIdentityField($object);
-               }
+               $this->addFormNameToViewHelperVariableContainer();
+               $this->addFormObjectToViewHelperVariableContainer();
+               $this->addFieldNamePrefixToViewHelperVariableContainer();
 
-               $content = $hiddenIdentityFields;
+               $content = $this->renderHiddenIdentityField();
                $content .= $this->renderHiddenReferrerFields();
                $content .= $this->renderChildren();
                $this->tag->setContent($content);
 
-               if (!empty($object)) {
-                       $this->viewHelperVariableContainer->remove('Tx_Fluid_ViewHelpers_FormViewHelper', 'formObject');
-               }
-               if ($this->arguments['name']) {
-                       $this->viewHelperVariableContainer->remove('Tx_Fluid_ViewHelpers_FormViewHelper', 'formName');
-               }
+               $this->removeFieldNamePrefixFromViewHelperVariableContainer();
+               $this->removeFormObjectFromViewHelperVariableContainer();
+               $this->removeFormNameFromViewHelperVariableContainer();
 
                return $this->tag->render();
        }
@@ -139,13 +129,10 @@ class Tx_Fluid_ViewHelpers_FormViewHelper extends Tx_Fluid_ViewHelpers_Form_Abst
        /**
         * Renders a hidden form field containing the technical identity of the given object.
         *
-        * @param object $object The object to create an identity field for
         * @return string A hidden field containing the Identity (UUID in FLOW3, uid in Extbase) of the given object or NULL if the object is unknown to the persistence framework
-        * @author Robert Lemke <robert@typo3.org>
-        * @author Karsten Dambekalns <karsten@typo3.org>
-        * @author Bastian Waidelich <bastian@typo3.org>
         */
-       protected function renderHiddenIdentityField($object) {
+       protected function renderHiddenIdentityField() {
+               $object = $this->arguments['object'];
                if (!is_object($object)
                        || !($object instanceof Tx_Extbase_DomainObject_AbstractDomainObject)
                        || ($object->_isNew() && !$object->_isClone())) {
@@ -154,7 +141,10 @@ class Tx_Fluid_ViewHelpers_FormViewHelper extends Tx_Fluid_ViewHelpers_Form_Abst
                // Intentionally NOT using PersistenceManager::getIdentifierByObject here!!
                // Using that one breaks re-submission of data in forms in case of an error.
                $identifier = $object->getUid();
-               return ($identifier === NULL) ? '<!-- Object of type ' . get_class($object) . ' is without identity -->' : '<input type="hidden" name="'. $this->arguments['name'] . '[uid]" value="' . $identifier .'" />';
+               if ($identifier === NULL) {
+                       return chr(10) . '<!-- Object of type ' . get_class($object) . ' is without identity -->' . chr(10);
+               }
+               return chr(10) . '<input type="hidden" name="'. $this->prefixFieldName($this->arguments['name']) . '[uid]" value="' . $identifier .'" />' . chr(10);
        }
 
        /**
@@ -168,13 +158,102 @@ class Tx_Fluid_ViewHelpers_FormViewHelper extends Tx_Fluid_ViewHelpers_Form_Abst
                $request = $this->controllerContext->getRequest();
                $extensionName = $request->getControllerExtensionName();
                $controllerName = $request->getControllerName();
-               $controllerActionName = $request->getControllerActionName();
-               $result = '';
-               foreach (array('__referrer[extensionName]' => $extensionName, '__referrer[controllerName]' => $controllerName, '__referrer[actionName]' => $controllerActionName) as $fieldName => $fieldValue) {
-                       $result .= PHP_EOL . '<input type="hidden" name="' . $fieldName . '" value="' . $fieldValue . '" />';
-               }
+               $actionName = $request->getControllerActionName();
+
+               $result = chr(10);
+               $result .= '<input type="hidden" name="' . $this->prefixFieldName('__referrer[extensionName]') . '" value="' . $extensionName . '" />' . chr(10);
+               $result .= '<input type="hidden" name="' . $this->prefixFieldName('__referrer[controllerName]') . '" value="' . $controllerName . '" />' . chr(10);
+               $result .= '<input type="hidden" name="' . $this->prefixFieldName('__referrer[actionName]') . '" value="' . $actionName . '" />' . chr(10);
                return $result;
        }
+
+       /**
+        * Adds the form name to the ViewHelperVariableContainer if the name attribute is specified.
+        *
+        * @return void
+        */
+       protected function addFormNameToViewHelperVariableContainer() {
+               if ($this->arguments->hasArgument('name')) {
+                       $this->viewHelperVariableContainer->add('Tx_Fluid_ViewHelpers_FormViewHelper', 'formName', $this->arguments['name']);
+               }
+       }
+
+       /**
+        * Removes the form name from the ViewHelperVariableContainer.
+        *
+        * @return void
+        */
+       protected function removeFormNameFromViewHelperVariableContainer() {
+               if ($this->arguments->hasArgument('name')) {
+                       $this->viewHelperVariableContainer->remove('Tx_Fluid_ViewHelpers_FormViewHelper', 'formName');
+               }
+       }
+
+       /**
+        * Adds the object that is bound to this form to the ViewHelperVariableContainer if the formObject attribute is specified.
+        *
+        * @return void
+        */
+       protected function addFormObjectToViewHelperVariableContainer() {
+               if ($this->arguments->hasArgument('object')) {
+                       $this->viewHelperVariableContainer->add('Tx_Fluid_ViewHelpers_FormViewHelper', 'formObject', $this->arguments['object']);
+               }
+       }
+
+       /**
+        * Removes the form object from the ViewHelperVariableContainer.
+        *
+        * @return void
+        */
+       protected function removeFormObjectFromViewHelperVariableContainer() {
+               if ($this->arguments->hasArgument('object')) {
+                       $this->viewHelperVariableContainer->remove('Tx_Fluid_ViewHelpers_FormViewHelper', 'formObject');
+               }
+       }
+
+       /**
+        * Adds the field name prefix to the ViewHelperVariableContainer
+        *
+        * @return void
+        */
+       protected function addFieldNamePrefixToViewHelperVariableContainer() {
+               if ($this->arguments->hasArgument('fieldNamePrefix')) {
+                       $fieldNamePrefix = $this->arguments['fieldNamePrefix'];
+               } else {
+                       $fieldNamePrefix = $this->getDefaultFieldNamePrefix();
+               }
+               $this->viewHelperVariableContainer->add('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix', $fieldNamePrefix);
+       }
+
+       /**
+        * Removes field name prefix from the ViewHelperVariableContainer
+        *
+        * @return void
+        */
+       protected function removeFieldNamePrefixFromViewHelperVariableContainer() {
+               $this->viewHelperVariableContainer->remove('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix');
+       }
+
+       /**
+        * Retrieves the default field name prefix for this form
+        *
+        * @return string default field name prefix
+        */
+       protected function getDefaultFieldNamePrefix() {
+               $request = $this->controllerContext->getRequest();
+               if ($this->arguments->hasArgument('extensionName')) {
+                       $extensionName = $this->arguments['extensionName'];
+               } else {
+                       $extensionName = $request->getControllerExtensionName();
+               }
+               if ($this->arguments->hasArgument('pluginName')) {
+                       $pluginName = $this->arguments['pluginName'];
+               } else {
+                       $pluginName = $request->getPluginName();
+               }
+
+               return 'tx_' . strtolower($extensionName) . '_' . strtolower($pluginName);
+       }
 }
 
 ?>
\ No newline at end of file
index 95fd8b9..af55078 100644 (file)
@@ -33,12 +33,13 @@ class Tx_Fluid_ViewHelpers_BaseViewHelperTest_testcase extends Tx_Fluid_ViewHelp
        public function renderTakesBaseURIFromControllerContext() {
                $baseURI = 'http://typo3.org/';
 
-               $request = $this->getMock('Tx_Extbase_MVC_Web_Request');
-               $request->expects($this->any())->method('getBaseURI')->will($this->returnValue($baseURI));
+               $this->request = $this->getMock('Tx_Extbase_MVC_Web_Request');
+               $this->request->expects($this->any())->method('getBaseURI')->will($this->returnValue($baseURI));
 
-               $this->controllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($request));
+               $this->controllerContext = $this->getMock('Tx_Extbase_MVC_Controller_ControllerContext');
+               $this->controllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
 
-               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_BaseViewHelper'), array('dummy'), array(), '', FALSE);
+               $viewHelper = new Tx_Fluid_ViewHelpers_BaseViewHelper();
                $this->injectDependenciesIntoViewHelper($viewHelper);
 
                $expected = '<base href="http://typo3.org/"></base>';
index 388cfd9..427f057 100644 (file)
@@ -18,7 +18,7 @@ require_once(dirname(__FILE__) . '/../ViewHelperBaseTestcase.php');
 /**
  * Test for the Abstract Form view helper
  *
- * @version $Id: AbstractFormViewHelperTest.php 2914 2009-07-28 18:26:38Z bwaidelich $
+ * @version $Id: AbstractFormViewHelperTest.php 2991 2009-08-06 12:09:58Z robert $
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
  */
 require_once(t3lib_extMgm::extPath('extbase', 'Tests/Base_testcase.php'));
@@ -26,280 +26,60 @@ class Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelperTest_testcase extends Tx_F
 
        /**
         * @test
-        * @author Robert Lemke <robert@typo3.org>
         * @author Bastian Waidelich <bastian@typo3.org>
         */
-       public function ifAnAttributeValueIsAnObjectMaintainedByThePersistenceManagerItIsConvertedToAUUID() {
-               $mockPersistenceBackend = $this->getMock('Tx_Extbase_Persistence_BackendInterface');
-               $mockPersistenceBackend->expects($this->any())->method('getIdentifierByObject')->will($this->returnValue('6f487e40-4483-11de-8a39-0800200c9a66'));
+       public function prefixFieldNameReturnsEmptyStringIfGivenFieldNameIsNULL() {
+               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('dummy'), array(), '', FALSE);
+               $this->injectDependenciesIntoViewHelper($viewHelper);
 
-               $mockPersistenceManager = $this->getMock('Tx_Extbase_Persistence_ManagerInterface');
-               $mockPersistenceManager->expects($this->any())->method('getBackend')->will($this->returnValue($mockPersistenceBackend));
-
-               $className = 'Object' . uniqid();
-               $fullClassName = 'Tx_Fluid_ViewHelpers_Form_' . $className;
-               eval('class ' . $className . '  {
-                       public function FLOW3_Persistence_isNew() { return FALSE; }
-                       public function FLOW3_Persistence_isDirty($propertyName) {}
-                       public function FLOW3_Persistence_memorizeCleanState($propertyName = NULL) {}
-                       public function FLOW3_AOP_Proxy_getProperty($name) {}
-                       public function FLOW3_AOP_Proxy_getProxyTargetClassName() {}
-                       public function __clone() {}
-               }');
-               $object = $this->getMock($fullClassName);
-               $object->expects($this->any())->method('FLOW3_Persistence_isNew')->will($this->returnValue(FALSE));
-
-               $formViewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('dummy'), array(), '', FALSE);
-               $formViewHelper->injectPersistenceManager($mockPersistenceManager);
-
-               // TODO mock arguments
-               $arguments = new Tx_Fluid_Core_ViewHelper_Arguments(array('name' => 'foo', 'value' => $object, 'property' => NULL));
-               $formViewHelper->_set('arguments', $arguments);
-               $formViewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(FALSE));
-
-               $this->assertSame('foo[uid]', $formViewHelper->_call('getName'));
-               $this->assertSame('6f487e40-4483-11de-8a39-0800200c9a66', $formViewHelper->_call('getValue'));
-       }
-
-       /**
-        * @test
-        * @author Sebastian Kurfürst <sebastian@typo3.org>
-        */
-       public function getNameBuildsNameFromPropertyAndFormNameIfInObjectAccessorMode() {
-               $formViewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('isObjectAccessorMode'), array(), '', FALSE);
-               $this->injectDependenciesIntoViewHelper($formViewHelper);
-
-               $formViewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
-               $this->viewHelperVariableContainer->expects($this->once())->method('get')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'formName')->will($this->returnValue('myFormName'));
-
-               $formViewHelper->_set('arguments', array('name' => NULL, 'value' => NULL, 'property' => 'bla'));
-               $expected = 'myFormName[bla]';
-               $actual = $formViewHelper->_call('getName');
-               $this->assertSame($expected, $actual);
-       }
-
-       /**
-        * @test
-        * @author Sebastian Kurfürst <sebastian@typo3.org>
-        * @author Bastian Waidelich <bastian@typo3.org>
-        */
-       public function getValueBuildsValueFromPropertyAndFormObjectIfInObjectAccessorMode() {
-               $formViewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('isObjectAccessorMode'), array(), '', FALSE);
-               $this->injectDependenciesIntoViewHelper($formViewHelper);
-
-               $className = 'test_' . uniqid();
-               $mockObject = eval('
-                       class ' . $className . ' {
-                               public function getSomething() {
-                                       return "MyString";
-                               }
-                       }
-                       return new ' . $className . ';
-               ');
-
-               $formViewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
-               $this->viewHelperVariableContainer->expects($this->once())->method('get')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'formObject')->will($this->returnValue($mockObject));
-               $this->viewHelperVariableContainer->expects($this->once())->method('exists')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'formObject')->will($this->returnValue(TRUE));
-
-               // TODO mock arguments
-               $arguments = new Tx_Fluid_Core_ViewHelper_Arguments(array('name' => NULL, 'value' => NULL, 'property' => 'something'));
-               $formViewHelper->_set('arguments', $arguments);
-               $expected = 'MyString';
-               $actual = $formViewHelper->_call('getValue');
-               $this->assertSame($expected, $actual);
-       }
-
-       /**
-        * @test
-        * @author Bastian Waidelich <bastian@typo3.org>
-        */
-       public function getValueReturnsNullIfNotInObjectAccessorModeAndValueArgumentIsNoSet() {
-               $formViewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('isObjectAccessorMode'), array(), '', FALSE);
-               $formViewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(FALSE));
-
-               $mockArguments = $this->getMock('Tx_Fluid_Core_ViewHelper_Arguments', array(), array(), '', FALSE);
-               $mockArguments->expects($this->any())->method('hasArgument')->with('value')->will($this->returnValue(FALSE));
-               $formViewHelper->_set('arguments', $mockArguments);
-
-               $this->assertNull($formViewHelper->_call('getValue'));
-       }
-
-       /**
-        * @test
-        * @author Bastian Waidelich <bastian@typo3.org>
-        */
-       public function getValueReturnsValueArgumentIfSpecified() {
-               $formViewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('isObjectAccessorMode'), array(), '', FALSE);
-               $formViewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(FALSE));
-
-               $mockArguments = $this->getMock('Tx_Fluid_Core_ViewHelper_Arguments', array(), array(), '', FALSE);
-               $mockArguments->expects($this->any())->method('hasArgument')->with('value')->will($this->returnValue(TRUE));
-               $mockArguments->expects($this->any())->method('offsetGet')->with('value')->will($this->returnValue('someValue'));
-               $formViewHelper->_set('arguments', $mockArguments);
-
-               $this->assertEquals('someValue', $formViewHelper->_call('getValue'));
-       }
-
-       /**
-        * @test
-        * @author Sebastian Kurfürst <sebastian@typo3.org>
-        */
-       public function isObjectAccessorModeReturnsTrueIfPropertyIsSetAndFormObjectIsGiven() {
-               $formViewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('dummy'), array(), '', FALSE);
-               $this->injectDependenciesIntoViewHelper($formViewHelper);
-
-               $this->viewHelperVariableContainer->expects($this->once())->method('exists')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'formName')->will($this->returnValue(TRUE));
-
-               $formViewHelper->_set('arguments', array('name' => NULL, 'value' => NULL, 'property' => 'bla'));
-               $this->assertTrue($formViewHelper->_call('isObjectAccessorMode'));
-
-               $formViewHelper->_set('arguments', array('name' => NULL, 'value' => NULL, 'property' => NULL));
-               $this->assertFalse($formViewHelper->_call('isObjectAccessorMode'));
-       }
-
-       /**
-        * @test
-        * @author Christopher Hlubek <hlubek@networkteam.com>
-        */
-       public function getErrorsForPropertyReturnsErrorsFromRequestIfPropertyIsSet() {
-               $mockRequest = $this->getMock('Tx_Extbase_MVC_Request');
-
-               $formViewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('hasArgument'), array(), '', FALSE);
-               $this->injectDependenciesIntoViewHelper($formViewHelper);
-               $mockArguments = $this->getMock('Tx_Fluid_Core_ViewHelper_Arguments', array(), array(), '', FALSE);
-               $mockArguments->expects($this->once())->method('hasArgument')->with('property')->will($this->returnValue(TRUE));
-               $mockArguments->expects($this->once())->method('offsetGet')->with('property')->will($this->returnValue('bar'));
-               $formViewHelper->_set('arguments', $mockArguments);
-               $this->viewHelperVariableContainer->expects($this->any())->method('get')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'formName')->will($this->returnValue('foo'));
-
-               $this->controllerContext->expects($this->once())->method('getRequest')->will($this->returnValue($mockRequest));
-               $mockArgumentError = $this->getMock('Tx_Extbase_MVC_Controller_ArgumentError', array(), array('foo'));
-               $mockArgumentError->expects($this->once())->method('getPropertyName')->will($this->returnValue('foo'));
-               $mockPropertyError = $this->getMock('Tx_Extbase_Validation_PropertyError', array(), array('bar'));
-               $mockPropertyError->expects($this->once())->method('getPropertyName')->will($this->returnValue('bar'));
-               $mockError = $this->getMock('Tx_Extbase_Error_Error', array(), array(), '', FALSE);
-               $mockPropertyError->expects($this->once())->method('getErrors')->will($this->returnValue(array($mockError)));
-               $mockArgumentError->expects($this->once())->method('getErrors')->will($this->returnValue(array($mockPropertyError)));
-               $mockRequest->expects($this->once())->method('getErrors')->will($this->returnValue(array($mockArgumentError)));
-
-               $errors = $formViewHelper->_call('getErrorsForProperty');
-               $this->assertEquals(array($mockError), $errors);
-       }
-
-       /**
-        * @test
-        * @author Bastian Waidelich <bastian@typo3.org>
-        */
-       public function getErrorsForPropertyReturnsEmptyArrayIfPropertyIsNotSet() {
-               $formViewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('hasArgument'), array(), '', FALSE);
-               $this->injectDependenciesIntoViewHelper($formViewHelper);
-               $mockArguments = $this->getMock('Tx_Fluid_Core_ViewHelper_Arguments', array(), array(), '', FALSE);
-               $mockArguments->expects($this->once())->method('hasArgument')->with('property')->will($this->returnValue(FALSE));
-               $formViewHelper->_set('arguments', $mockArguments);
-
-               $errors = $formViewHelper->_call('getErrorsForProperty');
-               $this->assertEquals(array(), $errors);
+               $this->assertSame('', $viewHelper->_call('prefixFieldName', NULL));
        }
 
-
        /**
         * @test
         * @author Bastian Waidelich <bastian@typo3.org>
         */
-       public function setErrorClassAttributeDoesNotSetClassAttributeIfNoErrorOccured() {
-               $formViewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('hasArgument', 'getErrorsForProperty'), array(), '', FALSE);
-               $this->injectDependenciesIntoViewHelper($formViewHelper);
-               $mockArguments = $this->getMock('Tx_Fluid_Core_ViewHelper_Arguments', array(), array(), '', FALSE);
-               $mockArguments->expects($this->once())->method('hasArgument')->with('class')->will($this->returnValue(FALSE));
-               $formViewHelper->_set('arguments', $mockArguments);
+       public function prefixFieldNameReturnsEmptyStringIfGivenFieldNameIsEmpty() {
+               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('dummy'), array(), '', FALSE);
+               $this->injectDependenciesIntoViewHelper($viewHelper);
 
-               $this->tagBuilder->expects($this->never())->method('addAttribute');
-
-               $formViewHelper->_call('setErrorClassAttribute');
+               $this->assertSame('', $viewHelper->_call('prefixFieldName', ''));
        }
 
        /**
         * @test
         * @author Bastian Waidelich <bastian@typo3.org>
         */
-       public function setErrorClassAttributeSetsErrorClassIfAnErrorOccured() {
-               $formViewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('hasArgument', 'getErrorsForProperty'), array(), '', FALSE);
-               $this->injectDependenciesIntoViewHelper($formViewHelper);
-               $mockArguments = $this->getMock('Tx_Fluid_Core_ViewHelper_Arguments', array(), array(), '', FALSE);
-               $mockArguments->expects($this->at(0))->method('hasArgument')->with('class')->will($this->returnValue(FALSE));
-               $mockArguments->expects($this->at(1))->method('hasArgument')->with('errorClass')->will($this->returnValue(FALSE));
-               $formViewHelper->_set('arguments', $mockArguments);
-
-               $mockError = $this->getMock('Tx_Extbase_Error_Error', array(), array(), '', FALSE);
-               $formViewHelper->expects($this->once())->method('getErrorsForProperty')->will($this->returnValue(array($mockError)));
+       public function prefixFieldNameReturnsGivenFieldNameIfFieldNamePrefixIsEmpty() {
+               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('dummy'), array(), '', FALSE);
+               $this->injectDependenciesIntoViewHelper($viewHelper);
+               $this->viewHelperVariableContainer->expects($this->once())->method('get')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix')->will($this->returnValue(''));
 
-               $this->tagBuilder->expects($this->once())->method('addAttribute')->with('class', 'f3-form-error');
-
-               $formViewHelper->_call('setErrorClassAttribute');
+               $this->assertSame('someFieldName', $viewHelper->_call('prefixFieldName', 'someFieldName'));
        }
 
        /**
         * @test
         * @author Bastian Waidelich <bastian@typo3.org>
         */
-       public function setErrorClassAttributeAppendsErrorClassToExistingClassesIfAnErrorOccured() {
-               $formViewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('hasArgument', 'getErrorsForProperty'), array(), '', FALSE);
-               $this->injectDependenciesIntoViewHelper($formViewHelper);
-               $mockArguments = $this->getMock('Tx_Fluid_Core_ViewHelper_Arguments', array(), array(), '', FALSE);
-               $mockArguments->expects($this->at(0))->method('hasArgument')->with('class')->will($this->returnValue(TRUE));
-               $mockArguments->expects($this->at(1))->method('offsetGet')->with('class')->will($this->returnValue('default classes'));
-               $mockArguments->expects($this->at(2))->method('hasArgument')->with('errorClass')->will($this->returnValue(FALSE));
-               $formViewHelper->_set('arguments', $mockArguments);
-
-               $mockError = $this->getMock('Tx_Extbase_Error_Error', array(), array(), '', FALSE);
-               $formViewHelper->expects($this->once())->method('getErrorsForProperty')->will($this->returnValue(array($mockError)));
-
-               $this->tagBuilder->expects($this->once())->method('addAttribute')->with('class', 'default classes f3-form-error');
+       public function prefixFieldNamePrefixesGivenFieldNameWithFieldNamePrefix() {
+               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('dummy'), array(), '', FALSE);
+               $this->injectDependenciesIntoViewHelper($viewHelper);
+               $this->viewHelperVariableContainer->expects($this->once())->method('get')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix')->will($this->returnValue('somePrefix'));
 
-               $formViewHelper->_call('setErrorClassAttribute');
+               $this->assertSame('somePrefix[someFieldName]', $viewHelper->_call('prefixFieldName', 'someFieldName'));
        }
 
        /**
         * @test
         * @author Bastian Waidelich <bastian@typo3.org>
         */
-       public function setErrorClassAttributeSetsCustomErrorClassIfAnErrorOccured() {
-               $formViewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('hasArgument', 'getErrorsForProperty'), array(), '', FALSE);
-               $this->injectDependenciesIntoViewHelper($formViewHelper);
-               $mockArguments = $this->getMock('Tx_Fluid_Core_ViewHelper_Arguments', array(), array(), '', FALSE);
-               $mockArguments->expects($this->at(0))->method('hasArgument')->with('class')->will($this->returnValue(FALSE));
-               $mockArguments->expects($this->at(1))->method('hasArgument')->with('errorClass')->will($this->returnValue(TRUE));
-               $mockArguments->expects($this->at(2))->method('offsetGet')->with('errorClass')->will($this->returnValue('custom-error-class'));
-               $formViewHelper->_set('arguments', $mockArguments);
-
-               $mockError = $this->getMock('Tx_Extbase_Error_Error', array(), array(), '', FALSE);
-               $formViewHelper->expects($this->once())->method('getErrorsForProperty')->will($this->returnValue(array($mockError)));
-
-               $this->tagBuilder->expects($this->once())->method('addAttribute')->with('class', 'custom-error-class');
-
-               $formViewHelper->_call('setErrorClassAttribute');
-       }
-
-       /**
-        * @test
-        * @author Bastian Waidelich <bastian@typo3.org>
-        */
-       public function setErrorClassAttributeAppendsCustomErrorClassIfAnErrorOccured() {
-               $formViewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('hasArgument', 'getErrorsForProperty'), array(), '', FALSE);
-               $this->injectDependenciesIntoViewHelper($formViewHelper);
-               $mockArguments = $this->getMock('Tx_Fluid_Core_ViewHelper_Arguments', array(), array(), '', FALSE);
-               $mockArguments->expects($this->at(0))->method('hasArgument')->with('class')->will($this->returnValue(TRUE));
-               $mockArguments->expects($this->at(1))->method('offsetGet')->with('class')->will($this->returnValue('default classes'));
-               $mockArguments->expects($this->at(2))->method('hasArgument')->with('errorClass')->will($this->returnValue(TRUE));
-               $mockArguments->expects($this->at(3))->method('offsetGet')->with('errorClass')->will($this->returnValue('custom-error-class'));
-               $formViewHelper->_set('arguments', $mockArguments);
-
-               $mockError = $this->getMock('Tx_Extbase_Error_Error', array(), array(), '', FALSE);
-               $formViewHelper->expects($this->once())->method('getErrorsForProperty')->will($this->returnValue(array($mockError)));
-
-               $this->tagBuilder->expects($this->once())->method('addAttribute')->with('class', 'default classes custom-error-class');
+       public function prefixFieldNamePreservesSquareBracketsOfFieldName() {
+               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('dummy'), array(), '', FALSE);
+               $this->injectDependenciesIntoViewHelper($viewHelper);
+               $this->viewHelperVariableContainer->expects($this->once())->method('get')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix')->will($this->returnValue('somePrefix[foo]'));
 
-               $formViewHelper->_call('setErrorClassAttribute');
+               $this->assertSame('somePrefix[foo][someFieldName][bar]', $viewHelper->_call('prefixFieldName', 'someFieldName[bar]'));
        }
 }
 
index 946d82d..d064963 100644 (file)
@@ -38,9 +38,7 @@ class Tx_Fluid_ViewHelpers_Form_ErrorsViewHelperTest_testcase extends Tx_Fluid_V
        public function renderWithoutSpecifiedNameLoopsThroughRootErrors() {
                $mockError1 = $this->getMock('Tx_Extbase_Error_Error', array(), array(), '', FALSE);
                $mockError2 = $this->getMock('Tx_Extbase_Error_Error', array(), array(), '', FALSE);
-               $mockRequest = $this->getMock('Tx_Extbase_MVC_Request');
-               $mockRequest->expects($this->atLeastOnce())->method('getErrors')->will($this->returnValue(array($mockError1, $mockError2)));
-               $this->controllerContext->expects($this->atLeastOnce())->method('getRequest')->will($this->returnValue($mockRequest));
+               $this->request->expects($this->atLeastOnce())->method('getErrors')->will($this->returnValue(array($mockError1, $mockError2)));
 
                $viewHelper = new Tx_Fluid_ViewHelpers_Form_ErrorsViewHelper();
                $this->injectDependenciesIntoViewHelper($viewHelper);
index 27e4a7a..c8c22ac 100644 (file)
@@ -189,9 +189,9 @@ class Tx_Fluid_ViewHelpers_Form_SelectViewHelperTest_testcase extends Tx_Fluid_V
         * @test
         * @author Karsten Dambekalns <karsten@typo3.org>
         */
-       public function selectWithoutFurtherConfigurationOnDomainObjectsUsesUUIDForValueAndLabel() {
+       public function selectWithoutFurtherConfigurationOnDomainObjectsUsesUIDForValueAndLabel() {
                $mockPersistenceBackend = $this->getMock('Tx_Extbase_Persistence_BackendInterface');
-               $mockPersistenceBackend->expects($this->any())->method('getIdentifierByObject')->will($this->returnValue('fakeUUID'));
+               $mockPersistenceBackend->expects($this->any())->method('getIdentifierByObject')->will($this->returnValue('fakeUID'));
 
                $mockPersistenceManager = $this->getMock('Tx_Extbase_Persistence_ManagerInterface');
                $mockPersistenceManager->expects($this->any())->method('getBackend')->will($this->returnValue($mockPersistenceBackend));
@@ -199,7 +199,7 @@ class Tx_Fluid_ViewHelpers_Form_SelectViewHelperTest_testcase extends Tx_Fluid_V
 
                $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('addAttribute', 'setContent', 'render'), array(), '', FALSE);
                $mockTagBuilder->expects($this->once())->method('addAttribute')->with('name', 'myName');
-               $mockTagBuilder->expects($this->once())->method('setContent')->with('<option value="fakeUUID">fakeUUID</option>' . chr(10));
+               $mockTagBuilder->expects($this->once())->method('setContent')->with('<option value="fakeUID">fakeUID</option>' . chr(10));
                $mockTagBuilder->expects($this->once())->method('render');
                $this->viewHelper->injectTagBuilder($mockTagBuilder);
 
@@ -223,7 +223,7 @@ class Tx_Fluid_ViewHelpers_Form_SelectViewHelperTest_testcase extends Tx_Fluid_V
         */
        public function selectWithoutFurtherConfigurationOnDomainObjectsUsesToStringForLabelIfAvailable() {
                $mockPersistenceBackend = $this->getMock('Tx_Extbase_Persistence_BackendInterface');
-               $mockPersistenceBackend->expects($this->any())->method('getIdentifierByObject')->will($this->returnValue('fakeUUID'));
+               $mockPersistenceBackend->expects($this->any())->method('getIdentifierByObject')->will($this->returnValue('fakeUID'));
 
                $mockPersistenceManager = $this->getMock('Tx_Extbase_Persistence_ManagerInterface');
                $mockPersistenceManager->expects($this->any())->method('getBackend')->will($this->returnValue($mockPersistenceBackend));
@@ -231,7 +231,7 @@ class Tx_Fluid_ViewHelpers_Form_SelectViewHelperTest_testcase extends Tx_Fluid_V
 
                $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('addAttribute', 'setContent', 'render'), array(), '', FALSE);
                $mockTagBuilder->expects($this->once())->method('addAttribute')->with('name', 'myName');
-               $mockTagBuilder->expects($this->once())->method('setContent')->with('<option value="fakeUUID">toStringResult</option>' . chr(10));
+               $mockTagBuilder->expects($this->once())->method('setContent')->with('<option value="fakeUID">toStringResult</option>' . chr(10));
                $mockTagBuilder->expects($this->once())->method('render');
                $this->viewHelper->injectTagBuilder($mockTagBuilder);
 
index 05016b2..78acd60 100644 (file)
@@ -33,24 +33,60 @@ class Tx_Fluid_ViewHelpers_FormViewHelperTest_testcase extends Tx_Fluid_ViewHelp
 
        /**
         * @test
-        * @author Robert Lemke <robert@typo3.org>
+        * @author Bastian Waidelich <bastian@typo3.org>
         */
-       public function renderHiddenIdentityFieldReturnsAHiddenInputFieldContainingTheObjectsUUID() {
-               $object = new stdClass();
+       public function renderHiddenIdentityFieldReturnsAHiddenInputFieldContainingTheObjectsUID() {
+               $object = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_DomainObject_AbstractDomainObject'), array('_isNew'));
+               $object->_set('uid', '123');
+               $object->expects($this->once())->method('_isNew')->will($this->returnValue(FALSE));
 
-               $mockBackend = $this->getMock('Tx_Extbase_Persistence_BackendInterface');
-               $mockBackend->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue('123'));
+               $expectedResult = chr(10) . '<input type="hidden" name="prefix[theName][uid]" value="123" />' . chr(10);
 
-               $mockPersistenceManager = $this->getMock('Tx_Extbase_Persistence_ManagerInterface');
-               $mockPersistenceManager->expects($this->any())->method('getBackend')->will($this->returnValue($mockBackend));
+               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_FormViewHelper'), array('prefixFieldName'), array(), '', FALSE);
+               $this->injectDependenciesIntoViewHelper($viewHelper);
+               $viewHelper->setArguments(new Tx_Fluid_Core_ViewHelper_Arguments(array('name' => 'theName', 'object' => $object)));
+               $viewHelper->expects($this->any())->method('prefixFieldName')->with('theName')->will($this->returnValue('prefix[theName]'));
 
-               $expectedResult = '<input type="hidden" name="theName[uid]" value="123" />';
+               $actualResult = $viewHelper->_call('renderHiddenIdentityField');
+               $this->assertSame($expectedResult, $actualResult);
+       }
 
-               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_FormViewHelper'), array('dummy'), array(), '', FALSE);
-               $viewHelper->setArguments(new Tx_Fluid_Core_ViewHelper_Arguments(array('name' => 'theName')));
-               $viewHelper->_set('persistenceManager', $mockPersistenceManager);
+       /**
+        * @test
+        * @author Bastian Waidelich <bastian@typo3.org>
+        */
+       public function renderHiddenIdentityFieldReturnsAHiddenInputFieldIfObjectIsNewButAClone() {
+               $object = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_DomainObject_AbstractDomainObject'), array('_isNew', '_isClone'));
+               $object->_set('uid', '123');
+               $object->expects($this->once())->method('_isNew')->will($this->returnValue(TRUE));
+               $object->expects($this->once())->method('_isClone')->will($this->returnValue(TRUE));
+
+               $expectedResult = chr(10) . '<input type="hidden" name="prefix[theName][uid]" value="123" />' . chr(10);
+
+               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_FormViewHelper'), array('prefixFieldName'), array(), '', FALSE);
+               $this->injectDependenciesIntoViewHelper($viewHelper);
+               $viewHelper->setArguments(new Tx_Fluid_Core_ViewHelper_Arguments(array('name' => 'theName', 'object' => $object)));
+               $viewHelper->expects($this->any())->method('prefixFieldName')->with('theName')->will($this->returnValue('prefix[theName]'));
 
-               $actualResult = $viewHelper->_call('renderHiddenIdentityField', $object);
+               $actualResult = $viewHelper->_call('renderHiddenIdentityField');
+               $this->assertSame($expectedResult, $actualResult);
+       }
+
+       /**
+        * @test
+        * @author Bastian Waidelich <bastian@typo3.org>
+        */
+       public function renderHiddenIdentityFieldReturnsACommentIfTheObjectIsWithoutIdentity() {
+               $object = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_DomainObject_AbstractDomainObject'), array('_isNew'));
+               $object->expects($this->once())->method('_isNew')->will($this->returnValue(FALSE));
+
+               $expectedResult = chr(10) . '<!-- Object of type ' . get_class($object) . ' is without identity -->' . chr(10);
+
+               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_FormViewHelper'), array('prefixFieldName'), array(), '', FALSE);
+               $this->injectDependenciesIntoViewHelper($viewHelper);
+               $viewHelper->setArguments(new Tx_Fluid_Core_ViewHelper_Arguments(array('name' => 'theName', 'object' => $object)));
+
+               $actualResult = $viewHelper->_call('renderHiddenIdentityField');
                $this->assertSame($expectedResult, $actualResult);
        }
 
@@ -61,13 +97,13 @@ class Tx_Fluid_ViewHelpers_FormViewHelperTest_testcase extends Tx_Fluid_ViewHelp
        public function renderAddsObjectToTemplateVariableContainer() {
                $formObject = new stdClass();
 
-               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_FormViewHelper'), array('renderChildren', 'renderHiddenIdentityField', 'renderHiddenReferrerFields'), array(), '', FALSE);
+               $viewHelper = $this->getMock('Tx_Fluid_ViewHelpers_FormViewHelper', array('renderChildren', 'renderHiddenIdentityField', 'renderHiddenReferrerFields', 'addFormNameToViewHelperVariableContainer', 'addFieldNamePrefixToViewHelperVariableContainer', 'removeFormNameFromViewHelperVariableContainer', 'removeFieldNamePrefixFromViewHelperVariableContainer'));
                $this->injectDependenciesIntoViewHelper($viewHelper);
 
-
+               $viewHelper->setArguments(new Tx_Fluid_Core_ViewHelper_Arguments(array('object' => $formObject)));
                $this->viewHelperVariableContainer->expects($this->once())->method('add')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'formObject', $formObject);
                $this->viewHelperVariableContainer->expects($this->once())->method('remove')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'formObject');
-               $viewHelper->render(NULL, array(), NULL, NULL, NULL, NULL, array(), $formObject);
+               $viewHelper->render();
        }
 
        /**
@@ -77,14 +113,14 @@ class Tx_Fluid_ViewHelpers_FormViewHelperTest_testcase extends Tx_Fluid_ViewHelp
        public function renderAddsFormNameToTemplateVariableContainer() {
                $formName = 'someFormName';
 
-               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_FormViewHelper'), array('renderChildren', 'renderHiddenIdentityField', 'renderHiddenReferrerFields'), array(), '', FALSE);
+               $viewHelper = $this->getMock('Tx_Fluid_ViewHelpers_FormViewHelper', array('renderChildren', 'renderHiddenIdentityField', 'renderHiddenReferrerFields', 'addFormObjectToViewHelperVariableContainer', 'addFieldNamePrefixToViewHelperVariableContainer', 'removeFormObjectFromViewHelperVariableContainer', 'removeFieldNamePrefixFromViewHelperVariableContainer'));
                $this->injectDependenciesIntoViewHelper($viewHelper);
 
                $viewHelper->setArguments(new Tx_Fluid_Core_ViewHelper_Arguments(array('name' => $formName)));
 
                $this->viewHelperVariableContainer->expects($this->once())->method('add')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'formName', $formName);
                $this->viewHelperVariableContainer->expects($this->once())->method('remove')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'formName');
-               $viewHelper->render('', array(), NULL, NULL, NULL, NULL);
+               $viewHelper->render();
        }
 
        /**
@@ -92,11 +128,11 @@ class Tx_Fluid_ViewHelpers_FormViewHelperTest_testcase extends Tx_Fluid_ViewHelp
         * @author Christopher Hlubek <hlubek@networkteam.com>
         */
        public function renderCallsRenderHiddenReferrerFields() {
-               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_FormViewHelper'), array('renderChildren', 'renderHiddenReferrerFields'), array(), '', FALSE);
+               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_FormViewHelper'), array('renderChildren', 'renderHiddenReferrerFields'));
                $viewHelper->expects($this->once())->method('renderHiddenReferrerFields');
                $this->injectDependenciesIntoViewHelper($viewHelper);
 
-               $viewHelper->render('', array(), NULL, NULL, NULL, NULL);
+               $viewHelper->render();
        }
 
        /**
@@ -105,21 +141,129 @@ class Tx_Fluid_ViewHelpers_FormViewHelperTest_testcase extends Tx_Fluid_ViewHelp
         * @author Bastian Waidelich <bastian@typo3.org>
         */
        public function renderHiddenReferrerFieldsAddCurrentControllerAndActionAsHiddenFields() {
-               $mockRequest = $this->getMock('Tx_Extbase_MVC_Request');
-               $this->controllerContext->expects($this->atLeastOnce())->method('getRequest')->will($this->returnValue($mockRequest));
-
                $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_FormViewHelper'), array('dummy'), array(), '', FALSE);
                $this->injectDependenciesIntoViewHelper($viewHelper);
 
-               $mockRequest->expects($this->atLeastOnce())->method('getControllerExtensionName')->will($this->returnValue('extensionName'));
-               $mockRequest->expects($this->atLeastOnce())->method('getControllerName')->will($this->returnValue('controllerName'));
-               $mockRequest->expects($this->atLeastOnce())->method('getControllerActionName')->will($this->returnValue('controllerActionName'));
+               $this->request->expects($this->atLeastOnce())->method('getControllerExtensionName')->will($this->returnValue('extensionName'));
+               $this->request->expects($this->atLeastOnce())->method('getControllerName')->will($this->returnValue('controllerName'));
+               $this->request->expects($this->atLeastOnce())->method('getControllerActionName')->will($this->returnValue('controllerActionName'));
 
                $hiddenFields = $viewHelper->_call('renderHiddenReferrerFields');
-               $expectedResult = PHP_EOL . '<input type="hidden" name="__referrer[extensionName]" value="extensionName" />' . PHP_EOL .
-                       '<input type="hidden" name="__referrer[controllerName]" value="controllerName" />' . PHP_EOL .
-                       '<input type="hidden" name="__referrer[actionName]" value="controllerActionName" />';
+               $expectedResult = chr(10) . '<input type="hidden" name="__referrer[extensionName]" value="extensionName" />' . chr(10) .
+                       '<input type="hidden" name="__referrer[controllerName]" value="controllerName" />' . chr(10) .
+                       '<input type="hidden" name="__referrer[actionName]" value="controllerActionName" />' . chr(10);
                $this->assertEquals($expectedResult, $hiddenFields);
        }
+
+       /**
+        * @test
+        * @author Bastian Waidelich <bastian@typo3.org>
+        */
+       public function renderAddsSpecifiedPrefixToTemplateVariableContainer() {
+               $prefix = 'somePrefix';
+
+               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_FormViewHelper'), array('renderChildren', 'renderHiddenIdentityField', 'renderHiddenReferrerFields'), array(), '', FALSE);
+               $this->injectDependenciesIntoViewHelper($viewHelper);
+
+               $viewHelper->setArguments(new Tx_Fluid_Core_ViewHelper_Arguments(array('fieldNamePrefix' => $prefix)));
+
+               $this->viewHelperVariableContainer->expects($this->once())->method('add')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix', $prefix);
+               $this->viewHelperVariableContainer->expects($this->once())->method('remove')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix');
+               $viewHelper->render();
+       }
+
+       /**
+        * @test
+        * @author Bastian Waidelich <bastian@typo3.org>
+        */
+       public function renderAddsExtensionPrefixToTemplateVariableContainerIfNoPrefixIsSpecified() {
+               $expectedPrefix = 'tx_someextension_someplugin';
+
+               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_FormViewHelper'), array('renderChildren', 'renderHiddenIdentityField', 'renderHiddenReferrerFields'), array(), '', FALSE);
+               $this->injectDependenciesIntoViewHelper($viewHelper);
+
+               $viewHelper->setArguments(
+                       new Tx_Fluid_Core_ViewHelper_Arguments(
+                               array(
+                                       'extensionName' => 'someExtension',
+                                       'pluginName' => 'somePlugin',
+                               )
+                       )
+               );
+
+               $this->viewHelperVariableContainer->expects($this->once())->method('add')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix', $expectedPrefix);
+               $this->viewHelperVariableContainer->expects($this->once())->method('remove')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix');
+               $viewHelper->render();
+       }
+
+       /**
+        * @test
+        * @author Bastian Waidelich <bastian@typo3.org>
+        */
+       public function renderUsesCurrentExtensionNameForExtensionPrefixIfNoPrefixAndNoExtensionNameIsSpecified() {
+               $expectedPrefix = 'tx_currentextensionname_someplugin';
+
+               $this->request->expects($this->atLeastOnce())->method('getControllerExtensionName')->will($this->returnValue('currentExtensionName'));
+
+               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_FormViewHelper'), array('renderChildren', 'renderHiddenIdentityField', 'renderHiddenReferrerFields'), array(), '', FALSE);
+               $this->injectDependenciesIntoViewHelper($viewHelper);
+
+               $viewHelper->setArguments(
+                       new Tx_Fluid_Core_ViewHelper_Arguments(
+                               array(
+                                       'pluginName' => 'somePlugin',
+                               )
+                       )
+               );
+
+               $this->viewHelperVariableContainer->expects($this->once())->method('add')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix', $expectedPrefix);
+               $this->viewHelperVariableContainer->expects($this->once())->method('remove')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix');
+               $viewHelper->render();
+       }
+
+       /**
+        * @test
+        * @author Bastian Waidelich <bastian@typo3.org>
+        */
+       public function renderUsesCurrentPluginNameForExtensionPrefixIfNoPrefixAndNoPluginNameIsSpecified() {
+               $expectedPrefix = 'tx_someextension_currentpluginname';
+
+               $this->request->expects($this->atLeastOnce())->method('getPluginName')->will($this->returnValue('currentPluginName'));
+
+               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_FormViewHelper'), array('renderChildren', 'renderHiddenIdentityField', 'renderHiddenReferrerFields'), array(), '', FALSE);
+               $this->injectDependenciesIntoViewHelper($viewHelper);
+
+               $viewHelper->setArguments(
+                       new Tx_Fluid_Core_ViewHelper_Arguments(
+                               array(
+                                       'extensionName' => 'someExtension',
+                               )
+                       )
+               );
+
+               $this->viewHelperVariableContainer->expects($this->once())->method('add')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix', $expectedPrefix);
+               $this->viewHelperVariableContainer->expects($this->once())->method('remove')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix');
+               $viewHelper->render();
+       }
+
+       /**
+        * @test
+        * @author Bastian Waidelich <bastian@typo3.org>
+        */
+       public function renderUsesCurrentExtensionNameAndCurrentPluginNameForExtensionPrefixIfNoPrefixAndNoExtensionNameAndNoPluginNameIsSpecified() {
+               $expectedPrefix = 'tx_currentextensionname_currentpluginname';
+
+               $this->request->expects($this->atLeastOnce())->method('getControllerExtensionName')->will($this->returnValue('currentExtensionName'));
+               $this->request->expects($this->atLeastOnce())->method('getPluginName')->will($this->returnValue('currentPluginName'));
+
+               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_FormViewHelper'), array('renderChildren', 'renderHiddenIdentityField', 'renderHiddenReferrerFields'), array(), '', FALSE);
+               $this->injectDependenciesIntoViewHelper($viewHelper);
+
+               $viewHelper->setArguments(new Tx_Fluid_Core_ViewHelper_Arguments(array()));
+
+               $this->viewHelperVariableContainer->expects($this->once())->method('add')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix', $expectedPrefix);
+               $this->viewHelperVariableContainer->expects($this->once())->method('remove')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix');
+               $viewHelper->render();
+       }
 }
 ?>
\ No newline at end of file
index bf3d040..b97ec20 100644 (file)
@@ -56,6 +56,11 @@ abstract class Tx_Fluid_ViewHelpers_ViewHelperBaseTestcase extends Tx_Extbase_Ba
        protected $arguments;
 
        /**
+        * @var \Tx_Extbase_MVC_Request
+        */
+       protected $request;
+
+       /**
         * @return void
         * @author Sebastian Kurfürst <sebastian@typo3.org>
         */
@@ -63,8 +68,10 @@ abstract class Tx_Fluid_ViewHelpers_ViewHelperBaseTestcase extends Tx_Extbase_Ba
                $this->viewHelperVariableContainer = $this->getMock('Tx_Fluid_Core_ViewHelper_ViewHelperVariableContainer');
                $this->templateVariableContainer = $this->getMock('Tx_Fluid_Core_ViewHelper_TemplateVariableContainer');
                $this->uriBuilder = $this->getMock('Tx_Extbase_MVC_Web_Routing_URIBuilder');
+               $this->request = $this->getMock('Tx_Extbase_MVC_Request');
                $this->controllerContext = $this->getMock('Tx_Extbase_MVC_Controller_ControllerContext');
                $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->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder');
                $this->arguments = $this->getMock('Tx_Fluid_Core_ViewHelper_Arguments', array(), array(), '', FALSE);
        }
index b489b57..e96ca44 100644 (file)
@@ -49,6 +49,7 @@ return array(
        'tx_fluid_viewhelpers_imageviewhelper' => $extensionClassesPath . 'ViewHelpers/ImageViewHelper.php',
        'tx_fluid_viewhelpers_thenviewhelper' => $extensionClassesPath . 'ViewHelpers/ThenViewHelper.php',
        'tx_fluid_viewhelpers_translateviewhelper' => $extensionClassesPath . 'ViewHelpers/TranslateViewHelper.php',
+       'tx_fluid_viewhelpers_form_abstractformfieldviewhelper' => $extensionClassesPath . 'ViewHelpers/Form/AbstractFormFieldViewHelper.php',
        'tx_fluid_viewhelpers_form_abstractformviewhelper' => $extensionClassesPath . 'ViewHelpers/Form/AbstractFormViewHelper.php',
        'tx_fluid_viewhelpers_form_errorsviewhelper' => $extensionClassesPath . 'ViewHelpers/Form/ErrorsViewHelper.php',
        'tx_fluid_viewhelpers_form_hiddenviewhelper' => $extensionClassesPath . 'ViewHelpers/Form/HiddenViewHelper.php',