forked from TYPO3/Fluid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Refactor or VH tests to functionals (TYPO3#642)
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
Showing
2 changed files
with
69 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.