Add tests for template functions: setData, addData, addFunction
Signed-off-by: Atul Pratap Singh <atulpratapsingh05@gmail.com>
This commit is contained in:
parent
704b02306b
commit
b725916252
3
templates/test/add_data.phtml
Normal file
3
templates/test/add_data.phtml
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
echo $variable1;
|
||||
echo $variable2;
|
||||
2
templates/test/add_function.phtml
Normal file
2
templates/test/add_function.phtml
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
echo hello($variable);
|
||||
@ -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
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user