Smarty Modular Templates

I use Smarty Templates, and I was just curious to find out if I have any testing mechanism. The number of different template files is increasing, as well as the complexity. Ideally, I would like to check the final HTML output that comes in to make sure that the templates / conditions / variables used in Smarty work as expected. Is there any way to do this?

+4
source share
1 answer

You can use the Smarty fetch() function. Below is a free example / pseudo code.

Testing Template

 {* foo.tpl *} <html> <head></head> <body>{$hi}</body> </html> 

Expected Result

 <!-- foo.html --> <html> <head></head> <body>Hello World!</body> </html> 

Class TestCase

 class FooTemplateTestCase extends TestCase { protected $_view; public function setup(){ $this->_view = new Smarty(); // setup smarty options, caching, etc } public function test(){ $this->_view->assign('hi', 'Hello World!'); $output = $this->_view->fetch('foo.tpl'); $expected_output = file_get_contents('foo.html'); $this->assertEquals($expected_output, $output); } } 
+4
source

All Articles