root/trunk/tests/Renderer/Savant3Test.php

Revision 279, 2.7 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     require_once 'Savant3.php';
3
4     class Renderer_Savant3Test extends PHPUnit2_Framework_TestCase {
5
6         protected $template;
7
8         public function test_simple() {
9
10             $template = new Savant3();
11             $template->setTemplate('test.savant.simple.tpl');
12             $template->setPath('template', 'Renderer/res/');
13             $template->assign('name', 'sven');
14
15             $expected = '<html><body><p>sven</p></body></html>';
16             $result = $template->fetch();
17             $result = self::stripWhitespace($result);
18
19             $this->assertSameVerbose($expected, $result);
20         }
21
22         public function test_form_1() {
23
24             $definition = array('name' => array('type' => 'String'));
25             $form = patForms::createForm($definition, array('name' => 'test'));
26             $form->setRenderer(patForms::createRenderer("Savant3", $args));
27
28             $template = $form->renderForm(array(
29                 'tmplDir' => 'Renderer/res',
30                 'tmplFile' => 'test.savant.form.tpl',
31             ));
32
33             $expected = '<form name="test" method="post" ><input name="name" type="text" value="" /></form>';
34             $result = $template->fetch();
35
36             $result = self::stripAction($result);
37             $result = self::stripElementId($result);
38             $result = self::stripWhitespace($result);
39
40             $this->assertSameVerbose($expected, $result);
41         }
42
43         public function test_form_2() {
44
45             $template = new Savant3();
46             $template->setTemplate('test.savant.form.tpl');
47             $template->setPath('template', 'Renderer/res/');
48
49             $definition = array('name' => array('type' => 'String'));
50             $form = patForms::createForm($definition, array('name' => 'test'));
51             $form->setRenderer(patForms::createRenderer("Savant3", $args));
52
53             $template = $form->renderForm($template);
54
55             $expected = '<form name="test" method="post" ><input name="name" type="text" value="" /></form>';
56             $result = $template->fetch();
57
58             $result = self::stripAction($result);
59             $result = self::stripElementId($result);
60             $result = self::stripWhitespace($result);
61
62             $this->assertSameVerbose($expected, $result);
63         }
64
65         static protected function stripAction($str) {
66
67             return preg_replace('!action="[^\"]*"!', '', $str);
68         }
69
70         protected function stripElementId($element) {
71
72             return preg_replace('!id="pfo[a-zA-Z0-9]*" ?!', '', $element);
73         }
74
75         static protected function stripWhitespace($str) {
76
77             return preg_replace('|[\n\r\t]*|', '', $str);
78         }
79
80         protected function assertSameVerbose($expected, $result) {
81
82             try {
83                 $this->assertTrue($expected == $result);
84             } catch(Exception $e) {
85                 $lf = php_sapi_name() == 'cli' ? "\n" : '<br>';
86                 echo $lf . $lf;
87                 echo 'expected was: ' . htmlentities($expected) . $lf;
88                 echo 'result was: ' . htmlentities($result) . $lf . $lf;
89                 throw($e);
90             }
91         }
92     }
93
94 ?>
Note: See TracBrowser for help on using the browser.