Skip to content

Commit

Permalink
[TASK] allow typo3/testing-framework:^7
Browse files Browse the repository at this point in the history
update tests to work with TYPO3 11 and 12
  • Loading branch information
lukasniestroj committed May 12, 2023
1 parent 0ec1e52 commit 4432a55
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 43 deletions.
29 changes: 17 additions & 12 deletions Tests/Functional/ComponentRendererTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<?php

declare(strict_types=1);

namespace SMS\FluidComponents\Tests\Functional;

use SMS\FluidComponents\Fluid\ViewHelper\ComponentRenderer;
use TYPO3\CMS\Core\Cache\Backend\NullBackend;
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\Fluid\Core\Rendering\RenderingContext;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInvoker;

Expand All @@ -17,12 +21,11 @@ class ComponentRendererTest extends FunctionalTestCase
protected $testNamespace = 'SMS\\FluidComponents\\Tests\\Fixtures\\Functional\\Components';
protected $resetSingletonInstances = true;

protected $initializeDatabase = false;
protected $testExtensionsToLoad = [
protected bool $initializeDatabase = false;
protected array $testExtensionsToLoad = [
'typo3conf/ext/fluid_components'
];


public function setUp(): void
{
parent::setUp();
Expand Down Expand Up @@ -76,14 +79,16 @@ public function renderComponent($component, $arguments, $content, $expected)
/** @var ViewHelperInvoker $invoker */
$invoker = GeneralUtility::makeInstance(ViewHelperInvoker::class);

if ($container->has(RenderingContext::class)) {
/** @var RenderingContext $renderingContext */
$renderingContext = $container->get(RenderingContext::class);
$renderingContext->setRequest(GeneralUtility::makeInstance(Request::class));
} else {
/** @var RenderingContext $renderingContext */
$renderingContext = GeneralUtility::makeInstance(RenderingContext::class);
}
$renderingContext = $container->get(RenderingContextFactory::class)->create();

$renderingContext->setRequest(
new Request(
(new ServerRequest)->withAttribute(
'extbase',
new ExtbaseRequestParameters
)
)
);

$output = $invoker->invoke(
$renderer,
Expand Down
30 changes: 18 additions & 12 deletions Tests/Functional/ParameterEscapingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@

namespace SMS\FluidComponents\Tests\Functional;

use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use SMS\FluidComponents\Utility\ComponentLoader;
use TYPO3\CMS\Fluid\View\TemplateView;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

class ParameterEscapingTest extends FunctionalTestCase
{
protected $initializeDatabase = false;
protected $testExtensionsToLoad = [
protected bool $initializeDatabase = false;
protected array $testExtensionsToLoad = [
'typo3conf/ext/fluid_components'
];

Expand Down Expand Up @@ -142,7 +145,17 @@ public function renderDataProvider(): \Generator
*/
public function render(string $template, string $expected): void
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view = new TemplateView();
$view->getRenderingContext()->setRequest(
new Request(
(new ServerRequest)->withAttribute(
'extbase',
new ExtbaseRequestParameters
)
)
);
$view->getRenderingContext()->getViewHelperResolver()->addNamespace('fc', 'SMS\\FluidComponents\\ViewHelpers');
$view->getRenderingContext()->getViewHelperResolver()->addNamespace('test', 'SMS\\FluidComponents\\Tests\\Fixtures\\Functional\\Components');
$view->assign(
'maliciousVariable',
"<script>alert('This JavaScript should not be executed by the browser')</script>"
Expand All @@ -151,14 +164,7 @@ public function render(string $template, string $expected): void
'safeVariable',
'<div>Pre-rendered output without unsafe user input</div>'
);

$view->setTemplateSource('<html
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:fc="http://typo3.org/ns/SMS/FluidComponents/ViewHelpers"
xmlns:test="http://typo3.org/ns/SMS/FluidComponents/Tests/Fixtures/Functional/Components"
data-namespace-typo3-fluid="true"
>' . $template);

$view->getRenderingContext()->getTemplatePaths()->setTemplateSource($template);
self::assertSame($expected, $view->render());
}
}
18 changes: 9 additions & 9 deletions Tests/Functional/ViewHelpers/Variable/MapViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

namespace SMS\FluidComponents\Tests\Functional\ViewHelpers\Variable;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Fluid\View\TemplateView;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

class MapViewHelperTest extends FunctionalTestCase
{
protected bool $initializeDatabase = false;
protected array $testExtensionsToLoad = [
'typo3conf/ext/fluid_components'
];

public function renderDataProvider(): \Generator
{
$input = [
Expand Down Expand Up @@ -125,14 +129,10 @@ public function renderDataProvider(): \Generator
*/
public function render(array $input, string $template, array $expected): void
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view = new TemplateView();
$view->getRenderingContext()->getViewHelperResolver()->addNamespace('fc', 'SMS\\FluidComponents\\ViewHelpers');
$view->assign('dataSource',$input);
$view->setTemplateSource('<html
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:fc="SMS\FluidComponents\ViewHelpers"
data-namespace-typo3-fluid="true"
>' . $template);

$view->getRenderingContext()->getTemplatePaths()->setTemplateSource($template);
$view->render();
self::assertSame($expected, $view->getRenderingContext()->getVariableProvider()->get('dataTarget'));
}
Expand Down
18 changes: 9 additions & 9 deletions Tests/Functional/ViewHelpers/Variable/PushViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

namespace SMS\FluidComponents\Tests\Functional\ViewHelpers\Variable;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Fluid\View\TemplateView;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

class PushViewHelperTest extends FunctionalTestCase
{
protected bool $initializeDatabase = false;
protected array $testExtensionsToLoad = [
'typo3conf/ext/fluid_components'
];

public function renderDataProvider(): \Generator
{
$simpleArray = ['a', 'b', 'c', 'd'];
Expand Down Expand Up @@ -47,14 +51,10 @@ public function renderDataProvider(): \Generator
*/
public function render(array $input, string $template, array $expected): void
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view = new TemplateView();
$view->getRenderingContext()->getViewHelperResolver()->addNamespace('fc', 'SMS\\FluidComponents\\ViewHelpers');
$view->assign('inputArray',$input);
$view->setTemplateSource('<html
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:fc="SMS\FluidComponents\ViewHelpers"
data-namespace-typo3-fluid="true"
>' . $template);

$view->getRenderingContext()->getTemplatePaths()->setTemplateSource($template);
$view->render();
self::assertSame($expected, $view->getRenderingContext()->getVariableProvider()->get('resultArray'));
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"typo3fluid/fluid": "^2"
},
"require-dev": {
"typo3/testing-framework": "^6.0",
"typo3/testing-framework": "^6.0 || ^7.0",
"squizlabs/php_codesniffer": "^3.0",
"editorconfig-checker/editorconfig-checker": "^10.0",
"phpspec/prophecy-phpunit": "^2.0"
Expand Down

0 comments on commit 4432a55

Please sign in to comment.