From 726a2d2695f35c0bbcc71a6827d2987ed0dabf5e Mon Sep 17 00:00:00 2001 From: Ian Jenkins Date: Wed, 19 Sep 2018 15:33:28 +0100 Subject: [PATCH] Add more tests to avoid regression --- bin/install-wp-tests.sh | 0 tests/namespaced/test-namespaced.twig | 1 + tests/test-timber-loader.php | 34 +++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) mode change 100644 => 100755 bin/install-wp-tests.sh create mode 100644 tests/namespaced/test-namespaced.twig diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh old mode 100644 new mode 100755 diff --git a/tests/namespaced/test-namespaced.twig b/tests/namespaced/test-namespaced.twig new file mode 100644 index 000000000..79e526307 --- /dev/null +++ b/tests/namespaced/test-namespaced.twig @@ -0,0 +1 @@ +This is a namespaced template. diff --git a/tests/test-timber-loader.php b/tests/test-timber-loader.php index 648082142..812f0340c 100644 --- a/tests/test-timber-loader.php +++ b/tests/test-timber-loader.php @@ -130,4 +130,38 @@ function testTwigLoadsFromLocationWithNamespace(){ $this->assertEquals('', trim($str)); } + function testTwigLoadsFromLocationWithAndWithoutNamespaces(){ + Timber::$locations = array( 'namespaced' => __DIR__.'/namespaced', __DIR__ . '/assets' ); + + // Namespaced location + $str = Timber::compile('@namespaced/test-namespaced.twig'); + $this->assertEquals('This is a namespaced template.', trim($str)); + + // Non namespaced location + $str = Timber::compile('thumb-test.twig'); + $this->assertEquals('', trim($str)); + } + + function testTwigLoadsFromLocationWithAndWithoutNamespacesAndDirs(){ + Timber::$dirname = array('foo', 'views'); + Timber::$locations = array( 'namespaced' => __DIR__.'/namespaced', __DIR__ . '/assets' ); + + // Namespaced location + $str = Timber::compile('@namespaced/test-namespaced.twig'); + $this->assertEquals('This is a namespaced template.', trim($str)); + + // Non namespaced location + $str = Timber::compile('thumb-test.twig'); + $this->assertEquals('', trim($str)); + + if (!file_exists(get_template_directory().'/foo')) { + mkdir(get_template_directory().'/foo', 0777, true); + } + copy(__DIR__.'/assets/single-foo.twig', get_template_directory().'/foo/single-foo.twig'); + + // Dir + $str = Timber::compile('single-foo.twig'); + $this->assertEquals('I am single-foo', trim($str)); + } + }