Add tests for template functions: setData, addData, addFunction

Signed-off-by: Atul Pratap Singh <atulpratapsingh05@gmail.com>
This commit is contained in:
Atul Pratap Singh 2016-01-15 09:38:48 +05:30
parent 704b02306b
commit b725916252
3 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,3 @@
<?php
echo $variable1;
echo $variable2;

View File

@ -0,0 +1,2 @@
<?php
echo hello($variable);

View File

@ -15,6 +15,64 @@ require_once 'test/PMATestCase.php';
*/
class TemplateTest extends PMATestCase
{
/**
* Test for setData
*
* @return void
*/
public function testSetData()
{
$template = PMA\libraries\Template::get('test/echo');
$template->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
*