root/trunk/tests/Renderer/SmartyTest.php

Revision 279, 2.0 kB (checked in by sfuchs, 3 years ago)

added Renderer_Flexy, Renderer_Savant3, Renderer_Smarty (including unit tests)
fixes docblock in Renderer_PhpTal

Line 
1 <?
2
3     require_once SMARTY_DIR . 'Smarty.class.php';
4
5     class Renderer_SmartyTest extends PHPUnit2_Framework_TestCase {
6
7         protected $template;
8
9         public function test_simple() {
10
11             $template = new Smarty();
12             $template->template_dir = 'Renderer/res/';
13             $template->compile_dir = 'Renderer/res/templates_c';
14             $template->assign('name', 'sven');
15
16             $expected = '<html><body><p>sven</p></body></html>';
17             $result = $template->fetch('test.smarty.simple.tpl');
18             $result = self::stripWhitespace($result);
19
20             $this->assertSameVerbose($expected, $result);
21         }
22
23         public function test_form_1() {
24
25             $definition = array('name' => array('type' => 'String'));
26             $form = patForms::createForm($definition, array('name' => 'test'));
27             $form->setRenderer(patForms::createRenderer("Smarty"));
28
29             $template = $form->renderForm(array(
30                 'tmplDir' => 'Renderer/res',
31                 'compileDir' => 'Renderer/res/templates_c',
32             ));
33
34             $expected = '<form name="test" method="post" ><input name="name" type="text" value="" /></form>';
35             $result = $template->fetch('test.smarty.form.tpl');
36
37             $result = self::stripAction($result);
38             $result = self::stripElementId($result);
39             $result = self::stripWhitespace($result);
40
41             $this->assertSameVerbose($expected, $result);
42         }
43
44         static protected function stripAction($str) {
45
46             return preg_replace('!action="[^\"]*"!', '', $str);
47         }
48
49         protected function stripElementId($element) {
50
51             return preg_replace('!id="pfo[a-zA-Z0-9]*" ?!', '', $element);
52         }
53
54         static protected function stripWhitespace($str) {
55
56             return preg_replace('|[\n\r\t]*|', '', $str);
57         }
58
59         protected function assertSameVerbose($expected, $result) {
60
61             try {
62                 $this->assertTrue($expected == $result);
63             } catch(Exception $e) {
64                 $lf = php_sapi_name() == 'cli' ? "\n" : '<br>';
65                 echo $lf . $lf;
66                 echo 'expected was: ' . htmlentities($expected) . $lf;
67                 echo 'result was: ' . htmlentities($result) . $lf . $lf;
68                 throw($e);
69             }
70         }
71     }
72
73 ?>
Note: See TracBrowser for help on using the browser.