Skip to content

Commit

Permalink
[TASK] Refactor or VH tests to functionals (TYPO3#642)
Browse files Browse the repository at this point in the history
In order to provide reliable testing scenarios for ViewHelpers,
we prepare real world application of passing templates into
the Fluid Parser and comparing the result over isolated
variable passage into VH Helper methods.

With the refactoring also caching can now be tested.

All f:or tests have been refactored to functional tests
with this patch.
  • Loading branch information
s2b authored Aug 8, 2022
1 parent a044019 commit 87d0e31
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 90 deletions.
69 changes: 69 additions & 0 deletions tests/Functional/ViewHelpers/OrViewHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

/*
* This file belongs to the package "TYPO3 Fluid".
* See LICENSE.txt that was shipped with this package.
*/

namespace TYPO3Fluid\Fluid\Tests\Functional\ViewHelpers;

use TYPO3Fluid\Fluid\Tests\Functional\AbstractFunctionalTestCase;
use TYPO3Fluid\Fluid\View\TemplateView;

class OrViewHelperTest extends AbstractFunctionalTestCase
{
public function renderDataProvider(): \Generator
{
yield 'without arguments' => [
'<f:or>{var}</f:or>',
['var' => 'foo'],
'foo',
];
yield 'with content argument and non-empty content' => [
'<f:or content="{var}" />',
['var' => 'foo'],
'foo',
];
yield 'with content argument and empty content' => [
'<f:or content="{var}" />',
['var' => null],
null, // @todo this should probably be an empty string?
];
yield 'with alternative' => [
'<f:or content="{var}" alternative="alt" />',
['var' => null],
'alt',
];
yield 'with arguments and non-empty content' => [
'<f:or content="{var}" alternative="alt" arguments="{0: \'bar\', 1: 42}" />',
['var' => 'foo %1$s %2$d'],
'foo bar 42',
];
yield 'with arguments and empty content' => [
'<f:or content="{var}" alternative="alt %1$s %2$d" arguments="{0: \'bar\', 1: 42}" />',
['var' => null],
'alt bar 42',
];
}

/**
* @test
* @dataProvider renderDataProvider
*/
public function render(string $template, array $variables, $expected): void
{
$view = new TemplateView();
$view->assignMultiple($variables);
$view->getRenderingContext()->setCache(self::$cache);
$view->getRenderingContext()->getTemplatePaths()->setTemplateSource($template);
self::assertSame($expected, $view->render());

$view = new TemplateView();
$view->assignMultiple($variables);
$view->getRenderingContext()->setCache(self::$cache);
$view->getRenderingContext()->getTemplatePaths()->setTemplateSource($template);
self::assertSame($expected, $view->render());
}
}
90 changes: 0 additions & 90 deletions tests/Unit/ViewHelpers/OrViewHelperTest.php

This file was deleted.

0 comments on commit 87d0e31

Please sign in to comment.