From a121d1974dfad754b44b055133f77a24e1307850 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Tue, 20 Mar 2018 19:03:06 +0100 Subject: [PATCH] improve unit tests --- temp.txt | 1 + test/TplBlockTest.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 temp.txt diff --git a/temp.txt b/temp.txt new file mode 100644 index 0000000..0f130bc --- /dev/null +++ b/temp.txt @@ -0,0 +1 @@ +Hello {{name}} \ No newline at end of file diff --git a/test/TplBlockTest.php b/test/TplBlockTest.php index 401cbb1..948128f 100644 --- a/test/TplBlockTest.php +++ b/test/TplBlockTest.php @@ -23,5 +23,36 @@ class TplBlockTest extends TestCase{ ); $this->assertEquals("Hello Gnieark", $tpl->apply_tpl_str("Hello {{name}}")); } + //test from a file + public function testParseFromFile(){ + file_put_contents("temp.txt","Hello {{name}}"); + $tpl = new TplBlock(); + $tpl->add_vars(array( + "name" => "Gnieark", + "title" => "Monsieur", + "firstname" => "Grouik" + ) + ); + $this->assertEquals("Hello Gnieark", $tpl->apply_tpl_file("temp.txt")); + } + + //test blocs + public function testBlocs(){ + $str = " + Bhah blah wpooie456 + + have to be shown + + + WONT to be shown + + "; + $tpl = new TplBlock(); + $tpl2 = new TplBlock("bloc"); + $tpl->add_sub_block($tpl2); + $str = $tpl->apply_tpl_str($str); + $this->assertContains('have',$str); + $this->assertFalse(strpos("WONT",$str)); + } } \ No newline at end of file