From b725916252cd6877232841cf34d6765d95edab6c Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Fri, 15 Jan 2016 09:38:48 +0530 Subject: [PATCH] Add tests for template functions: setData, addData, addFunction Signed-off-by: Atul Pratap Singh --- templates/test/add_data.phtml | 3 ++ templates/test/add_function.phtml | 2 ++ test/classes/TemplateTest.php | 58 +++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 templates/test/add_data.phtml create mode 100644 templates/test/add_function.phtml diff --git a/templates/test/add_data.phtml b/templates/test/add_data.phtml new file mode 100644 index 0000000000..eee5ebe053 --- /dev/null +++ b/templates/test/add_data.phtml @@ -0,0 +1,3 @@ +setData( + array( + 'variable' => 'value' + ) + ); + $this->assertEquals('value', $template->render()); + } + + /** + * Test for addData + * + * @return void + */ + public function testAddData() + { + $template = PMA\libraries\Template::get('test/addData'); + $template->addData( + array( + 'variable1' => 'value1' + ) + ); + $template->addData( + array( + 'variable2' => 'value2' + ) + ); + $result = $template->render(); + $this->assertContains('value1', $result); + $this->assertContains('value2', $result); + } + + /** + * Test for addFunction + * + * @return void + */ + public function testAddFunction() + { + $template = PMA\libraries\Template::get('test/add_function'); + $template->addFunction('hello', function ($string) { + return 'hello ' . $string; + }); + $template->addData( + array( + 'variable' => 'world' + ) + ); + $this->assertEquals('hello world', $template->render()); + } + /** * Test for render *