diff --git a/CHANGELOG.md b/CHANGELOG.md index c265c4a..75ea67c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,38 @@ # ![FormZ](Documentation/Images/formz-icon@medium.png) FormZ - Changelog +1.1.1 - 2017-06-12 +------------------ + +Contains two bug-fixes: + +- **[[e225096](https://github.com/romm/formz/commit/e2250962f9ae92b5fa00876217e59d7f6a649f7a)] [BUGFIX] Fix nested field layouts not properly rendered** + + This commit allows several field layouts level: a field rendered with the field view helper can now render another field within its slots. + + Example: + + ``` + + + Bacon ipsum dolor... + + + ... + + + + ``` + +- **[[7da753a](https://github.com/romm/formz/commit/7da753ac0e7115dc84a5a964884051ca5c91ca84)] [BUGFIX] Fix layout/partial root paths not merged in field layouts** + + This commit fixes the situation where a slot in a field layout tries to use a partial from the actual rendering context: until now only the partials configured in the FormZ view TypoScript configuration were supported, resulting in a fatal error. + + The paths are now merged together, giving access to both of them. + + The same behaviour is done for layouts. + +- **[[9be619c](https://github.com/romm/formz/commit/9be619cf5ebdf567404203aaa748a066d413cc05)] [TASK] Mark form validation data functions as deprecated** + 1.1.0 - 2017-04-08 ------------------ diff --git a/Classes/Form/FormInterface.php b/Classes/Form/FormInterface.php index 39bc9c4..6c2dc63 100644 --- a/Classes/Form/FormInterface.php +++ b/Classes/Form/FormInterface.php @@ -25,14 +25,17 @@ */ interface FormInterface { - /** + * @deprecated This method is deprecated and will be deleted in FormZ v2. + * * @param string $key * @return array */ public function getValidationData($key = null); /** + * @deprecated This method is deprecated and will be deleted in FormZ v2. + * * @param array $validationData * @internal */ diff --git a/Classes/Form/FormTrait.php b/Classes/Form/FormTrait.php index 9f99a15..95624f4 100644 --- a/Classes/Form/FormTrait.php +++ b/Classes/Form/FormTrait.php @@ -13,6 +13,8 @@ namespace Romm\Formz\Form; +use TYPO3\CMS\Core\Utility\GeneralUtility; + /** * This trait should be used by default to implement all the functions required * by the interface `FormInterface`. @@ -22,7 +24,6 @@ */ trait FormTrait { - /** * Contains the optional data returned from the validators of each field. * @@ -31,11 +32,15 @@ trait FormTrait protected $validationData = []; /** + * @deprecated This method is deprecated and will be deleted in FormZ v2. + * * @param string $key * @return array */ public function getValidationData($key = null) { + GeneralUtility::logDeprecatedFunction(); + $result = $this->validationData; if (null !== $key) { @@ -48,11 +53,15 @@ public function getValidationData($key = null) } /** + * @deprecated This method is deprecated and will be deleted in FormZ v2. + * * @param array $validationData * @internal */ public function setValidationData(array $validationData) { + GeneralUtility::logDeprecatedFunction(); + $this->validationData = $validationData; } } diff --git a/Classes/Service/ViewHelper/Field/FieldContextEntry.php b/Classes/Service/ViewHelper/Field/FieldContextEntry.php new file mode 100644 index 0000000..df356e2 --- /dev/null +++ b/Classes/Service/ViewHelper/Field/FieldContextEntry.php @@ -0,0 +1,62 @@ + + * + * This file is part of the TYPO3 FormZ project. + * It is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License, either + * version 3 of the License, or any later version. + * + * For the full copyright and license information, see: + * http://www.gnu.org/licenses/gpl-3.0.html + */ + +namespace Romm\Formz\Service\ViewHelper\Field; + +use Romm\Formz\Configuration\Form\Field\Field; + +class FieldContextEntry +{ + /** + * @var Field + */ + protected $field; + + /** + * @var array + */ + protected $options = []; + + /** + * @param Field $field + */ + public function __construct(Field $field) + { + $this->field = $field; + } + + /** + * @return Field|null + */ + public function getField() + { + return $this->field; + } + + /** + * @param string $name + * @param mixed $value + */ + public function setOption($name, $value) + { + $this->options[$name] = $value; + } + + /** + * @return array + */ + public function getOptions() + { + return $this->options; + } +} diff --git a/Classes/Service/ViewHelper/FieldViewHelperService.php b/Classes/Service/ViewHelper/Field/FieldViewHelperService.php similarity index 64% rename from Classes/Service/ViewHelper/FieldViewHelperService.php rename to Classes/Service/ViewHelper/Field/FieldViewHelperService.php index 8a9d077..5543760 100644 --- a/Classes/Service/ViewHelper/FieldViewHelperService.php +++ b/Classes/Service/ViewHelper/Field/FieldViewHelperService.php @@ -11,12 +11,13 @@ * http://www.gnu.org/licenses/gpl-3.0.html */ -namespace Romm\Formz\Service\ViewHelper; +namespace Romm\Formz\Service\ViewHelper\Field; use Romm\Formz\Configuration\Form\Field\Field; use Romm\Formz\Configuration\View\Layouts\Layout; use Romm\Formz\Core\Core; use TYPO3\CMS\Core\SingletonInterface; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\StandaloneView; /** @@ -26,14 +27,13 @@ class FieldViewHelperService implements SingletonInterface { /** - * @var Field - */ - protected $currentField; - - /** - * @var array + * Contains all current fields being rendered by FormZ: if a field is + * rendered beneath another field, several entries will be added to this + * property. + * + * @var FieldContextEntry[] */ - protected $fieldOptions = []; + protected $contextEntries; /** * @var StandaloneView[] @@ -41,43 +41,41 @@ class FieldViewHelperService implements SingletonInterface protected $view; /** - * Reset every state that can be used by this service. + * Adds a new context entry to the entries array. The other field-related + * methods will be processed on this entry until the field rendering has + * ended. + * + * @param Field $field */ - public function resetState() + public function setCurrentField(Field $field) { - $this->currentField = null; - $this->fieldOptions = []; + $this->contextEntries[] = GeneralUtility::makeInstance(FieldContextEntry::class, $field); } /** - * Checks that the `FieldViewHelper` has been called. If not, an exception - * is thrown. - * - * @return bool + * Removes the current field context entry. */ - public function fieldContextExists() + public function removeCurrentField() { - return $this->currentField instanceof Field; + array_pop($this->contextEntries); } /** - * Returns the current field which was defined by the `FieldViewHelper`. - * - * Returns null if no current field was found. + * Checks that a field context is found. * - * @return Field|null + * @return bool */ - public function getCurrentField() + public function fieldContextExists() { - return $this->currentField; + return false === empty($this->contextEntries); } /** - * @param Field $field + * @return Field */ - public function setCurrentField(Field $field) + public function getCurrentField() { - $this->currentField = $field; + return $this->getCurrentContext()->getField(); } /** @@ -86,7 +84,7 @@ public function setCurrentField(Field $field) */ public function setFieldOption($name, $value) { - $this->fieldOptions[$name] = $value; + $this->getCurrentContext()->setOption($name, $value); } /** @@ -94,7 +92,7 @@ public function setFieldOption($name, $value) */ public function getFieldOptions() { - return $this->fieldOptions; + return $this->getCurrentContext()->getOptions(); } /** @@ -119,4 +117,12 @@ public function getView(Layout $layout) return $this->view[$identifier]; } + + /** + * @return FieldContextEntry + */ + protected function getCurrentContext() + { + return end($this->contextEntries); + } } diff --git a/Classes/Service/ViewHelper/FormViewHelperService.php b/Classes/Service/ViewHelper/Form/FormViewHelperService.php similarity index 98% rename from Classes/Service/ViewHelper/FormViewHelperService.php rename to Classes/Service/ViewHelper/Form/FormViewHelperService.php index 4055b60..22c192b 100644 --- a/Classes/Service/ViewHelper/FormViewHelperService.php +++ b/Classes/Service/ViewHelper/Form/FormViewHelperService.php @@ -11,7 +11,7 @@ * http://www.gnu.org/licenses/gpl-3.0.html */ -namespace Romm\Formz\Service\ViewHelper; +namespace Romm\Formz\Service\ViewHelper\Form; use Romm\Formz\Behaviours\BehavioursManager; use Romm\Formz\Exceptions\DuplicateEntryException; diff --git a/Classes/Service/ViewHelper/SlotViewHelperService.php b/Classes/Service/ViewHelper/Slot/SlotContextEntry.php similarity index 71% rename from Classes/Service/ViewHelper/SlotViewHelperService.php rename to Classes/Service/ViewHelper/Slot/SlotContextEntry.php index ebb7843..d95b907 100644 --- a/Classes/Service/ViewHelper/SlotViewHelperService.php +++ b/Classes/Service/ViewHelper/Slot/SlotContextEntry.php @@ -11,59 +11,63 @@ * http://www.gnu.org/licenses/gpl-3.0.html */ -namespace Romm\Formz\Service\ViewHelper; +namespace Romm\Formz\Service\ViewHelper\Slot; use Closure; use Romm\Formz\Exceptions\EntryNotFoundException; -use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface; -use TYPO3\CMS\Fluid\Core\ViewHelper\TemplateVariableContainer; -class SlotViewHelperService implements SingletonInterface +class SlotContextEntry { + /** + * @var RenderingContextInterface|\TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface + */ + protected $renderingContext; + /** * Contains the closures which will render the registered slots. The keys * of this array are the names of the slots. * * @var Closure[] */ - private $closures = []; + protected $closures = []; /** * @var array[] */ - private $arguments = []; + protected $arguments = []; /** - * @var RenderingContextInterface|\TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface[] + * @var array[] */ - private $renderingContext = []; + protected $injectedVariables = []; /** * @var array[] */ - private $injectedVariables = []; + protected $savedVariables = []; /** - * @var array[] + * @param RenderingContextInterface $renderingContext */ - private $savedVariables = []; + public function __construct(RenderingContextInterface $renderingContext) + { + $this->renderingContext = $renderingContext; + } /** - * Adds a closure - which will render the slot with the given name - to the + * Adds a closure - used to render the slot with the given name - to the * private storage in this class. * - * @param string $name - * @param Closure $closure - * @param array $arguments - * @param RenderingContextInterface $renderingContext + * @param string $name + * @param Closure $closure + * @param array $arguments */ - public function addSlot($name, Closure $closure, array $arguments, RenderingContextInterface $renderingContext) + public function addSlot($name, Closure $closure, array $arguments) { $this->closures[$name] = $closure; $this->arguments[$name] = $arguments; - $this->renderingContext[$name] = $renderingContext; } /** @@ -114,12 +118,12 @@ public function hasSlot($name) * Note that the variables that are already defined are first saved before * being overridden, so they can be restored later. * - * @param string $slotName - * @param array $arguments + * @param string $slotName + * @param array $arguments */ public function addTemplateVariables($slotName, array $arguments) { - $templateVariableContainer = $this->getTemplateVariableContainer($slotName); + $templateVariableContainer = $this->renderingContext->getTemplateVariableContainer(); $savedArguments = []; ArrayUtility::mergeRecursiveWithOverrule( @@ -144,11 +148,11 @@ public function addTemplateVariables($slotName, array $arguments) * Will remove all variables previously injected in the template variable * container, and restore the ones that were saved before being overridden. * - * @param string $slotName + * @param string $slotName */ public function restoreTemplateVariables($slotName) { - $templateVariableContainer = $this->getTemplateVariableContainer($slotName); + $templateVariableContainer = $this->renderingContext->getTemplateVariableContainer(); $mergedArguments = (isset($this->injectedVariables[$slotName])) ? $this->injectedVariables[$slotName] : []; $savedArguments = (isset($this->savedVariables[$slotName])) ? $this->savedVariables[$slotName] : []; @@ -160,27 +164,4 @@ public function restoreTemplateVariables($slotName) $templateVariableContainer->add($key, $value); } } - - /** - * @param string $slotName - * @return TemplateVariableContainer - */ - protected function getTemplateVariableContainer($slotName) - { - /** @var TemplateVariableContainer $templateVariableContainer */ - $templateVariableContainer = $this->renderingContext[$slotName]->getTemplateVariableContainer(); - - return $templateVariableContainer; - } - - /** - * Resets the service variables. - */ - public function resetState() - { - $this->closures = []; - $this->arguments = []; - $this->injectedVariables = []; - $this->savedVariables = []; - } } diff --git a/Classes/Service/ViewHelper/Slot/SlotViewHelperService.php b/Classes/Service/ViewHelper/Slot/SlotViewHelperService.php new file mode 100644 index 0000000..3950764 --- /dev/null +++ b/Classes/Service/ViewHelper/Slot/SlotViewHelperService.php @@ -0,0 +1,120 @@ + + * + * This file is part of the TYPO3 FormZ project. + * It is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License, either + * version 3 of the License, or any later version. + * + * For the full copyright and license information, see: + * http://www.gnu.org/licenses/gpl-3.0.html + */ + +namespace Romm\Formz\Service\ViewHelper\Slot; + +use Closure; +use Romm\Formz\Exceptions\EntryNotFoundException; +use TYPO3\CMS\Core\SingletonInterface; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface; + +class SlotViewHelperService implements SingletonInterface +{ + /** + * @var SlotContextEntry[] + */ + protected $contextEntries = []; + + /** + * @param RenderingContextInterface $renderingContext + */ + public function activate(RenderingContextInterface $renderingContext) + { + $this->contextEntries[] = GeneralUtility::makeInstance(SlotContextEntry::class, $renderingContext); + } + + /** + * Removes the current context entry. + */ + public function resetState() + { + array_pop($this->contextEntries); + } + + /** + * @see \Romm\Formz\Service\ViewHelper\Slot\SlotContextEntry::addSlot() + * + * @param string $name + * @param Closure $closure + * @param array $arguments + */ + public function addSlot($name, Closure $closure, array $arguments) + { + $this->getCurrentContext()->addSlot($name, $closure, $arguments); + } + + /** + * @see \Romm\Formz\Service\ViewHelper\Slot\SlotContextEntry::getSlotClosure() + * + * @param string $name + * @return Closure + * @throws EntryNotFoundException + */ + public function getSlotClosure($name) + { + return $this->getCurrentContext()->getSlotClosure($name); + } + + /** + * @see \Romm\Formz\Service\ViewHelper\Slot\SlotContextEntry::getSlotArguments() + * + * @param string $name + * @return array + * @throws EntryNotFoundException + */ + public function getSlotArguments($name) + { + return $this->getCurrentContext()->getSlotArguments($name); + } + + /** + * @see \Romm\Formz\Service\ViewHelper\Slot\SlotContextEntry::hasSlot() + * + * @param string $name + * @return bool + */ + public function hasSlot($name) + { + return $this->getCurrentContext()->hasSlot($name); + } + + /** + * @see \Romm\Formz\Service\ViewHelper\Slot\SlotContextEntry::addTemplateVariables() + * + * @param string $slotName + * @param array $arguments + */ + public function addTemplateVariables($slotName, array $arguments) + { + $this->getCurrentContext()->addTemplateVariables($slotName, $arguments); + } + + /** + * @see \Romm\Formz\Service\ViewHelper\Slot\SlotContextEntry::restoreTemplateVariables() + * + * @param string $slotName + */ + public function restoreTemplateVariables($slotName) + { + $this->getCurrentContext()->restoreTemplateVariables($slotName); + } + + /** + * @return SlotContextEntry + */ + protected function getCurrentContext() + { + return end($this->contextEntries); + } +} diff --git a/Classes/ViewHelpers/ClassViewHelper.php b/Classes/ViewHelpers/ClassViewHelper.php index e83cdd2..ef4ea62 100644 --- a/Classes/ViewHelpers/ClassViewHelper.php +++ b/Classes/ViewHelpers/ClassViewHelper.php @@ -17,8 +17,8 @@ use Romm\Formz\Exceptions\EntryNotFoundException; use Romm\Formz\Exceptions\InvalidEntryException; use Romm\Formz\Exceptions\UnregisteredConfigurationException; -use Romm\Formz\Service\ViewHelper\FieldViewHelperService; -use Romm\Formz\Service\ViewHelper\FormViewHelperService; +use Romm\Formz\Service\ViewHelper\Field\FieldViewHelperService; +use Romm\Formz\Service\ViewHelper\Form\FormViewHelperService; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Error\Result; use TYPO3\CMS\Extbase\Reflection\ObjectAccess; diff --git a/Classes/ViewHelpers/FieldViewHelper.php b/Classes/ViewHelpers/FieldViewHelper.php index 9c980a9..dd9a680 100644 --- a/Classes/ViewHelpers/FieldViewHelper.php +++ b/Classes/ViewHelpers/FieldViewHelper.php @@ -21,9 +21,9 @@ use Romm\Formz\Exceptions\InvalidArgumentValueException; use Romm\Formz\Exceptions\PropertyNotAccessibleException; use Romm\Formz\Service\StringService; -use Romm\Formz\Service\ViewHelper\FieldViewHelperService; -use Romm\Formz\Service\ViewHelper\FormViewHelperService; -use Romm\Formz\Service\ViewHelper\SlotViewHelperService; +use Romm\Formz\Service\ViewHelper\Field\FieldViewHelperService; +use Romm\Formz\Service\ViewHelper\Form\FormViewHelperService; +use Romm\Formz\Service\ViewHelper\Slot\SlotViewHelperService; use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\VersionNumberUtility; @@ -104,6 +104,12 @@ public function render() */ $this->injectFieldInService($this->arguments['name']); + /* + * Activating the slot service, which will be used all along the + * rendering of this very field. + */ + $this->slotService->activate($this->renderingContext); + /* * Calling this here will process every view helper beneath this one, * allowing options and slots to be used correctly in the field layout. @@ -131,7 +137,7 @@ public function render() /* * Resetting all services data. */ - $this->fieldService->resetState(); + $this->fieldService->removeCurrentField(); $this->slotService->resetState(); $viewHelperVariableContainer->setView($currentView); @@ -162,6 +168,9 @@ protected function renderLayoutView(array $templateArguments) $view = $this->fieldService->getView($layout); + $layoutPaths = $this->getPaths('layout'); + $partialPaths = $this->getPaths('partial'); + if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '8.0.0', '<')) { $view->setRenderingContext($this->renderingContext); } else { @@ -178,8 +187,8 @@ protected function renderLayoutView(array $templateArguments) } } - $view->setLayoutRootPaths($viewConfiguration->getAbsoluteLayoutRootPaths()); - $view->setPartialRootPaths($viewConfiguration->getAbsolutePartialRootPaths()); + $view->setLayoutRootPaths($layoutPaths); + $view->setPartialRootPaths($partialPaths); $view->assignMultiple($templateArguments); return $view->render(); @@ -287,6 +296,50 @@ protected function restoreOriginalArguments(array $templateArguments) } } + /** + * This function will determinate the layout/partial root paths that should + * be given to the standalone view. This must be a merge between the paths + * given in the TypoScript configuration and the paths of the current view. + * + * This way, the user can use the layouts/partials from both the form + * rendering extension, as well as the ones used by the field layout. + * + * Please note that TYPO3 v8+ has this behaviour by default, meaning only + * the TypoScript configuration paths are needed, however in TYPO3 v7.6- we + * need to access the root paths, which is *not* granted by Fluid... We are + * then forced to use reflection, please don't do this at home! + * + * @param string $type `partial` or `layout` + * @return array + * + * @deprecated Must be removed when TYPO3 7.6 is not supported anymore! + */ + protected function getPaths($type) + { + $viewConfiguration = $this->formService->getFormObject()->getConfiguration()->getRootConfiguration()->getView(); + + $paths = $type === 'partial' + ? $viewConfiguration->getAbsolutePartialRootPaths() + : $viewConfiguration->getAbsoluteLayoutRootPaths(); + + if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '8.0.0', '>=')) { + return $paths; + } else { + $currentView = $this->renderingContext->getViewHelperVariableContainer()->getView(); + $propertyName = $type === 'partial' + ? 'getPartialRootPaths' + : 'getLayoutRootPaths'; + + $reflectionClass = new \ReflectionClass($currentView); + $method = $reflectionClass->getMethod($propertyName); + $method->setAccessible(true); + + $value = $method->invoke($currentView); + + return array_unique(array_merge($paths, $value)); + } + } + /** * @param FormViewHelperService $service */ diff --git a/Classes/ViewHelpers/FormViewHelper.php b/Classes/ViewHelpers/FormViewHelper.php index a02d3a2..74b1b02 100644 --- a/Classes/ViewHelpers/FormViewHelper.php +++ b/Classes/ViewHelpers/FormViewHelper.php @@ -28,7 +28,7 @@ use Romm\Formz\Service\ExtensionService; use Romm\Formz\Service\StringService; use Romm\Formz\Service\TimeTrackerService; -use Romm\Formz\Service\ViewHelper\FormViewHelperService; +use Romm\Formz\Service\ViewHelper\Form\FormViewHelperService; use Romm\Formz\Validation\Validator\Form\DefaultFormValidator; use TYPO3\CMS\Core\Page\PageRenderer; use TYPO3\CMS\Core\Utility\GeneralUtility; diff --git a/Classes/ViewHelpers/FormatMessageViewHelper.php b/Classes/ViewHelpers/FormatMessageViewHelper.php index 5d415b9..a48baca 100644 --- a/Classes/ViewHelpers/FormatMessageViewHelper.php +++ b/Classes/ViewHelpers/FormatMessageViewHelper.php @@ -18,8 +18,8 @@ use Romm\Formz\Exceptions\InvalidArgumentTypeException; use Romm\Formz\Service\MessageService; use Romm\Formz\Service\StringService; -use Romm\Formz\Service\ViewHelper\FieldViewHelperService; -use Romm\Formz\Service\ViewHelper\FormViewHelperService; +use Romm\Formz\Service\ViewHelper\Field\FieldViewHelperService; +use Romm\Formz\Service\ViewHelper\Form\FormViewHelperService; use TYPO3\CMS\Extbase\Error\Error; use TYPO3\CMS\Extbase\Error\Message; use TYPO3\CMS\Extbase\Error\Notice; @@ -148,8 +148,7 @@ protected function getFieldName() if (empty($fieldName) && $this->fieldService->fieldContextExists() ) { - $field = $this->fieldService->getCurrentField(); - $fieldName = $field->getName(); + $fieldName = $this->fieldService->getCurrentField()->getName(); } if (null === $fieldName) { diff --git a/Classes/ViewHelpers/OptionViewHelper.php b/Classes/ViewHelpers/OptionViewHelper.php index 94af0eb..635a923 100644 --- a/Classes/ViewHelpers/OptionViewHelper.php +++ b/Classes/ViewHelpers/OptionViewHelper.php @@ -15,7 +15,7 @@ use Romm\Formz\Core\Core; use Romm\Formz\Exceptions\ContextNotFoundException; -use Romm\Formz\Service\ViewHelper\FieldViewHelperService; +use Romm\Formz\Service\ViewHelper\Field\FieldViewHelperService; use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface; diff --git a/Classes/ViewHelpers/Slot/HasViewHelper.php b/Classes/ViewHelpers/Slot/HasViewHelper.php index de22cec..3829d1a 100644 --- a/Classes/ViewHelpers/Slot/HasViewHelper.php +++ b/Classes/ViewHelpers/Slot/HasViewHelper.php @@ -15,8 +15,8 @@ use Romm\Formz\Core\Core; use Romm\Formz\Exceptions\ContextNotFoundException; -use Romm\Formz\Service\ViewHelper\FieldViewHelperService; -use Romm\Formz\Service\ViewHelper\SlotViewHelperService; +use Romm\Formz\Service\ViewHelper\Field\FieldViewHelperService; +use Romm\Formz\Service\ViewHelper\Slot\SlotViewHelperService; use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper; use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface; diff --git a/Classes/ViewHelpers/Slot/RenderViewHelper.php b/Classes/ViewHelpers/Slot/RenderViewHelper.php index 33291fd..64e54ca 100644 --- a/Classes/ViewHelpers/Slot/RenderViewHelper.php +++ b/Classes/ViewHelpers/Slot/RenderViewHelper.php @@ -16,8 +16,8 @@ use Closure; use Romm\Formz\Core\Core; use Romm\Formz\Exceptions\ContextNotFoundException; -use Romm\Formz\Service\ViewHelper\FieldViewHelperService; -use Romm\Formz\Service\ViewHelper\SlotViewHelperService; +use Romm\Formz\Service\ViewHelper\Field\FieldViewHelperService; +use Romm\Formz\Service\ViewHelper\Slot\SlotViewHelperService; use Romm\Formz\ViewHelpers\AbstractViewHelper; use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface; diff --git a/Classes/ViewHelpers/SlotViewHelper.php b/Classes/ViewHelpers/SlotViewHelper.php index 64f03ca..e12774c 100644 --- a/Classes/ViewHelpers/SlotViewHelper.php +++ b/Classes/ViewHelpers/SlotViewHelper.php @@ -15,8 +15,8 @@ use Romm\Formz\Core\Core; use Romm\Formz\Exceptions\ContextNotFoundException; -use Romm\Formz\Service\ViewHelper\FieldViewHelperService; -use Romm\Formz\Service\ViewHelper\SlotViewHelperService; +use Romm\Formz\Service\ViewHelper\Field\FieldViewHelperService; +use Romm\Formz\Service\ViewHelper\Slot\SlotViewHelperService; use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface; @@ -64,7 +64,7 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl /** @var SlotViewHelperService $slotService */ $slotService = Core::instantiate(SlotViewHelperService::class); - $slotService->addSlot($arguments['name'], $renderChildrenClosure, $arguments['arguments'], $renderingContext); + $slotService->addSlot($arguments['name'], $renderChildrenClosure, $arguments['arguments']); } /** diff --git a/Documentation/Localization.fr_FR/Settings.yml b/Documentation/Localization.fr_FR/Settings.yml index 1e71a7d..a39b198 100644 --- a/Documentation/Localization.fr_FR/Settings.yml +++ b/Documentation/Localization.fr_FR/Settings.yml @@ -6,8 +6,8 @@ conf.py: copyright: 2016 project: FormZ - version: 1.1.0 - release: 1.1.0 + version: 1.1.1 + release: 1.1.1 language: fr pdf_language: fr_FR latex_documents: diff --git a/Documentation/Settings.yml b/Documentation/Settings.yml index e10176d..de6f6d4 100644 --- a/Documentation/Settings.yml +++ b/Documentation/Settings.yml @@ -6,8 +6,8 @@ conf.py: copyright: 2016 project: FormZ - version: 1.1.0 - release: 1.1.0 + version: 1.1.1 + release: 1.1.1 latex_documents: - - Index - formz.tex diff --git a/Tests/Unit/Service/ViewHelper/Field/FieldContentEntryTest.php b/Tests/Unit/Service/ViewHelper/Field/FieldContentEntryTest.php new file mode 100644 index 0000000..911371c --- /dev/null +++ b/Tests/Unit/Service/ViewHelper/Field/FieldContentEntryTest.php @@ -0,0 +1,52 @@ +assertSame($field, $fieldContextEntry->getField()); + } + + /** + * @test + */ + public function setFieldOptionSetsFieldOption() + { + $fieldContextEntry = new FieldContextEntry(new Field); + + $fieldContextEntry->setOption('foo', 'bar'); + $this->assertEquals( + ['foo' => 'bar'], + $fieldContextEntry->getOptions() + ); + + $fieldContextEntry->setOption('bar', 'baz'); + $this->assertEquals( + [ + 'foo' => 'bar', + 'bar' => 'baz' + ], + $fieldContextEntry->getOptions() + ); + + $fieldContextEntry->setOption('foo', 'baz'); + $this->assertEquals( + [ + 'foo' => 'baz', + 'bar' => 'baz' + ], + $fieldContextEntry->getOptions() + ); + } +} diff --git a/Tests/Unit/Service/ViewHelper/FieldViewHelperServiceTest.php b/Tests/Unit/Service/ViewHelper/Field/FieldViewHelperServiceTest.php similarity index 58% rename from Tests/Unit/Service/ViewHelper/FieldViewHelperServiceTest.php rename to Tests/Unit/Service/ViewHelper/Field/FieldViewHelperServiceTest.php index d7f2c5f..b8ff9b6 100644 --- a/Tests/Unit/Service/ViewHelper/FieldViewHelperServiceTest.php +++ b/Tests/Unit/Service/ViewHelper/Field/FieldViewHelperServiceTest.php @@ -1,9 +1,9 @@ assertFalse($fieldService->fieldContextExists()); + $fieldService->setCurrentField($field); + $this->assertTrue($fieldService->fieldContextExists()); - $fieldService->setFieldOption('foo', 'bar'); - $this->assertEquals( - ['foo' => 'bar'], - $fieldService->getFieldOptions() - ); - - $fieldService->setFieldOption('bar', 'baz'); - $this->assertEquals( - [ - 'foo' => 'bar', - 'bar' => 'baz' - ], - $fieldService->getFieldOptions() - ); - - $fieldService->setFieldOption('foo', 'baz'); - $this->assertEquals( - [ - 'foo' => 'baz', - 'bar' => 'baz' - ], - $fieldService->getFieldOptions() - ); + $fieldService->removeCurrentField(); + + $this->assertFalse($fieldService->fieldContextExists()); } /** * @test */ - public function resetStateResetsState() + public function nestingFieldsWorks() { $fieldService = new FieldViewHelperService; - $field = new Field; - - $fieldService->setCurrentField($field); - $fieldService->setFieldOption('foo', 'bar'); - - $fieldService->resetState(); - - $this->assertFalse($fieldService->fieldContextExists()); - $this->assertNull($fieldService->getCurrentField()); - $this->assertEmpty($fieldService->getFieldOptions()); + $field1 = new Field; + $field2 = new Field; + + $fieldService->setCurrentField($field1); + $this->assertSame($field1, $fieldService->getCurrentField()); + $fieldService->setCurrentField($field2); + $this->assertSame($field2, $fieldService->getCurrentField()); + $fieldService->removeCurrentField(); + $this->assertSame($field1, $fieldService->getCurrentField()); } /** diff --git a/Tests/Unit/Service/ViewHelper/FormViewHelperServiceTest.php b/Tests/Unit/Service/ViewHelper/Form/FormViewHelperServiceTest.php similarity index 93% rename from Tests/Unit/Service/ViewHelper/FormViewHelperServiceTest.php rename to Tests/Unit/Service/ViewHelper/Form/FormViewHelperServiceTest.php index 108a0c2..f2ec348 100644 --- a/Tests/Unit/Service/ViewHelper/FormViewHelperServiceTest.php +++ b/Tests/Unit/Service/ViewHelper/Form/FormViewHelperServiceTest.php @@ -1,8 +1,8 @@ 'baz']; - $this->assertFalse($slotService->hasSlot('foo')); - $slotService->addSlot('foo', $fooClosure, $fooArguments, new RenderingContext); - $this->assertTrue($slotService->hasSlot('foo')); - $this->assertSame($fooClosure, $slotService->getSlotClosure('foo')); - $this->assertEquals($fooArguments, $slotService->getSlotArguments('foo')); - - $this->assertFalse($slotService->hasSlot('bar')); - $slotService->addSlot('bar', $barClosure, $barArguments, new RenderingContext); - $this->assertTrue($slotService->hasSlot('bar')); - $this->assertSame($barClosure, $slotService->getSlotClosure('bar')); - $this->assertEquals($barArguments, $slotService->getSlotArguments('bar')); + $this->assertFalse($contextEntry->hasSlot('foo')); + $contextEntry->addSlot('foo', $fooClosure, $fooArguments); + $this->assertTrue($contextEntry->hasSlot('foo')); + $this->assertSame($fooClosure, $contextEntry->getSlotClosure('foo')); + $this->assertEquals($fooArguments, $contextEntry->getSlotArguments('foo')); + + $this->assertFalse($contextEntry->hasSlot('bar')); + $contextEntry->addSlot('bar', $barClosure, $barArguments); + $this->assertTrue($contextEntry->hasSlot('bar')); + $this->assertSame($barClosure, $contextEntry->getSlotClosure('bar')); + $this->assertEquals($barArguments, $contextEntry->getSlotArguments('bar')); } /** @@ -46,6 +46,7 @@ public function addSlotAddsSlot() */ public function templateVariablesAreAdded() { + /** @var RenderingContext|\PHPUnit_Framework_MockObject_MockObject $renderingContext */ $renderingContext = $this->getMockBuilder(RenderingContext::class) ->setMethods(['getTemplateVariableContainer']) ->getMock(); @@ -65,12 +66,12 @@ public function templateVariablesAreAdded() ->method('getTemplateVariableContainer') ->willReturn($templateVariableContainerMock); - $slotService = new SlotViewHelperService; + $contextEntry = new SlotContextEntry($renderingContext); $emptyClosure = function () { }; - $slotService->addSlot('foo', $emptyClosure, ['foo' => 'bar'], $renderingContext); + $contextEntry->addSlot('foo', $emptyClosure, ['foo' => 'bar']); - $slotService->addTemplateVariables( + $contextEntry->addTemplateVariables( 'foo', ['bar' => 'baz'] ); @@ -85,6 +86,7 @@ public function templateVariablesAreAdded() */ public function templateVariablesAreOverriddenThenAdded() { + /** @var RenderingContext|\PHPUnit_Framework_MockObject_MockObject $renderingContext */ $renderingContext = $this->getMockBuilder(RenderingContext::class) ->setMethods(['getTemplateVariableContainer']) ->getMock(); @@ -101,12 +103,12 @@ public function templateVariablesAreOverriddenThenAdded() ->method('getTemplateVariableContainer') ->willReturn($templateVariableContainerMock); - $slotService = new SlotViewHelperService; + $contextEntry = new SlotContextEntry($renderingContext); $emptyClosure = function () { }; - $slotService->addSlot('foo', $emptyClosure, ['foo' => 'bar'], $renderingContext); + $contextEntry->addSlot('foo', $emptyClosure, ['foo' => 'bar']); - $slotService->addTemplateVariables( + $contextEntry->addTemplateVariables( 'foo', ['foo' => 'baz'] ); @@ -117,6 +119,7 @@ public function templateVariablesAreOverriddenThenAdded() */ public function templateVariablesAreProperlyRestored() { + /** @var RenderingContext|\PHPUnit_Framework_MockObject_MockObject $renderingContext */ $renderingContext = $this->getMockBuilder(RenderingContext::class) ->setMethods(['getTemplateVariableContainer']) ->getMock(); @@ -128,10 +131,10 @@ public function templateVariablesAreProperlyRestored() ->method('getTemplateVariableContainer') ->willReturn($templateVariableContainer); - $slotService = new SlotViewHelperService; + $contextEntry = new SlotContextEntry($renderingContext); $emptyClosure = function () { }; - $slotService->addSlot('foo', $emptyClosure, ['foo' => 'bar'], $renderingContext); + $contextEntry->addSlot('foo', $emptyClosure, ['foo' => 'bar']); $this->assertFalse($templateVariableContainer->exists('bar')); $this->assertEquals( @@ -139,7 +142,7 @@ public function templateVariablesAreProperlyRestored() $templateVariableContainer->get('foo') ); - $slotService->addTemplateVariables('foo', ['bar' => 'baz']); + $contextEntry->addTemplateVariables('foo', ['bar' => 'baz']); $this->assertTrue($templateVariableContainer->exists('bar')); $this->assertEquals( @@ -147,7 +150,7 @@ public function templateVariablesAreProperlyRestored() $templateVariableContainer->get('foo') ); - $slotService->restoreTemplateVariables('foo'); + $contextEntry->restoreTemplateVariables('foo'); $this->assertFalse($templateVariableContainer->exists('bar')); $this->assertEquals( @@ -156,22 +159,6 @@ public function templateVariablesAreProperlyRestored() ); } - /** - * @test - */ - public function resetStateResetsState() - { - $slotService = new SlotViewHelperService; - $fooClosure = function () { - return 'foo'; - }; - - $slotService->addSlot('foo', $fooClosure, [], new RenderingContext); - $slotService->resetState(); - - $this->assertFalse($slotService->hasSlot('foo')); - } - /** * @test */ @@ -179,8 +166,8 @@ public function getNotFoundSlotClosureThrowsException() { $this->setExpectedException(EntryNotFoundException::class); - $slotService = new SlotViewHelperService; - $slotService->getSlotClosure('bar'); + $contextEntry = new SlotContextEntry(new RenderingContext); + $contextEntry->getSlotClosure('bar'); } /** @@ -190,7 +177,7 @@ public function getNotFoundSlotArgumentsThrowsException() { $this->setExpectedException(EntryNotFoundException::class); - $slotService = new SlotViewHelperService; - $slotService->getSlotArguments('bar'); + $contextEntry = new SlotContextEntry(new RenderingContext); + $contextEntry->getSlotArguments('bar'); } } diff --git a/Tests/Unit/Service/ViewHelper/Slot/SlotViewHelperServiceTest.php b/Tests/Unit/Service/ViewHelper/Slot/SlotViewHelperServiceTest.php new file mode 100644 index 0000000..9417c02 --- /dev/null +++ b/Tests/Unit/Service/ViewHelper/Slot/SlotViewHelperServiceTest.php @@ -0,0 +1,34 @@ +activate(new RenderingContext); + $slotService->addSlot('foo', $closure, []); + $this->assertTrue($slotService->hasSlot('foo')); + + $slotService->activate(new RenderingContext); + $this->assertFalse($slotService->hasSlot('foo')); + $slotService->addSlot('bar', $closure, []); + $this->assertTrue($slotService->hasSlot('bar')); + + $slotService->resetState(); + $this->assertFalse($slotService->hasSlot('bar')); + $this->assertTrue($slotService->hasSlot('foo')); + } +} diff --git a/Tests/Unit/ViewHelpers/ClassViewHelperTest.php b/Tests/Unit/ViewHelpers/ClassViewHelperTest.php index 7ce80d5..3568c44 100644 --- a/Tests/Unit/ViewHelpers/ClassViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/ClassViewHelperTest.php @@ -6,8 +6,8 @@ use Romm\Formz\Exceptions\EntryNotFoundException; use Romm\Formz\Exceptions\InvalidEntryException; use Romm\Formz\Exceptions\UnregisteredConfigurationException; -use Romm\Formz\Service\ViewHelper\FieldViewHelperService; -use Romm\Formz\Service\ViewHelper\FormViewHelperService; +use Romm\Formz\Service\ViewHelper\Field\FieldViewHelperService; +use Romm\Formz\Service\ViewHelper\Form\FormViewHelperService; use Romm\Formz\Tests\Fixture\Form\DefaultForm; use Romm\Formz\ViewHelpers\ClassViewHelper; use TYPO3\CMS\Extbase\Validation\Error; diff --git a/Tests/Unit/ViewHelpers/FieldViewHelperTest.php b/Tests/Unit/ViewHelpers/FieldViewHelperTest.php index d06a8b1..02f73c1 100644 --- a/Tests/Unit/ViewHelpers/FieldViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/FieldViewHelperTest.php @@ -11,9 +11,9 @@ use Romm\Formz\Exceptions\PropertyNotAccessibleException; use Romm\Formz\Form\FormObject; use Romm\Formz\Form\FormObjectFactory; -use Romm\Formz\Service\ViewHelper\FieldViewHelperService; -use Romm\Formz\Service\ViewHelper\FormViewHelperService; -use Romm\Formz\Service\ViewHelper\SlotViewHelperService; +use Romm\Formz\Service\ViewHelper\Field\FieldViewHelperService; +use Romm\Formz\Service\ViewHelper\Form\FormViewHelperService; +use Romm\Formz\Service\ViewHelper\Slot\SlotViewHelperService; use Romm\Formz\Tests\Fixture\Form\DefaultForm; use Romm\Formz\ViewHelpers\FieldViewHelper; use TYPO3\CMS\Core\Cache\Backend\NullBackend; @@ -53,11 +53,7 @@ public function renderViewHelper($fieldName, $layoutName, FormObject $formObject ->method('formContextExists') ->willReturn(true); - $fieldServiceMock = $this->getMockedFieldService(); - $viewHelper->injectFieldService($fieldServiceMock); - $fieldServiceMock->expects($this->once()) - ->method('setCurrentField') - ->with($formObject->getConfiguration()->getField($fieldName)); + $viewHelper->injectFieldService(new FieldViewHelperService); $viewHelper->injectSlotService(new SlotViewHelperService); $viewHelper->setRenderingContext($this->getMockedRenderingContext()); @@ -153,7 +149,7 @@ public function renderNotExistingFieldThrowsException() ->setMethods(['renderChildren']) ->getMock(); $viewHelper->injectFormService($this->getMockedFormService($formObject)); - $viewHelper->injectFieldService($this->getMockedFieldService()); + $viewHelper->injectFieldService(new FieldViewHelperService); $viewHelper->setRenderingContext($this->getMockedRenderingContext()); $viewHelper->setArguments(['name' => 'bar']); @@ -181,7 +177,7 @@ public function renderFieldWithInvalidLayoutNameTypeThrowsException() ->setMethods(['renderChildren']) ->getMock(); $viewHelper->injectFormService($this->getMockedFormService($formObject)); - $viewHelper->injectFieldService($this->getMockedFieldService()); + $viewHelper->injectFieldService(new FieldViewHelperService); $viewHelper->injectSlotService(new SlotViewHelperService); $viewHelper->setRenderingContext($this->getMockedRenderingContext()); @@ -212,7 +208,7 @@ public function renderFieldWithEmptyLayoutNameThrowsException() ->setMethods(['renderChildren']) ->getMock(); $viewHelper->injectFormService($this->getMockedFormService($formObject)); - $viewHelper->injectFieldService($this->getMockedFieldService()); + $viewHelper->injectFieldService(new FieldViewHelperService); $viewHelper->injectSlotService(new SlotViewHelperService); $viewHelper->setRenderingContext($this->getMockedRenderingContext()); @@ -245,7 +241,7 @@ public function renderFieldWithNotExistingLayoutNameThrowsException() ->setMethods(['renderChildren']) ->getMock(); $viewHelper->injectFormService($this->getMockedFormService($formObject)); - $viewHelper->injectFieldService($this->getMockedFieldService()); + $viewHelper->injectFieldService(new FieldViewHelperService); $viewHelper->injectSlotService(new SlotViewHelperService); $viewHelper->setRenderingContext($this->getMockedRenderingContext()); @@ -278,7 +274,7 @@ public function renderFieldWithNotExistingLayoutItemNameThrowsException() ->setMethods(['renderChildren']) ->getMock(); $viewHelper->injectFormService($this->getMockedFormService($formObject)); - $viewHelper->injectFieldService($this->getMockedFieldService()); + $viewHelper->injectFieldService(new FieldViewHelperService); $viewHelper->injectSlotService(new SlotViewHelperService); $viewHelper->setRenderingContext($this->getMockedRenderingContext()); @@ -314,7 +310,7 @@ public function originalArgumentsAreRestoredAfterViewHelperIsRendered() ->setMethods(['renderChildren']) ->getMock(); $viewHelper->injectFormService($this->getMockedFormService($formObject)); - $viewHelper->injectFieldService($this->getMockedFieldService()); + $viewHelper->injectFieldService(new FieldViewHelperService); $viewHelper->injectSlotService(new SlotViewHelperService); $renderingContextMock = $this->getMockedRenderingContext(); @@ -429,18 +425,6 @@ protected function getMockedFormService(FormObject $formObject) return $formService; } - /** - * @return FieldViewHelperService|\PHPUnit_Framework_MockObject_MockObject - */ - protected function getMockedFieldService() - { - $fieldService = $this->getMockBuilder(FieldViewHelperService::class) - ->setMethods(['setCurrentField']) - ->getMock(); - - return $fieldService; - } - /** * @return RenderingContext|\PHPUnit_Framework_MockObject_MockObject */ @@ -457,6 +441,7 @@ protected function getMockedRenderingContext() ->willReturn($mockRequest); $view = new StandaloneView; + $view->setTemplatePathAndFilename('foo/bar'); $view->setControllerContext($controllerContextMock); $viewHelperVariableContainer = new ViewHelperVariableContainer; diff --git a/Tests/Unit/ViewHelpers/FormViewHelperTest.php b/Tests/Unit/ViewHelpers/FormViewHelperTest.php index 9e52a15..b5338ec 100644 --- a/Tests/Unit/ViewHelpers/FormViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/FormViewHelperTest.php @@ -12,7 +12,7 @@ use Romm\Formz\Exceptions\InvalidOptionValueException; use Romm\Formz\Form\FormObject; use Romm\Formz\Service\ControllerService; -use Romm\Formz\Service\ViewHelper\FormViewHelperService; +use Romm\Formz\Service\ViewHelper\Form\FormViewHelperService; use Romm\Formz\Service\ViewHelper\Legacy\FormViewHelper; use Romm\Formz\Service\ViewHelper\Legacy\OldFormViewHelper; use Romm\Formz\Tests\Fixture\Form\DefaultForm; diff --git a/Tests/Unit/ViewHelpers/FormatMessageViewHelperTest.php b/Tests/Unit/ViewHelpers/FormatMessageViewHelperTest.php index 5374d83..f450cff 100644 --- a/Tests/Unit/ViewHelpers/FormatMessageViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/FormatMessageViewHelperTest.php @@ -10,8 +10,8 @@ use Romm\Formz\Exceptions\EntryNotFoundException; use Romm\Formz\Exceptions\InvalidArgumentTypeException; use Romm\Formz\Form\FormObjectFactory; -use Romm\Formz\Service\ViewHelper\FieldViewHelperService; -use Romm\Formz\Service\ViewHelper\FormViewHelperService; +use Romm\Formz\Service\ViewHelper\Field\FieldViewHelperService; +use Romm\Formz\Service\ViewHelper\Form\FormViewHelperService; use Romm\Formz\Tests\Fixture\Form\ExtendedForm; use Romm\Formz\ViewHelpers\FormatMessageViewHelper; use TYPO3\CMS\Extbase\Error\Message; diff --git a/Tests/Unit/ViewHelpers/OptionViewHelperTest.php b/Tests/Unit/ViewHelpers/OptionViewHelperTest.php index da4dc79..a6ac9af 100644 --- a/Tests/Unit/ViewHelpers/OptionViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/OptionViewHelperTest.php @@ -3,7 +3,7 @@ use Romm\Formz\Configuration\Form\Field\Field; use Romm\Formz\Exceptions\ContextNotFoundException; -use Romm\Formz\Service\ViewHelper\FieldViewHelperService; +use Romm\Formz\Service\ViewHelper\Field\FieldViewHelperService; use Romm\Formz\Tests\Unit\UnitTestContainer; use Romm\Formz\ViewHelpers\OptionViewHelper; diff --git a/Tests/Unit/ViewHelpers/Slot/HasViewHelperTest.php b/Tests/Unit/ViewHelpers/Slot/HasViewHelperTest.php index 89a737c..308d3f6 100644 --- a/Tests/Unit/ViewHelpers/Slot/HasViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Slot/HasViewHelperTest.php @@ -2,9 +2,9 @@ namespace Romm\Formz\Tests\Unit\ViewHelpers\Slot; use Romm\Formz\Exceptions\ContextNotFoundException; -use Romm\Formz\Service\ViewHelper\FieldViewHelperService; +use Romm\Formz\Service\ViewHelper\Field\FieldViewHelperService; use Romm\Formz\Service\ViewHelper\Legacy\Slot\OldHasViewHelper; -use Romm\Formz\Service\ViewHelper\SlotViewHelperService; +use Romm\Formz\Service\ViewHelper\Slot\SlotViewHelperService; use Romm\Formz\Tests\Unit\UnitTestContainer; use Romm\Formz\Tests\Unit\ViewHelpers\AbstractViewHelperUnitTest; use Romm\Formz\ViewHelpers\Slot\HasViewHelper; diff --git a/Tests/Unit/ViewHelpers/Slot/RenderViewHelperTest.php b/Tests/Unit/ViewHelpers/Slot/RenderViewHelperTest.php index 3b9403b..e785657 100644 --- a/Tests/Unit/ViewHelpers/Slot/RenderViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Slot/RenderViewHelperTest.php @@ -3,8 +3,8 @@ use Romm\Formz\Configuration\Form\Field\Field; use Romm\Formz\Exceptions\ContextNotFoundException; -use Romm\Formz\Service\ViewHelper\FieldViewHelperService; -use Romm\Formz\Service\ViewHelper\SlotViewHelperService; +use Romm\Formz\Service\ViewHelper\Field\FieldViewHelperService; +use Romm\Formz\Service\ViewHelper\Slot\SlotViewHelperService; use Romm\Formz\Tests\Unit\UnitTestContainer; use Romm\Formz\Tests\Unit\ViewHelpers\AbstractViewHelperUnitTest; use Romm\Formz\ViewHelpers\Slot\RenderViewHelper; @@ -17,7 +17,7 @@ class RenderViewHelperTest extends AbstractViewHelperUnitTest */ public function renderViewHelper() { - $slotArgument = 'foo-slot'; + $slotName = 'foo-slot'; /** @var FieldViewHelperService|\PHPUnit_Framework_MockObject_MockObject $fieldService */ $fieldService = $this->getMockBuilder(FieldViewHelperService::class) @@ -29,21 +29,25 @@ public function renderViewHelper() /** @var SlotViewHelperService|\PHPUnit_Framework_MockObject_MockObject $slotService */ $slotService = $this->getMockBuilder(SlotViewHelperService::class) - ->setMethods(['getSlotClosure', 'getSlotArguments', 'hasSlot', 'getTemplateVariableContainer']) + ->setMethods(['getSlotClosure', 'hasSlot', 'addTemplateVariables', 'restoreTemplateVariables']) ->getMock(); $slotService->expects($this->once()) ->method('hasSlot') - ->with($slotArgument) + ->with($slotName) ->willReturn(true); $slotService->expects($this->once()) ->method('getSlotClosure') - ->with($slotArgument) + ->with($slotName) ->willReturn(function () { return 'foo'; }); $slotService->expects($this->once()) - ->method('getSlotArguments') - ->with($slotArgument) + ->method('addTemplateVariables') + ->with($slotName) + ->willReturn([]); + $slotService->expects($this->once()) + ->method('restoreTemplateVariables') + ->with($slotName) ->willReturn([]); UnitTestContainer::get()->registerMockedInstance(SlotViewHelperService::class, $slotService); @@ -52,7 +56,7 @@ public function renderViewHelper() $this->injectDependenciesIntoViewHelper($viewHelper); $viewHelper->injectFieldService($fieldService); $viewHelper->setArguments([ - 'slot' => $slotArgument, + 'slot' => $slotName, 'arguments' => [] ]); $viewHelper->initializeArguments(); @@ -74,7 +78,8 @@ public function argumentsAreAddedThenRemoved() ->getMock(); $emptyClosure = function () { }; - $slotService->addSlot('foo', $emptyClosure, ['foo' => 'bar'], new RenderingContext); + $slotService->activate(new RenderingContext); + $slotService->addSlot('foo', $emptyClosure, ['foo' => 'bar']); $slotService->expects($this->once()) ->method('addTemplateVariables'); diff --git a/Tests/Unit/ViewHelpers/SlotViewHelperTest.php b/Tests/Unit/ViewHelpers/SlotViewHelperTest.php index bbd808a..890c70d 100644 --- a/Tests/Unit/ViewHelpers/SlotViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/SlotViewHelperTest.php @@ -2,8 +2,8 @@ namespace Romm\Formz\Tests\Unit\ViewHelpers; use Romm\Formz\Exceptions\ContextNotFoundException; -use Romm\Formz\Service\ViewHelper\FieldViewHelperService; -use Romm\Formz\Service\ViewHelper\SlotViewHelperService; +use Romm\Formz\Service\ViewHelper\Field\FieldViewHelperService; +use Romm\Formz\Service\ViewHelper\Slot\SlotViewHelperService; use Romm\Formz\Tests\Unit\UnitTestContainer; use Romm\Formz\ViewHelpers\SlotViewHelper; diff --git a/ext_emconf.php b/ext_emconf.php index 40c9b22..8fcf4af 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -2,7 +2,7 @@ /** @noinspection PhpUndefinedVariableInspection */ $EM_CONF[$_EXTKEY] = [ 'title' => 'FormZ • Modern form handler', - 'version' => '1.1.0', + 'version' => '1.1.1', 'state' => 'stable', 'description' => 'Manage your forms easily with powerful tools: TypoScript based validation, Fluid view helpers, a whole JavaScript API, and more. Use pre-defined layouts for Twitter Bootstrap and Foundation to build nice-looking forms in minutes. Need to build a basic form with only two fields? Need to build a huge registration form with dozens of fields? Use FormZ, it will live up to your expectations! Visit typo3-formz.com for more information.',