Skip to content

Commit

Permalink
Add more tests to avoid regression
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Jenkins committed Sep 19, 2018
1 parent aea48b9 commit 726a2d2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Empty file modified bin/install-wp-tests.sh 100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions tests/namespaced/test-namespaced.twig
@@ -0,0 +1 @@
This is a namespaced template.
34 changes: 34 additions & 0 deletions tests/test-timber-loader.php
Expand Up @@ -130,4 +130,38 @@ function testTwigLoadsFromLocationWithNamespace(){
$this->assertEquals('<img src="" />', 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('<img src="" />', 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('<img src="" />', 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));
}

}

0 comments on commit 726a2d2

Please sign in to comment.