Commit 851bac6e authored by Andreas Fernandez's avatar Andreas Fernandez Committed by Andreas Fernandez
Browse files

[BUGFIX] Fix handling of ClosureFinisher

Check if the incoming optionValue is a closure and return early in such
case.

Resolves: #82550
Releases: master, 8.7
Change-Id: I0f6b12b8ed777906bfe7bc6849841b246e95bbd3
Reviewed-on: https://review.typo3.org/54213


Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: default avatarRalf Zimmermann <ralf.zimmermann@tritum.de>
Reviewed-by: Björn Jacob's avatarBjoern Jacob <bjoern.jacob@tritum.de>
Reviewed-by: default avatarJoerg Boesche <typo3@joergboesche.de>
Reviewed-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: Björn Jacob's avatarBjoern Jacob <bjoern.jacob@tritum.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
parent ec169157
......@@ -174,6 +174,10 @@ abstract class AbstractFinisher implements FinisherInterface
return $optionValue;
}
if ($optionValue instanceof \Closure) {
return $optionValue;
}
$formRuntime = $this->finisherContext->getFormRuntime();
// You can encapsulate a option value with {}.
......
<?php
declare(strict_types=1);
namespace TYPO3\CMS\Form\Tests\Unit\Domain\Finishers;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use TYPO3\CMS\Form\Domain\Finishers\ClosureFinisher;
use TYPO3\CMS\Form\Domain\Finishers\FinisherContext;
use TYPO3\CMS\Form\Domain\Runtime\FormRuntime;
/**
* Test case
*/
class ClosureFinisherTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
{
/**
* @test
*/
public function closureOptionForFinisherCanBeSetAndIsFunctional()
{
$closure = function (FinisherContext $finisherContext) {
return 'foobar';
};
/** @var ClosureFinisher|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface $mockClosureFinisher */
$mockClosureFinisher = $this->getAccessibleMock(ClosureFinisher::class, ['dummy'], [], '', false);
$mockClosureFinisher->_set('options', [
'closure' => $closure
]);
$finisherContextProphecy = $this->prophesize(FinisherContext::class);
$formRuntimeProphecy = $this->prophesize(FormRuntime::class);
$finisherContextProphecy->getFormRuntime(Argument::cetera())->willReturn($formRuntimeProphecy->reveal());
/** @var FinisherContext|ObjectProphecy $revealedFinisherContext */
$revealedFinisherContext = $finisherContextProphecy->reveal();
$mockClosureFinisher->_set('finisherContext', $revealedFinisherContext);
$closure = $mockClosureFinisher->_call('parseOption', 'closure');
$this->assertSame('foobar', $closure($revealedFinisherContext));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment