From 7388438f387d1a480cfd760dfe9f0918a9c15b17 Mon Sep 17 00:00:00 2001 From: Roberto Torresani Date: Tue, 12 Jul 2016 12:59:33 +0200 Subject: [PATCH] [TASK] Move arguments to initializeArguments() in Nl2brVH in ext:fluid Move the argument registrations away from the render() method to initializeArguments(), to prevent any errors with PHP7 and subclassed ViewHelpers if/when render() method signatures change. Change the UnitTest Nl2brViewHelperTest with setArguments() Resolves: #77064 Releases: master Change-Id: I5bcf8ca97d39ce5ccbb1602bde80f48bafde3d32 Reviewed-on: https://review.typo3.org/48928 Tested-by: Bamboo TYPO3com Reviewed-by: Joerg Boesche Tested-by: Joerg Boesche Reviewed-by: Susanne Moog Tested-by: Susanne Moog --- .../ViewHelpers/Format/Nl2brViewHelper.php | 16 ++++++- .../Format/Nl2brViewHelperTest.php | 44 ++++++++++++++----- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Format/Nl2brViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Format/Nl2brViewHelper.php index 22725f2d126f..a8391c2442bc 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Format/Nl2brViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Format/Nl2brViewHelper.php @@ -46,15 +46,27 @@ class Nl2brViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; + /** + * Initialize arguments. + * + * @api + * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception + */ + public function initializeArguments() + { + parent::initializeArguments(); + $this->registerArgument('value', 'string', 'string to format'); + } + /** * Replaces newline characters by HTML line breaks. * - * @param string $value string to format * @return string the altered string. * @api */ - public function render($value = null) + public function render() { + $value = $this->arguments['value']; return static::renderStatic( array( 'value' => $value diff --git a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/Nl2brViewHelperTest.php b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/Nl2brViewHelperTest.php index bf93455aee40..35b5751306bd 100644 --- a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/Nl2brViewHelperTest.php +++ b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/Nl2brViewHelperTest.php @@ -29,11 +29,8 @@ class Nl2brViewHelperTest extends ViewHelperBaseTestcase protected function setUp() { parent::setUp(); - $this->viewHelper = $this->getMockBuilder(Nl2brViewHelper::class) - ->setMethods(array('renderChildren')) - ->getMock(); + $this->viewHelper = new Nl2brViewHelper(); $this->injectDependenciesIntoViewHelper($this->viewHelper); - $this->viewHelper->initializeArguments(); } /** @@ -41,8 +38,17 @@ class Nl2brViewHelperTest extends ViewHelperBaseTestcase */ public function viewHelperDoesNotModifyTextWithoutLineBreaks() { - $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('

Some Text without line breaks

')); - $actualResult = $this->viewHelper->render(); + $this->viewHelper->setRenderChildrenClosure( + function () { + return '

Some Text without line breaks

'; + } + ); + $this->setArgumentsUnderTest( + $this->viewHelper, + [ + ] + ); + $actualResult = $this->viewHelper->initializeArgumentsAndRender(); $this->assertEquals('

Some Text without line breaks

', $actualResult); } @@ -51,8 +57,17 @@ class Nl2brViewHelperTest extends ViewHelperBaseTestcase */ public function viewHelperConvertsLineBreaksToBRTags() { - $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Line 1' . chr(10) . 'Line 2')); - $actualResult = $this->viewHelper->render(); + $this->viewHelper->setRenderChildrenClosure( + function () { + return 'Line 1' . chr(10) . 'Line 2'; + } + ); + $this->setArgumentsUnderTest( + $this->viewHelper, + [ + ] + ); + $actualResult = $this->viewHelper->initializeArgumentsAndRender(); $this->assertEquals('Line 1
' . chr(10) . 'Line 2', $actualResult); } @@ -61,8 +76,17 @@ class Nl2brViewHelperTest extends ViewHelperBaseTestcase */ public function viewHelperConvertsWindowsLineBreaksToBRTags() { - $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Line 1' . chr(13) . chr(10) . 'Line 2')); - $actualResult = $this->viewHelper->render(); + $this->viewHelper->setRenderChildrenClosure( + function () { + return 'Line 1' . chr(13) . chr(10) . 'Line 2'; + } + ); + $this->setArgumentsUnderTest( + $this->viewHelper, + [ + ] + ); + $actualResult = $this->viewHelper->initializeArgumentsAndRender(); $this->assertEquals('Line 1
' . chr(13) . chr(10) . 'Line 2', $actualResult); } } -- 2.20.1