require_once SMARTY_DIR . 'Smarty.class.php'; class Renderer_SmartyTest extends PHPUnit2_Framework_TestCase { protected $template; public function test_simple() { $template = new Smarty(); $template->template_dir = 'Renderer/res/'; $template->compile_dir = 'Renderer/res/templates_c'; $template->assign('name', 'sven'); $expected = '
sven
'; $result = $template->fetch('test.smarty.simple.tpl'); $result = self::stripWhitespace($result); $this->assertSameVerbose($expected, $result); } public function test_form_1() { $definition = array('name' => array('type' => 'String')); $form = patForms::createForm($definition, array('name' => 'test')); $form->setRenderer(patForms::createRenderer("Smarty")); $template = $form->renderForm(array( 'tmplDir' => 'Renderer/res', 'compileDir' => 'Renderer/res/templates_c', )); $expected = ''; $result = $template->fetch('test.smarty.form.tpl'); $result = self::stripAction($result); $result = self::stripElementId($result); $result = self::stripWhitespace($result); $this->assertSameVerbose($expected, $result); } static protected function stripAction($str) { return preg_replace('!action="[^\"]*"!', '', $str); } protected function stripElementId($element) { return preg_replace('!id="pfo[a-zA-Z0-9]*" ?!', '', $element); } static protected function stripWhitespace($str) { return preg_replace('|[\n\r\t]*|', '', $str); } protected function assertSameVerbose($expected, $result) { try { $this->assertTrue($expected == $result); } catch(Exception $e) { $lf = php_sapi_name() == 'cli' ? "\n" : '