Skip to content

Commit

Permalink
[TASK] Prevent template compilation in inheritance test
Browse files Browse the repository at this point in the history
This is an ugly workaround to prevent the interfering runtime
cache until #975 is resolved. Currently, subsequent test cases
are successful even if the rendering is modified to not inherit
ViewHelper namespaces to sub templates because they
re-use the "in-memory" template classes from previous tests.
As there is currently no way to configure this, we need to use
the ugly f:cache.disable ViewHelper in the affected template
to get robust testing results.
  • Loading branch information
s2b committed Sep 8, 2024
1 parent 8f1ee9e commit d00ef83
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
20 changes: 6 additions & 14 deletions tests/Functional/Core/Rendering/NamespaceInheritanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ public static function namespacesAreInheritedToLayoutAndPartialsDataProvider():
{
return [
'namespace provided via php api' => [
'<f:layout name="NamespaceInheritanceLayout" /><f:section name="Main"><test:tagBasedTest location="Template" /></f:section>',
'<f:cache.disable /><f:layout name="NamespaceInheritanceLayout" /><f:section name="Main"><test:tagBasedTest location="Template" /></f:section>',
['test' => 'TYPO3Fluid\\Fluid\\Tests\\Functional\\Fixtures\\ViewHelpers'],
[],
],
// @todo this should probably not work
'namespace provided to layout and partials via inline namespace declaration in template' => [
'{namespace test=TYPO3Fluid\\Fluid\\Tests\\Functional\\Fixtures\\ViewHelpers}<f:layout name="NamespaceInheritanceLayout" /><f:section name="Main"><test:tagBasedTest location="Template" /></f:section>',
'{namespace test=TYPO3Fluid\\Fluid\\Tests\\Functional\\Fixtures\\ViewHelpers}<f:cache.disable /><f:layout name="NamespaceInheritanceLayout" /><f:section name="Main"><test:tagBasedTest location="Template" /></f:section>',
[],
[],
],
// @todo this should probably not work
'namespace provided to layout and partials via xml namespace declaration in template' => [
'<html xmlns:test="http://typo3.org/ns/TYPO3Fluid/Fluid/Tests/Functional/Fixtures/ViewHelpers"><f:layout name="NamespaceInheritanceLayout" /><f:section name="Main"><test:tagBasedTest location="Template" /></f:section>',
'<html xmlns:test="http://typo3.org/ns/TYPO3Fluid/Fluid/Tests/Functional/Fixtures/ViewHelpers"><f:cache.disable /><f:layout name="NamespaceInheritanceLayout" /><f:section name="Main"><test:tagBasedTest location="Template" /></f:section>',
[],
[],
],
// @todo this should probably not work
'namespace inherited from template to dynamic layout' => [
'<html xmlns:test="http://typo3.org/ns/TYPO3Fluid/Fluid/Tests/Functional/Fixtures/ViewHelpers"><f:layout name="{myLayout}" /><f:section name="Main"><test:tagBasedTest location="Template" /></f:section>',
'<html xmlns:test="http://typo3.org/ns/TYPO3Fluid/Fluid/Tests/Functional/Fixtures/ViewHelpers"><f:cache.disable /><f:layout name="{myLayout}" /><f:section name="Main"><test:tagBasedTest location="Template" /></f:section>',
[],
['myLayout' => 'NamespaceInheritanceLayout'],
],
Expand All @@ -50,7 +50,7 @@ public static function namespacesAreInheritedToLayoutAndPartialsDataProvider():
#[DataProvider('namespacesAreInheritedToLayoutAndPartialsDataProvider')]
public function namespacesAreInheritedToLayoutAndPartials(string $source, array $predefinedNamespaces, array $variables): void
{
$expectedResult = '<div location="Layout" />' . "\n\n" . '<div location="Template" />' . "\n\n" . '<div location="NestedPartial" />' . "\n\n" . '<div location="Partial" />' . "\n\n";
$expectedResult = "\n" . '<div location="Layout" />' . "\n\n" . '<div location="Template" />' . "\n\n\n\n" . '<div location="NestedPartial" />' . "\n\n" . '<div location="Partial" />' . "\n\n";

// Uncached
$view = new TemplateView();
Expand All @@ -62,15 +62,7 @@ public function namespacesAreInheritedToLayoutAndPartials(string $source, array
$view->getRenderingContext()->getTemplatePaths()->setPartialRootPaths([__DIR__ . '/../../Fixtures/Partials/']);
self::assertSame($expectedResult, $view->render());

// Cached
$view = new TemplateView();
$view->getRenderingContext()->setCache(self::$cache);
$view->getRenderingContext()->getViewHelperResolver()->addNamespaces($predefinedNamespaces);
$view->assignMultiple($variables);
$view->getRenderingContext()->getTemplatePaths()->setTemplateSource($source);
$view->getRenderingContext()->getTemplatePaths()->setLayoutRootPaths([__DIR__ . '/../../Fixtures/Layouts/']);
$view->getRenderingContext()->getTemplatePaths()->setPartialRootPaths([__DIR__ . '/../../Fixtures/Partials/']);
self::assertSame($expectedResult, $view->render());
// @todo Cached state is currently not relevant here, since caching needs to be disabled for all affected templates to get robust testing results
}

public static function namespaceDefinedInParentNotValidInChildrenDataProvider(): array
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<f:cache.disable />
<test:tagBasedTest location="Layout" />

<f:render section="Main" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<f:cache.disable />
<test:tagBasedTest location="NestedPartial" />
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<f:cache.disable />
<f:render partial="NamespaceInheritanceNestedPartial" />
<test:tagBasedTest location="Partial" />

0 comments on commit d00ef83

Please sign in to comment.