Skip to content

Commit

Permalink
updated tests for custom extension
Browse files Browse the repository at this point in the history
  • Loading branch information
dxprog committed Oct 28, 2015
1 parent 19fb6ea commit 97d156c
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions tests/Dust/FilesystemTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class FilesystemTest extends DustTestBase {
public static $dir;

public static function setUpBeforeClass() {
FilesystemTest::$dir = sys_get_temp_dir();
if (FilesystemTest::$dir[strlen(FilesystemTest::$dir) - 1] != '/') FilesystemTest::$dir .= '/';
Expand All @@ -18,8 +18,14 @@ public static function setUpBeforeClass() {
//add child template
$fileRes = file_put_contents(FilesystemTest::$dir . '/childTemplate.dust', '{>baseTemplate/}{<two}newTwo{/two}{<three}newThree{/three}');
if ($fileRes === false) throw new DustException('Unable to create template');

// Add template with custom extension
$fileRes = file_put_contents(FilesystemTest::$dir . '/simpleTemplate.tl', 'line1{~n}line2');
if ($fileRes === false) {
throw new DustException('Unable to create template');
}
}

public static function deleteTree($dir) {
foreach (scandir($dir) as $file) {
if ($file != '.' && $file != '..') {
Expand All @@ -29,23 +35,31 @@ public static function deleteTree($dir) {
}
return rmdir($dir);
}

public static function tearDownAfterClass() {
if (!FilesystemTest::deleteTree(FilesystemTest::$dir)) throw new DustException('Unable to delete dir: ' . FilesystemTest::$dir);
}

public function testSimpleBlock() {
//just run the child, it should auto-find the base
$compiled = $this->dust->compileFile(FilesystemTest::$dir . '/childTemplate');
$expected = "before\noneDefault...newTwo...newThree\nafter";
$this->assertEquals($expected, $this->dust->renderTemplate($compiled, (object)[]));
}

public function testIncludedDirectories() {
//add the dir
$this->dust->includedDirectories[] = FilesystemTest::$dir;
//now have something call the child
$this->assertTemplate("Begin - before\noneDefault...newTwo...newThree\nafter - End", 'Begin - {>childTemplate/} - End', (object)[]);
}


public function testCustomFileExtension() {
$dust = new Dust(null, null, [ 'extension' => 'tl' ]);
$dust->includedDirectories[] = FilesystemTest::$dir;
$template = $dust->compile('{>simpleTemplate/}');
$render = $dust->renderTemplate($template, (object)[]);
$this->assertEquals($render, "line1\nline2");
}

}

0 comments on commit 97d156c

Please sign in to comment.