From d4b356dc294f62e7aec73a36880b2ae71209a1d3 Mon Sep 17 00:00:00 2001 From: Victor Welling Date: Tue, 28 Aug 2018 15:19:33 +0200 Subject: [PATCH] Added test for nested optional tags --- tests/Fixtures/Templates/optional_nested.twig | 11 +++++++++++ tests/TwigIntegrationTest.php | 13 +++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/Fixtures/Templates/optional_nested.twig diff --git a/tests/Fixtures/Templates/optional_nested.twig b/tests/Fixtures/Templates/optional_nested.twig new file mode 100644 index 0000000..c6163ea --- /dev/null +++ b/tests/Fixtures/Templates/optional_nested.twig @@ -0,0 +1,11 @@ +{## + # Nested 'optional' tags should not affect their parents. + #} +header +{% optional %} + {% optional %} + {% include 'runtime_exception.twig' %} + {% endoptional %} + not affected +{% endoptional %} +footer diff --git a/tests/TwigIntegrationTest.php b/tests/TwigIntegrationTest.php index fb71e88..3332da3 100644 --- a/tests/TwigIntegrationTest.php +++ b/tests/TwigIntegrationTest.php @@ -119,6 +119,19 @@ public function testOptionalBlocksShouldNotSuppressUnknownVariables() $this->renderTemplate('optional_unknown_variable.twig'); } + /** + * @return void + */ + public function testNestedOptionalBlocksShouldNotAffectedParents() + { + $output = $this->renderTemplate('optional_nested.twig'); + + $this->assertContains('header', $output); + $this->assertNotContains('should not be rendered', $output); + $this->assertContains('not affected', $output); + $this->assertContains('footer', $output); + } + /** * @param string $template *