Added Tests to prevent future regression
authorGrégoire Pineau <lyrixx@lyrixx.info>
Sat, 31 Aug 2013 23:06:11 +0000 (01:06 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Mon, 2 Sep 2013 12:28:12 +0000 (14:28 +0200)
test/Twig/Tests/Loader/FilesystemTest.php
test/Twig/Tests/Loader/Fixtures/themes/theme1/blocks.html.twig [new file with mode: 0644]
test/Twig/Tests/Loader/Fixtures/themes/theme2/blocks.html.twig [new file with mode: 0644]

index 3ca580b..13849b3 100644 (file)
@@ -124,4 +124,20 @@ class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase
         // get index.html from the main namespace
         $this->assertEquals("path\n", $loader->getSource('index.html'));
     }
+
+    public function testLoadTemplateAndRenderBlockWithCache()
+    {
+        $loader = new Twig_Loader_Filesystem(array());
+        $loader->addPath(dirname(__FILE__).'/Fixtures/themes/theme2');
+        $loader->addPath(dirname(__FILE__).'/Fixtures/themes/theme1');
+        $loader->addPath(dirname(__FILE__).'/Fixtures/themes/theme1', 'default_theme');
+
+        $twig = new Twig_Environment($loader);
+
+        $template = $twig->loadTemplate('blocks.html.twig');
+        $this->assertSame('block from theme 1', $template->renderBlock('b1', array()));
+
+        $template = $twig->loadTemplate('blocks.html.twig');
+        $this->assertSame('block from theme 2', $template->renderBlock('b2', array()));
+    }
 }
diff --git a/test/Twig/Tests/Loader/Fixtures/themes/theme1/blocks.html.twig b/test/Twig/Tests/Loader/Fixtures/themes/theme1/blocks.html.twig
new file mode 100644 (file)
index 0000000..dd0cbc2
--- /dev/null
@@ -0,0 +1,3 @@
+{% block b1 %}block from theme 1{% endblock %}
+
+{% block b2 %}block from theme 1{% endblock %}
diff --git a/test/Twig/Tests/Loader/Fixtures/themes/theme2/blocks.html.twig b/test/Twig/Tests/Loader/Fixtures/themes/theme2/blocks.html.twig
new file mode 100644 (file)
index 0000000..07cf9db
--- /dev/null
@@ -0,0 +1,3 @@
+{% use '@default_theme/blocks.html.twig' %}
+
+{% block b2 %}block from theme 2{% endblock %}