-
-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathFormMacros.forms.phpt
More file actions
58 lines (44 loc) · 1.43 KB
/
FormMacros.forms.phpt
File metadata and controls
58 lines (44 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* Test: FormMacros.
*/
declare(strict_types=1);
use Nette\Bridges\FormsLatte\FormMacros;
use Nette\Forms\Form;
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
class MyControl extends Nette\Forms\Controls\BaseControl
{
public function getLabel($c = null)
{
return '<label>My</label>';
}
public function getControl()
{
return '<input name=My>';
}
}
$form = new Form;
$form->getElementPrototype()->addClass('form-class');
$form->addHidden('id');
$form->addText('username', 'Username:'); // must have just one textfield to generate IE fix
$form['username']->getControlPrototype()->addClass('control-class');
$form->addRadioList('sex', 'Sex:', ['m' => 'male', 'f' => 'female']);
$form->addSelect('select', null, ['m' => 'male', 'f' => 'female']);
$form->addTextArea('area', null)->setDefaultValue('one<two');
$form->addCheckbox('checkbox', 'Checkbox');
$form->addCheckboxList('checklist', 'CheckboxList:', ['m' => 'male', 'f' => 'female']);
$form->addSubmit('send', 'Sign in');
$form['my'] = new MyControl;
$latte = new Latte\Engine;
FormMacros::install($latte->getCompiler());
$latte->addProvider('uiControl', ['myForm' => $form]);
$form['username']->addError('error');
Assert::matchFile(
__DIR__ . '/expected/FormMacros.forms.phtml',
$latte->compile(__DIR__ . '/templates/forms.latte')
);
Assert::matchFile(
__DIR__ . '/expected/FormMacros.forms.html',
$latte->renderToString(__DIR__ . '/templates/forms.latte')
);