Commit 088b745d authored by Christian Kuhn's avatar Christian Kuhn Committed by Benjamin Franzke
Browse files

[!!!][TASK] Require ServerRequestInterface in Extbase Request

The Extbase Request still had a fallback to fetch
the base Request from $GLOBALS. The base Request
is of course a hard dependency of the Extbase
Request, it should be actively hand over as
construct argument.

Change-Id: If0b66ce0daae8983d2a083808af0b8cbc724e824
Resolves: #98391
Related: #98370
Releases: main
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75782


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Benjamin Franzke's avatarBenjamin Franzke <bfr@qbus.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Benjamin Franzke's avatarBenjamin Franzke <bfr@qbus.de>
parent d082f5e3
......@@ -1790,11 +1790,6 @@ parameters:
count: 1
path: ../../typo3/sysext/extbase/Classes/Mvc/Request.php
-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 13
path: ../../typo3/sysext/extbase/Classes/Mvc/Request.php
-
message: "#^Dead catch \\- TYPO3\\\\CMS\\\\Backend\\\\Routing\\\\Exception\\\\ResourceNotFoundException is never thrown in the try block\\.$#"
count: 1
......
......@@ -42,6 +42,11 @@ Affected installations
Extensions that actively manipulate the given Extbase :php:`Request` using setter methods
will trigger fatal PHP "method does not exist" errors.
Instances with extensions actively creating a :php:`Request` must actively hand over
a :php:`\Psr\Http\Message\ServerRequestInterface` as constructor argument, it must have
the attribute :php:`extbase` set, which must be an instance of
:php:`\TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters`.
Migration
=========
......
......@@ -216,7 +216,7 @@ class ExtbaseRequestParameters
if ($argumentName === '') {
throw new InvalidArgumentNameException('Invalid argument name.', 1210858767);
}
if ($argumentName[0] === '_' && $argumentName[1] === '_') {
if (str_starts_with($argumentName, '__')) {
$this->internalArguments[$argumentName] = $value;
return $this;
}
......
......@@ -20,7 +20,6 @@ namespace TYPO3\CMS\Extbase\Mvc;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;
use TYPO3\CMS\Core\Http\ServerRequest;
/**
* The extbase request.
......@@ -36,32 +35,8 @@ class Request implements RequestInterface
{
protected ServerRequestInterface $request;
/**
* @todo v12: final public function __construct(ServerRequestInterface $request)
*/
public function __construct($request = null)
{
if (is_string($request) && !empty($request)) {
// Deprecation layer for old extbase Request __construct(string $controllerClassName = '')
$controllerClassName = $request;
/** @var ServerRequestInterface $request */
$request = $GLOBALS['TYPO3_REQUEST'] ?? new ServerRequest();
$attribute = new ExtbaseRequestParameters($controllerClassName);
$request = $request->withAttribute('extbase', $attribute);
} elseif ($request === null) {
// Deprecation layer when ServerRequestInterface is not given yet
/** @var ServerRequestInterface $request */
// Fallback "new ServerRequest()" currently used in install tool.
$request = $GLOBALS['TYPO3_REQUEST'] ?? new ServerRequest();
$attribute = new ExtbaseRequestParameters('');
$request = $request->withAttribute('extbase', $attribute);
}
if (!$request instanceof ServerRequestInterface) {
throw new \InvalidArgumentException(
'Request must implement PSR-7 ServerRequestInterface',
1624452071
);
}
final public function __construct(ServerRequestInterface $request)
{
if (!$request->getAttribute('extbase') instanceof ExtbaseRequestParameters) {
throw new \InvalidArgumentException(
'Given request must have an attribute "extbase" of type ExtbaseAttribute',
......
......@@ -26,6 +26,7 @@ use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
use TYPO3\CMS\Extbase\Mvc\Dispatcher;
use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extbase\Mvc\RequestInterface;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
......@@ -204,7 +205,8 @@ class ActionControllerArgumentTest extends FunctionalTestCase
private function buildRequest(string $actionName, array $arguments = null): Request
{
$request = new Request();
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$request = new Request($serverRequest);
$request = $request->withPluginName($this->pluginName);
$request = $request->withControllerExtensionName($this->extensionName);
$request = $request->withControllerName('ArgumentTest');
......
......@@ -19,6 +19,8 @@ namespace TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller;
use ExtbaseTeam\ActionControllerTest\Controller\TestController;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extbase\Mvc\View\JsonView;
use TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\Fixture\Validation\Validator\CustomValidator;
......@@ -51,7 +53,8 @@ class ActionControllerTest extends FunctionalTestCase
{
parent::setUp();
$this->request = new Request();
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$this->request = new Request($serverRequest);
$this->request = $this->request->withPluginName('Pi1');
$this->request = $this->request->withControllerExtensionName('ActionControllerTest');
$this->request = $this->request->withControllerName('Test');
......
......@@ -21,14 +21,13 @@ use ExtbaseTeam\BlogExample\Controller\BlogController;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\LanguageAspect;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
/**
* Test case
*/
class ControllerArgumentsMappingTest extends FunctionalTestCase
{
/**
......@@ -61,7 +60,8 @@ class ControllerArgumentsMappingTest extends FunctionalTestCase
];
$configurationManager = $this->get(ConfigurationManager::class);
$configurationManager->setConfiguration($configuration);
$this->request = new Request();
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$this->request = new Request($serverRequest);
$this->request = $this->request->withPluginName('Pi1');
$this->request = $this->request->withControllerExtensionName(BlogController::class);
$this->request = $this->request->withControllerName('Blog');
......
......@@ -19,12 +19,14 @@ namespace TYPO3\CMS\Extbase\Tests\Functional\Mvc\Validation;
use ExtbaseTeam\BlogExample\Controller\BlogController;
use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
use TYPO3\CMS\Extbase\Error\Error;
use TYPO3\CMS\Extbase\Error\Result;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
use TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService;
use TYPO3\CMS\Extbase\Mvc\Dispatcher;
use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extbase\Security\Cryptography\HashService;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
......@@ -74,7 +76,8 @@ class ActionControllerValidationTest extends FunctionalTestCase
$this->importCSVDataSet(__DIR__ . '/../../Persistence/Fixtures/posts.csv');
$response = new Response();
$request = new Request();
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$request = new Request($serverRequest);
$request = $request->withControllerActionName('testForward');
$request = $request->withArgument('blogPost', $blogPostArgument);
......@@ -125,7 +128,8 @@ class ActionControllerValidationTest extends FunctionalTestCase
$this->importCSVDataSet(__DIR__ . '/../../Persistence/Fixtures/posts.csv');
$response = new Response();
$request = new Request();
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$request = new Request($serverRequest);
$request = $request->withControllerActionName('testRelatedObject');
$request = $request->withArgument('blog', ['__identity' => 1, 'description' => str_repeat('test', 40)]);
......@@ -191,7 +195,8 @@ class ActionControllerValidationTest extends FunctionalTestCase
$this->importCSVDataSet(__DIR__ . '/../../Persistence/Fixtures/posts.csv');
$response = new Response();
$request = new Request();
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$request = new Request($serverRequest);
$request = $request->withControllerActionName('testRelatedObject');
$request = $request->withArgument('blog', ['__identity' => 1, 'description' => str_repeat('test', 40)]);
......
......@@ -20,6 +20,7 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller;
use PHPUnit\Framework\MockObject\MockObject;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
......@@ -33,6 +34,7 @@ use TYPO3\CMS\Extbase\Mvc\Controller\Arguments;
use TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService;
use TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentTypeException;
use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchActionException;
use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extbase\Mvc\RequestInterface;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
......@@ -661,7 +663,9 @@ class ActionControllerTest extends UnitTestCase
$extensionService->getPluginNamespace(Argument::cetera(), Argument::cetera())->willReturn('');
$controller->injectInternalExtensionService($extensionService->reveal());
$controller->_set('request', new Request());
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$request = new Request($serverRequest);
$controller->_set('request', $request);
$controller->addFlashMessage($messageBody, $messageTitle, $severity, $storeInSession);
}
......
......@@ -17,7 +17,9 @@ declare(strict_types=1);
namespace TYPO3\CMS\Extbase\Tests\Unit\Mvc;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException;
use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
......@@ -28,7 +30,8 @@ class RequestTest extends UnitTestCase
*/
public function aSingleArgumentCanBeSetWithWithArgumentAndRetrievedWithGetArgument(): void
{
$request = new Request();
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$request = new Request($serverRequest);
$request = $request->withArgument('someArgumentName', 'theValue');
self::assertEquals('theValue', $request->getArgument('someArgumentName'));
}
......@@ -40,8 +43,9 @@ class RequestTest extends UnitTestCase
{
$this->expectException(InvalidArgumentNameException::class);
$this->expectExceptionCode(1210858767);
$request = new Request();
$request = $request->withArgument('', 'theValue');
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$request = new Request($serverRequest);
$request->withArgument('', 'theValue');
}
/**
......@@ -50,7 +54,8 @@ class RequestTest extends UnitTestCase
public function withArgumentsOverridesAllExistingArguments(): void
{
$arguments = ['key1' => 'value1', 'key2' => 'value2'];
$request = new Request();
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$request = new Request($serverRequest);
$request = $request->withArgument('someKey', 'shouldBeOverridden');
$request = $request->withArguments($arguments);
$actualResult = $request->getArguments();
......@@ -60,12 +65,10 @@ class RequestTest extends UnitTestCase
/**
* @test
*/
public function withArgumentShouldSetControllerExtensionNameIfPackageKeyIsGiven(): void
public function withArgumentCanNotSetAtExtension(): void
{
$request = $this->getMockBuilder(Request::class)
->onlyMethods(['withControllerExtensionName'])
->getMock();
$request->method('withControllerExtensionName')->with('MyExtension');
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$request = new Request($serverRequest);
$request = $request->withArgument('@extension', 'MyExtension');
self::assertFalse($request->hasArgument('@extension'));
}
......@@ -73,12 +76,10 @@ class RequestTest extends UnitTestCase
/**
* @test
*/
public function withArgumentShouldSetControllerNameIfControllerIsGiven(): void
public function withArgumentCanNotSetAtController(): void
{
$request = $this->getMockBuilder(Request::class)
->onlyMethods(['withControllerName'])
->getMock();
$request->method('withControllerName')->with('MyController');
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$request = new Request($serverRequest);
$request = $request->withArgument('@controller', 'MyController');
self::assertFalse($request->hasArgument('@controller'));
}
......@@ -86,12 +87,10 @@ class RequestTest extends UnitTestCase
/**
* @test
*/
public function withArgumentShouldSetControllerActionNameIfActionIsGiven(): void
public function withArgumentCanNotSetAtAction(): void
{
$request = $this->getMockBuilder(Request::class)
->onlyMethods(['withControllerActionName'])
->getMock();
$request->method('withControllerActionName')->with('foo');
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$request = new Request($serverRequest);
$request = $request->withArgument('@action', 'foo');
self::assertFalse($request->hasArgument('@action'));
}
......@@ -99,12 +98,10 @@ class RequestTest extends UnitTestCase
/**
* @test
*/
public function withArgumentShouldSetFormatIfFormatIsGiven(): void
public function withArgumentCanNotSetAtFormat(): void
{
$request = $this->getMockBuilder(Request::class)
->onlyMethods(['withFormat'])
->getMock();
$request->method('withFormat')->with('txt');
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$request = new Request($serverRequest);
$request = $request->withArgument('@format', 'txt');
self::assertFalse($request->hasArgument('@format'));
}
......@@ -112,9 +109,10 @@ class RequestTest extends UnitTestCase
/**
* @test
*/
public function internalArgumentsShouldNotBeReturnedAsNormalArgument(): void
public function internalArgumentsIsNotReturnedAsNormalArgument(): void
{
$request = new Request();
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$request = new Request($serverRequest);
$request = $request->withArgument('__referrer', 'foo');
self::assertFalse($request->hasArgument('__referrer'));
}
......@@ -124,12 +122,13 @@ class RequestTest extends UnitTestCase
*/
public function multipleArgumentsCanBeSetWithWithArgumentsAndRetrievedWithGetArguments(): void
{
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$request = new Request($serverRequest);
$arguments = [
'firstArgument' => 'firstValue',
'dænishÅrgument' => 'görman välju',
'3a' => '3v',
];
$request = new Request();
$request = $request->withArguments($arguments);
self::assertEquals($arguments, $request->getArguments());
}
......@@ -139,7 +138,8 @@ class RequestTest extends UnitTestCase
*/
public function hasArgumentTellsIfAnArgumentExists(): void
{
$request = new Request();
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$request = new Request($serverRequest);
$request = $request->withArgument('existingArgument', 'theValue');
self::assertTrue($request->hasArgument('existingArgument'));
self::assertFalse($request->hasArgument('notExistingArgument'));
......@@ -150,7 +150,8 @@ class RequestTest extends UnitTestCase
*/
public function theActionNameCanBeSetAndRetrieved(): void
{
$request = new Request();
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$request = new Request($serverRequest);
$request = $request->withControllerActionName('theAction');
self::assertEquals('theAction', $request->getControllerActionName());
}
......@@ -160,7 +161,8 @@ class RequestTest extends UnitTestCase
*/
public function theRepresentationFormatCanBeSetAndRetrieved(): void
{
$request = new Request();
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$request = new Request($serverRequest);
$request = $request->withFormat('html');
self::assertEquals('html', $request->getFormat());
}
......@@ -210,7 +212,8 @@ class RequestTest extends UnitTestCase
*/
public function withControllerObjectNameResolvesControllerObjectNameArgumentsCorrectly(array $controllerArguments, string $controllerObjectName): void
{
$request = new Request();
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$request = new Request($serverRequest);
$request = $request->withControllerObjectName($controllerObjectName);
$actualControllerArguments = [
'extensionName' => $request->getControllerExtensionName(),
......
......@@ -18,7 +18,9 @@ declare(strict_types=1);
namespace TYPO3\CMS\Fluid\View;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extbase\Mvc\RequestInterface;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
......@@ -38,7 +40,11 @@ class StandaloneView extends AbstractTemplateView
// usage is typically *not* extbase context. Controllers that want to get rid of this
// have to ->setRequest($myServerRequestInterface), or even ->setRequest(null) after
// object construction to get rid of an extbase request again.
$renderingContext->setRequest(GeneralUtility::makeInstance(Request::class));
$request = $GLOBALS['TYPO3_REQUEST'] ?? new ServerRequest();
if ($request->getAttribute('extbase') === null) {
$request = $request->withAttribute('extbase', new ExtbaseRequestParameters());
}
$renderingContext->setRequest(GeneralUtility::makeInstance(Request::class, $request));
parent::__construct($renderingContext);
}
......
......@@ -17,6 +17,8 @@ declare(strict_types=1);
namespace TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Be\Menus;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
......@@ -69,7 +71,8 @@ class ActionMenuItemViewHelperTest extends FunctionalTestCase
{
$context = $this->get(RenderingContextFactory::class)->create();
$context->getTemplatePaths()->setTemplateSource($source);
$context->setRequest(new Request());
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$context->setRequest(new Request($serverRequest));
$view = new TemplateView($context);
$view->assignMultiple($variables);
self::assertSame($expectation, $view->render());
......
......@@ -17,9 +17,11 @@ declare(strict_types=1);
namespace TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
......@@ -34,7 +36,8 @@ class FlashMessagesViewHelperTest extends FunctionalTestCase
{
$context = $this->get(RenderingContextFactory::class)->create();
$context->getTemplatePaths()->setTemplateSource('<f:flashMessages />');
$context->setRequest(new Request());
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$context->setRequest(new Request($serverRequest));
self::assertEmpty((new TemplateView($context))->render());
}
......
......@@ -50,7 +50,8 @@ class CheckboxViewHelperTest extends FunctionalTestCase
{
$context = $this->get(RenderingContextFactory::class)->create();
$context->getTemplatePaths()->setTemplateSource($template);
$context->setRequest(new Request());
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$context->setRequest(new Request($serverRequest));
self::assertSame($expected, (new TemplateView($context))->render());
}
......@@ -63,7 +64,8 @@ class CheckboxViewHelperTest extends FunctionalTestCase
$formObject->someProperty = false;
$context = $this->get(RenderingContextFactory::class)->create();
$context->getTemplatePaths()->setTemplateSource('<f:form object="{formObject}" fieldNamePrefix="myFieldPrefix" objectName="myObjectName"><f:form.checkbox value="foo" property="someProperty" checked="true" /></f:form>');
$context->setRequest(new Request());
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$context->setRequest(new Request($serverRequest));
$view = new TemplateView($context);
$view->assign('formObject', $formObject);
self::assertStringContainsString('<input type="hidden" name="myFieldPrefix[myObjectName][someProperty]" value="" /><input type="checkbox" name="myFieldPrefix[myObjectName][someProperty]" value="foo" checked="checked" />', $view->render());
......@@ -78,7 +80,8 @@ class CheckboxViewHelperTest extends FunctionalTestCase
$formObject->someProperty = true;
$context = $this->get(RenderingContextFactory::class)->create();
$context->getTemplatePaths()->setTemplateSource('<f:form object="{formObject}" fieldNamePrefix="myFieldPrefix" objectName="myObjectName"><f:form.checkbox value="foo" property="someProperty" /></f:form>');
$context->setRequest(new Request());
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$context->setRequest(new Request($serverRequest));
$view = new TemplateView($context);
$view->assign('formObject', $formObject);
self::assertStringContainsString('<input type="hidden" name="myFieldPrefix[myObjectName][someProperty]" value="" /><input type="checkbox" name="myFieldPrefix[myObjectName][someProperty]" value="foo" checked="checked" />', $view->render());
......@@ -93,7 +96,8 @@ class CheckboxViewHelperTest extends FunctionalTestCase
$formObject->someProperty = [];
$context = $this->get(RenderingContextFactory::class)->create();
$context->getTemplatePaths()->setTemplateSource('<f:form object="{formObject}" fieldNamePrefix="myFieldPrefix" objectName="myObjectName"><f:form.checkbox value="foo" property="someProperty" /></f:form>');
$context->setRequest(new Request());
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$context->setRequest(new Request($serverRequest));
$view = new TemplateView($context);
$view->assign('formObject', $formObject);
self::assertStringContainsString('<input type="hidden" name="myFieldPrefix[myObjectName][someProperty]" value="" /><input type="checkbox" name="myFieldPrefix[myObjectName][someProperty][]" value="foo" />', $view->render());
......@@ -108,7 +112,8 @@ class CheckboxViewHelperTest extends FunctionalTestCase
$formObject->someProperty = ['foo'];
$context = $this->get(RenderingContextFactory::class)->create();
$context->getTemplatePaths()->setTemplateSource('<f:form object="{formObject}" fieldNamePrefix="myFieldPrefix" objectName="myObjectName"><f:form.checkbox value="foo" property="someProperty" /></f:form>');
$context->setRequest(new Request());
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$context->setRequest(new Request($serverRequest));
$view = new TemplateView($context);
$view->assign('formObject', $formObject);
self::assertStringContainsString('<input type="hidden" name="myFieldPrefix[myObjectName][someProperty]" value="" /><input type="checkbox" name="myFieldPrefix[myObjectName][someProperty][]" value="foo" checked="checked" />', $view->render());
......@@ -122,7 +127,8 @@ class CheckboxViewHelperTest extends FunctionalTestCase
$formObject = new \ArrayObject(['someProperty' => true]);
$context = $this->get(RenderingContextFactory::class)->create();
$context->getTemplatePaths()->setTemplateSource('<f:form object="{formObject}" fieldNamePrefix="myFieldPrefix" objectName="myObjectName"><f:form.checkbox value="bar" property="someProperty" /></f:form>');
$context->setRequest(new Request());
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$context->setRequest(new Request($serverRequest));
$view = new TemplateView($context);
$view->assign('formObject', $formObject);
self::assertStringContainsString('<input type="hidden" name="myFieldPrefix[myObjectName][someProperty]" value="" /><input type="checkbox" name="myFieldPrefix[myObjectName][someProperty]" value="bar" checked="checked" />', $view->render());
......@@ -137,7 +143,8 @@ class CheckboxViewHelperTest extends FunctionalTestCase
$formObject->someProperty = 'bar';
$context = $this->get(RenderingContextFactory::class)->create();
$context->getTemplatePaths()->setTemplateSource('<f:form object="{formObject}" fieldNamePrefix="myFieldPrefix" objectName="myObjectName"><f:form.checkbox value="foo" property="someProperty" /></f:form>');
$context->setRequest(new Request());
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$context->setRequest(new Request($serverRequest));
$view = new TemplateView($context);
$view->assign('formObject', $formObject);
self::assertStringContainsString('<input type="hidden" name="myFieldPrefix[myObjectName][someProperty]" value="" /><input type="checkbox" name="myFieldPrefix[myObjectName][someProperty]" value="foo" checked="checked" />', $view->render());
......@@ -152,7 +159,8 @@ class CheckboxViewHelperTest extends FunctionalTestCase
$formObject->someProperty = null;
$context = $this->get(RenderingContextFactory::class)->create();
$context->getTemplatePaths()->setTemplateSource('<f:form object="{formObject}" fieldNamePrefix="myFieldPrefix" objectName="myObjectName"><f:form.checkbox value="foo" property="someProperty" /></f:form>');
$context->setRequest(new Request());
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$context->setRequest(new Request($serverRequest));
$view = new TemplateView($context);
$view->assign('formObject', $formObject);
self::assertStringContainsString('<input type="hidden" name="myFieldPrefix[myObjectName][someProperty]" value="" /><input type="checkbox" name="myFieldPrefix[myObjectName][someProperty]" value="foo" />', $view->render());
......
......@@ -17,6 +17,8 @@ declare(strict_types=1);
namespace TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Form;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
......@@ -33,7 +35,8 @@ class HiddenViewHelperTest extends FunctionalTestCase
{
$context = $this->get(RenderingContextFactory::class)->create();
$context->getTemplatePaths()->setTemplateSource('<f:form.hidden name="foo" value="bar" />');
$context->setRequest(new Request());
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$context->setRequest(new Request($serverRequest));
self::assertSame('<input type="hidden" name="foo" value="bar" />', (new TemplateView($context))->render());
}
}
......@@ -17,6 +17,8 @@ declare(strict_types=1);
namespace TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Form;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
......@@ -33,7 +35,8 @@ class PasswordViewHelperTest extends FunctionalTestCase
{
$context = $this->get(RenderingContextFactory::class)->create();
$context->getTemplatePaths()->setTemplateSource('<f:form.password />');
$context->setRequest(new Request());
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$context->setRequest(new Request($serverRequest));
self::assertSame('<input type="password" name="" value="" />', (new TemplateView($context))->render());
}
......@@ -44,7 +47,8 @@ class PasswordViewHelperTest extends FunctionalTestCase
{
$context = $this->get(RenderingContextFactory::class)->create();
$context->getTemplatePaths()->setTemplateSource('<f:form.password name="NameOfTextbox" value="Current value" />');
$context->setRequest(new Request());
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters());
$context->setRequest(new Request($serverRequest));
self::assertSame('<input type="password" name="NameOfTextbox" value="Current value" />', (new TemplateView($context))->render());
}
......@@ -55,7 +59,8 @@ class PasswordViewHelperTest extends FunctionalTestCase
{
$context = $this->get(RenderingContextFactory::class)->create();