Skip to content

Commit 00cd58d

Browse files
committed
tests: added latte tests
1 parent 0344d58 commit 00cd58d

13 files changed

+547
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/**
4+
* Test: Nette\Bridges\FormsLatte\FormMacros: GET form
5+
*
6+
* @author Filip Procházka
7+
*/
8+
9+
use Nette\Bridges\FormsLatte\FormMacros;
10+
use Nette\Forms\Form;
11+
use Tester\Assert;
12+
13+
14+
require __DIR__ . '/../bootstrap.php';
15+
16+
$form = new Form;
17+
$form->setMethod('GET');
18+
$form->action = 'http://example.com/?do=foo-submit#toc';
19+
20+
ob_start();
21+
FormMacros::renderFormBegin($form, array());
22+
Assert::same('<form action="http://example.com/#toc" method="get">', ob_get_clean());
23+
24+
ob_start();
25+
FormMacros::renderFormEnd($form);
26+
Assert::match('<div><input type="hidden" name="do" value="foo-submit"><!--[if IE]><input type=IEbug disabled style="display:none"><![endif]--></div>
27+
</form>
28+
', ob_get_clean());
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/**
4+
* Test: Nette\Latte\Engine and FormMacros: {formContainer}
5+
*
6+
* @author Miloslav Hůla
7+
*/
8+
9+
use Nette\Latte,
10+
Nette\Forms\Form,
11+
Nette\Bridges\FormsLatte\FormMacros,
12+
Tester\Assert;
13+
14+
15+
require __DIR__ . '/../bootstrap.php';
16+
17+
18+
$form = new Form;
19+
$form->addText('input1', 'Input 1');
20+
21+
$cont1 = $form->addContainer('cont1');
22+
$cont1->addText('input2', 'Input 2');
23+
$cont1->addText('input3', 'Input 3');
24+
25+
$cont2 = $cont1->addContainer('cont2');
26+
$cont2->addCheckbox('input4', 'Input 4');
27+
$cont2->addCheckbox('input5', 'Input 5');
28+
$cont2->addCheckbox('input6', 'Input 6');
29+
30+
$cont1->addText('input7', 'Input 7');
31+
32+
$form->addSubmit('input8', 'Input 8');
33+
34+
35+
$latte = new Latte\Engine;
36+
FormMacros::install($latte->getCompiler());
37+
38+
Assert::matchFile(
39+
__DIR__ . '/expected/FormMacros.formContainer.phtml',
40+
$latte->compile(__DIR__ . '/templates/forms.formContainer.latte')
41+
);
42+
Assert::matchFile(
43+
__DIR__ . '/expected/FormMacros.formContainer.html',
44+
$latte->renderToString(
45+
__DIR__ . '/templates/forms.formContainer.latte',
46+
array('_control' => array('myForm' => $form))
47+
)
48+
);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/**
4+
* Test: Nette\Latte\Engine and FormMacros.
5+
*
6+
* @author David Grudl
7+
*/
8+
9+
use Nette\Latte,
10+
Nette\Forms\Form,
11+
Nette\Bridges\FormsLatte\FormMacros,
12+
Tester\Assert;
13+
14+
15+
require __DIR__ . '/../bootstrap.php';
16+
17+
18+
class MyControl extends Nette\Forms\Controls\BaseControl
19+
{
20+
function getLabel($c = NULL)
21+
{
22+
return '<label>My</label>';
23+
}
24+
25+
function getControl()
26+
{
27+
return '<input name=My>';
28+
}
29+
}
30+
31+
32+
$form = new Form;
33+
$form->addHidden('id');
34+
$form->addText('username', 'Username:'); // must have just one textfield to generate IE fix
35+
$form->addRadioList('sex', 'Sex:', array('m' => 'male', 'f' => 'female'));
36+
$form->addSelect('select', NULL, array('m' => 'male', 'f' => 'female'));
37+
$form->addTextArea('area', NULL)->setValue('one<two');
38+
$form->addCheckbox('checkbox', NULL);
39+
$form->addCheckboxList('checklist', NULL, array('m' => 'male', 'f' => 'female'));
40+
$form->addSubmit('send', 'Sign in');
41+
$form['my'] = new MyControl;
42+
43+
$latte = new Latte\Engine;
44+
FormMacros::install($latte->getCompiler());
45+
46+
$form['username']->addError('error');
47+
48+
Assert::matchFile(
49+
__DIR__ . '/expected/FormMacros.forms.phtml',
50+
$latte->compile(__DIR__ . '/templates/forms.latte')
51+
);
52+
Assert::matchFile(
53+
__DIR__ . '/expected/FormMacros.forms.html',
54+
$latte->renderToString(
55+
__DIR__ . '/templates/forms.latte',
56+
array('_control' => array('myForm' => $form))
57+
)
58+
);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/**
4+
* Test: Nette\Latte\Engine and FormMacros.
5+
*
6+
* @author David Grudl
7+
*/
8+
9+
use Nette\Latte,
10+
Nette\Forms\Form,
11+
Nette\Bridges\FormsLatte\FormMacros,
12+
Tester\Assert;
13+
14+
15+
require __DIR__ . '/../bootstrap.php';
16+
17+
18+
$form = new Form;
19+
$form->setMethod('get');
20+
$form->setAction('?arg=val');
21+
$form->addSubmit('send', 'Sign in');
22+
23+
$latte = new Latte\Engine;
24+
FormMacros::install($latte->getCompiler());
25+
26+
Assert::matchFile(
27+
__DIR__ . '/expected/FormMacros.get.phtml',
28+
$latte->compile(__DIR__ . '/templates/forms.get.latte')
29+
);
30+
Assert::matchFile(
31+
__DIR__ . '/expected/FormMacros.get.html',
32+
$latte->renderToString(
33+
__DIR__ . '/templates/forms.get.latte',
34+
array('_control' => array('myForm' => $form))
35+
)
36+
);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<form action="" method="post"><table>
2+
<tr>
3+
<th><label for="frm-input1">Input 1</label></th>
4+
<td><input type="text" name="input1" id="frm-input1" value=""></td>
5+
</tr>
6+
<tr>
7+
<th><label for="frm-cont1-input2">Input 2</label></th>
8+
<td><input type="text" name="cont1[input2]" id="frm-cont1-input2" value=""></td>
9+
</tr>
10+
<tr>
11+
<th><label for="frm-cont1-input3">Input 3</label></th>
12+
<td><input type="text" name="cont1[input3]" id="frm-cont1-input3" value=""></td>
13+
</tr>
14+
<tr>
15+
<th>Checkboxes</th>
16+
<td>
17+
<ol>
18+
<li><label for="frm-cont1-cont2-input4"><input type="checkbox" name="cont1[cont2][input4]" id="frm-cont1-cont2-input4">Input 4</label></li>
19+
<li><label for="frm-cont1-cont2-input5"><input type="checkbox" name="cont1[cont2][input5]" id="frm-cont1-cont2-input5">Input 5</label></li>
20+
<li><label for="frm-cont1-cont2-input6"><input type="checkbox" name="cont1[cont2][input6]" id="frm-cont1-cont2-input6">Input 6</label></li>
21+
</ol>
22+
</td>
23+
</tr>
24+
<tr>
25+
<th><label for="frm-cont1-input7">Input 7</label></th>
26+
<td><input type="text" name="cont1[input7]" id="frm-cont1-input7" value=""></td>
27+
</tr>
28+
<tr>
29+
<th></th>
30+
<td><input type="submit" name="input8" value="Input 8"></td>
31+
</tr>
32+
</table>
33+
</form>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
%A%
3+
//
4+
// main template
5+
//
6+
Nette\Bridges\FormsLatte\FormMacros::renderFormBegin($form = $_form = $_control["myForm"], array()) ?>
7+
<table>
8+
<tr>
9+
<th><?php if ($_label = $_form["input1"]->getLabel()) echo $_label ?></th>
10+
<td><?php echo $_form["input1"]->getControl() ?></td>
11+
</tr>
12+
<?php $_formStack[] = $_form; $formContainer = $_form = $_form["cont1"] ?>
13+
<tr>
14+
<th><?php if ($_label = $_form["input2"]->getLabel()) echo $_label ?></th>
15+
<td><?php echo $_form["input2"]->getControl() ?></td>
16+
</tr>
17+
<tr>
18+
<th><?php if ($_label = $_form["input3"]->getLabel()) echo $_label ?></th>
19+
<td><?php echo $_form["input3"]->getControl() ?></td>
20+
</tr>
21+
<tr>
22+
<th>Checkboxes</th>
23+
<td>
24+
<?php $_formStack[] = $_form; $formContainer = $_form = $_form["cont2"] ?> <ol>
25+
<?php $iterations = 0; foreach ($formContainer->controls AS $name => $field) { ?>
26+
<li><?php $_input = is_object($field) ? $field : $_form[$field]; echo $_input->getControl() ?></li>
27+
<?php $iterations++; } ?> </ol>
28+
<?php $_form = array_pop($_formStack) ?>
29+
</td>
30+
</tr>
31+
<tr>
32+
<th><?php if ($_label = $_form["input7"]->getLabel()) echo $_label ?></th>
33+
<td><?php echo $_form["input7"]->getControl() ?></td>
34+
</tr>
35+
<?php $_form = array_pop($_formStack) ?>
36+
<tr>
37+
<th><?php if ($_label = $_form["input8"]->getLabel()) echo $_label ?></th>
38+
<td><?php echo $_form["input8"]->getControl() ?></td>
39+
</tr>
40+
</table>
41+
<?php Nette\Bridges\FormsLatte\FormMacros::renderFormEnd($_form) ;
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<form action="" method="post" id="myForm" class="ajax">
2+
<input type="hidden" name="id" value="" title="Hello" size="10">
3+
4+
<br>
5+
6+
<input type="hidden" name="id" value="" title="Hello" size="10">
7+
<label for="frm-username">Username:</label>
8+
<input type="text" name="username" id="frm-username" value="" title="Hello" size="10"> error
9+
error
10+
<br>
11+
12+
<label for="frm-username" title="hello"> <input type="text" name="username" id="frm-username" value="" title="Hello" size="10"> </label>
13+
error <label for="frm-select"></label>
14+
<select name="select" id="frm-select" title="Hello" size="10"><option value="m">male</option><option value="f">female</option></select>
15+
16+
<br>
17+
18+
<label for="frm-select" title="hello"> <select name="select" id="frm-select" title="Hello" size="10"><option value="m">male</option><option value="f">female</option></select> </label>
19+
<label for="frm-area"></label>
20+
<textarea name="area" id="frm-area" title="Hello" size="10">one&lt;two</textarea>
21+
22+
<br>
23+
24+
<label for="frm-area" title="hello"> <textarea name="area" id="frm-area" title="Hello" size="10">one&lt;two</textarea> </label>
25+
26+
<input type="submit" name="send" value="Sign in" title="Hello" size="10">
27+
28+
<br>
29+
30+
<input type="submit" name="send" value="Sign in" title="Hello" size="10">
31+
32+
<label for="frm-username">Username:</label>
33+
34+
<LABEL title=hello for="frm-username">Name</LABEL>
35+
<input value=val type class="hello" name="username" id="frm-username">
36+
37+
<label for="frm-username"></label>
38+
<input type="text" name="username" id="frm-username" value="">
39+
40+
<label>My</label><input name=My>
41+
<div><!--[if IE]><input type=IEbug disabled style="display:none"><![endif]--></div>
42+
</form>
43+
44+
45+
<form action="" method="post"><div><input type="hidden" name="id" value=""><!--[if IE]><input type=IEbug disabled style="display:none"><![endif]--></div>
46+
</form>
47+
48+
49+
50+
<label for="frm-sex-m"> <input type="radio" name="sex" id="frm-sex-m" value="m"> male</label>
51+
<label title=hello for="frm-sex-m"> <input type="radio" name="sex" id="frm-sex-m" value="m"> </label>
52+
<label for="frm-sex-f"> <input type="radio" name="sex" id="frm-sex-f" value="f"> female</label>
53+
<label title=hello for="frm-sex-f"> <input type="radio" name="sex" id="frm-sex-f" value="f"> </label>
54+
55+
56+
<label for="frm-checkbox"> <input type="checkbox" name="checkbox" id="frm-checkbox"> Label</label>
57+
<label title=hello for="frm-checkbox"> <input type="checkbox" name="checkbox" id="frm-checkbox"> </label>
58+
<label title=hello for="frm-checkbox"> <input type="checkbox" name="checkbox" id="frm-checkbox"> </label>
59+
60+
61+
<label for="frm-checklist-m"> <input type="checkbox" name="checklist[]" id="frm-checklist-m" value="m"> male</label>
62+
<label for="frm-checklist-m"> <input title=hello type="checkbox" name="checklist[]" id="frm-checklist-m" value="m"> </label>
63+
<label for="frm-checklist-f"> <input type="checkbox" name="checklist[]" id="frm-checklist-f" value="f"> female</label>
64+
<label for="frm-checklist-f"> <input title=hello type="checkbox" name="checklist[]" id="frm-checklist-f" value="f"> </label>
65+
66+
67+
<form id="myForm" class="ajax" action="" method="post">
68+
<input type="text" name="username" id="frm-username" value="">
69+
<div><input type="hidden" name="id" value=""><!--[if IE]><input type=IEbug disabled style="display:none"><![endif]--></div>
70+
</form>
71+
72+
73+
<FORM action="" method="post">
74+
<input type="text" name="username" id="frm-username" value="">
75+
<div><input type="hidden" name="id" value=""><!--[if IE]><input type=IEbug disabled style="display:none"><![endif]--></div>
76+
</FORM>
77+
78+
79+
<select name="select" id="frm-select"><option value="m">male</option><option value="f">female</option></select>
80+
81+
82+
<textarea title="10" name="area" id="frm-area">one&lt;two</textarea>
83+
84+
85+
<select name="select" id="frm-select"><option value="m">male</option><option value="f">female</option></select>

0 commit comments

Comments
 (0)