-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Add test for recursive partial
- Loading branch information
Showing
4 changed files
with
142 additions
and
73 deletions.
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
tests/Functional/Cases/Rendering/RecursiveRenderingTest.php
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,133 @@ | ||
<?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\Cases\Rendering; | ||
|
||
use TYPO3Fluid\Fluid\Tests\Functional\AbstractFunctionalTestCase; | ||
use TYPO3Fluid\Fluid\View\TemplateView; | ||
|
||
final class RecursiveRenderingTest extends AbstractFunctionalTestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function recursiveSectionRenderingClonesVariableStorageAndRestoresAfterLoop(): void | ||
{ | ||
$source = file_get_contents(__DIR__ . '/../../Fixtures/Templates/RecursiveSectionRendering.html'); | ||
$variables = [ | ||
'settings' => [ | ||
'test' => '<strong>Bla</strong>' | ||
], | ||
'items' => [ | ||
[ | ||
'id' => 1, | ||
'items' => [ | ||
[ | ||
'id' => 2, | ||
'items' => [ | ||
[ | ||
'id' => 3, | ||
'items' => [] | ||
] | ||
] | ||
] | ||
] | ||
], | ||
[ | ||
'id' => 4 | ||
] | ||
] | ||
]; | ||
$expectations = [ | ||
'Item: 1.', | ||
'Item: 2.', | ||
'Item: 3.', | ||
'Item: 4.' | ||
]; | ||
|
||
$view = new TemplateView(); | ||
$view->getRenderingContext()->setCache(self::$cache); | ||
$view->assignMultiple($variables); | ||
$view->getRenderingContext()->getTemplatePaths()->setTemplateSource($source); | ||
$output = $view->render(); | ||
foreach ($expectations as $expectedValue) { | ||
self::assertStringContainsString($expectedValue, $output); | ||
} | ||
|
||
// A second run to verify cached template parsing | ||
$view = new TemplateView(); | ||
$view->getRenderingContext()->setCache(self::$cache); | ||
$view->assignMultiple($variables); | ||
$view->getRenderingContext()->getTemplatePaths()->setTemplateSource($source); | ||
$output = $view->render(); | ||
foreach ($expectations as $expectedValue) { | ||
self::assertStringContainsString($expectedValue, $output); | ||
} | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function recursivePartialRenderingClonesVariableStorageAndRestoresAfterLoop(): void | ||
{ | ||
$partialPath = __DIR__ . '/../../Fixtures/Partials/'; | ||
$source = file_get_contents(__DIR__ . '/../../Fixtures/Templates/RecursivePartialRendering.html'); | ||
$variables = [ | ||
'settings' => [ | ||
'test' => '<strong>Bla</strong>' | ||
], | ||
'items' => [ | ||
[ | ||
'id' => 1, | ||
'items' => [ | ||
[ | ||
'id' => 2, | ||
'items' => [ | ||
[ | ||
'id' => 3, | ||
'items' => [] | ||
] | ||
] | ||
] | ||
] | ||
], | ||
[ | ||
'id' => 4 | ||
] | ||
] | ||
]; | ||
$expectations = [ | ||
'Item: 1.', | ||
'Item: 2.', | ||
'Item: 3.', | ||
'Item: 4.' | ||
]; | ||
|
||
$view = new TemplateView(); | ||
$view->getRenderingContext()->setCache(self::$cache); | ||
$view->assignMultiple($variables); | ||
$view->getRenderingContext()->getTemplatePaths()->setPartialRootPaths([$partialPath]); | ||
$view->getRenderingContext()->getTemplatePaths()->setTemplateSource($source); | ||
$output = $view->render(); | ||
foreach ($expectations as $expectedValue) { | ||
self::assertStringContainsString($expectedValue, $output); | ||
} | ||
|
||
// A second run to verify cached template parsing | ||
$view = new TemplateView(); | ||
$view->getRenderingContext()->setCache(self::$cache); | ||
$view->assignMultiple($variables); | ||
$view->getRenderingContext()->getTemplatePaths()->setPartialRootPaths([$partialPath]); | ||
$view->getRenderingContext()->getTemplatePaths()->setTemplateSource($source); | ||
$output = $view->render(); | ||
foreach ($expectations as $expectedValue) { | ||
self::assertStringContainsString($expectedValue, $output); | ||
} | ||
} | ||
} |
73 changes: 0 additions & 73 deletions
73
tests/Functional/Cases/Rendering/RecursiveSectionRenderingTest.php
This file was deleted.
Oops, something went wrong.
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,8 @@ | ||
<f:spaceless> | ||
<f:for each="{items}" as="item"> | ||
Item: {item.id}. | ||
<f:if condition="{item.items}"> | ||
<f:render partial="RecursivePartial" arguments="{items: item.items}" /> | ||
</f:if> | ||
</f:for> | ||
</f:spaceless> |
1 change: 1 addition & 0 deletions
1
tests/Functional/Fixtures/Templates/RecursivePartialRendering.html
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 @@ | ||
<f:render partial="RecursivePartial" arguments="{items: items}" /> |