| 1 |
<? |
|---|
| 2 |
|
|---|
| 3 |
class Renderer_FlexyTest extends PHPUnit2_Framework_TestCase { |
|---|
| 4 |
|
|---|
| 5 |
protected $template; |
|---|
| 6 |
|
|---|
| 7 |
public function test_simple() { |
|---|
| 8 |
|
|---|
| 9 |
$template = new HTML_Template_Flexy(array( |
|---|
| 10 |
'templateDir' => 'Renderer/res', |
|---|
| 11 |
'compileDir' => 'Renderer/res/templates_c', |
|---|
| 12 |
)); |
|---|
| 13 |
$template->compile('test.flexy.simple.tpl'); |
|---|
| 14 |
$template->setData('name', 'sven'); |
|---|
| 15 |
|
|---|
| 16 |
$expected = '<html><body><p>sven</p></body></html>'; |
|---|
| 17 |
$result = $template->bufferedOutputObject(); |
|---|
| 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("Flexy")); |
|---|
| 28 |
|
|---|
| 29 |
$template = $form->renderForm(array( |
|---|
| 30 |
'tmplFile' => 'test.flexy.form.tpl', |
|---|
| 31 |
'tmplDir' => 'Renderer/res', |
|---|
| 32 |
'compileDir' => 'Renderer/res/templates_c', |
|---|
| 33 |
)); |
|---|
| 34 |
|
|---|
| 35 |
$expected = '<form name="test" method="post" ><input name="name" type="text" value="" /></form>'; |
|---|
| 36 |
$result = $template->bufferedOutputObject(); |
|---|
| 37 |
|
|---|
| 38 |
$result = self::stripAction($result); |
|---|
| 39 |
$result = self::stripElementId($result); |
|---|
| 40 |
$result = self::stripWhitespace($result); |
|---|
| 41 |
|
|---|
| 42 |
$this->assertSameVerbose($expected, $result); |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
static protected function stripAction($str) { |
|---|
| 46 |
|
|---|
| 47 |
return preg_replace('!action="[^\"]*"!', '', $str); |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
protected function stripElementId($element) { |
|---|
| 51 |
|
|---|
| 52 |
return preg_replace('!id="pfo[a-zA-Z0-9]*" ?!', '', $element); |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
static protected function stripWhitespace($str) { |
|---|
| 56 |
|
|---|
| 57 |
return preg_replace('|[\n\r\t]*|', '', $str); |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
protected function assertSameVerbose($expected, $result) { |
|---|
| 61 |
|
|---|
| 62 |
try { |
|---|
| 63 |
$this->assertTrue($expected == $result); |
|---|
| 64 |
} catch(Exception $e) { |
|---|
| 65 |
$lf = php_sapi_name() == 'cli' ? "\n" : '<br>'; |
|---|
| 66 |
echo $lf . $lf; |
|---|
| 67 |
echo 'expected was: ' . htmlentities($expected) . $lf; |
|---|
| 68 |
echo 'result was: ' . htmlentities($result) . $lf . $lf; |
|---|
| 69 |
throw($e); |
|---|
| 70 |
} |
|---|
| 71 |
} |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
?> |
|---|