-
-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathControls.Button.render.phpt
More file actions
121 lines (83 loc) 路 3.6 KB
/
Copy pathControls.Button.render.phpt
File metadata and controls
121 lines (83 loc) 路 3.6 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* Test: Nette\Forms\Controls\Button & SubmitButton
*/
declare(strict_types=1);
use Nette\Forms\Form;
use Nette\Utils\Html;
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
class Translator implements Nette\Localization\ITranslator
{
public function translate($s, ...$parameters): string
{
return strtoupper($s);
}
}
test(function () {
$form = new Form;
$input = $form->addButton('button', 'Caption');
Assert::null($input->getLabel());
Assert::type(Html::class, $input->getControl());
Assert::same('<input type="button" name="button" value="Caption">', (string) $input->getControl());
Assert::same('<input type="button" name="button" value="Another caption">', (string) $input->getControl('Another caption'));
});
test(function () { // translator
$form = new Form;
$input = $form->addButton('button', 'Caption');
$input->setTranslator(new Translator);
Assert::same('<input type="button" name="button" value="CAPTION">', (string) $input->getControl());
Assert::same('<input type="button" name="button" value="ANOTHER CAPTION">', (string) $input->getControl('Another caption'));
});
test(function () { // Html with translator
$form = new Form;
$input = $form->addButton('button', Html::el('b', 'Caption'));
$input->setTranslator(new Translator);
Assert::same('<input type="button" name="button" value="<b>Caption</b>">', (string) $input->getControl());
Assert::same('<input type="button" name="button" value="<b>Another label</b>">', (string) $input->getControl(Html::el('b', 'Another label')));
});
test(function () { // no validation rules
$form = new Form;
$input = $form->addButton('button', 'Caption')->setRequired('required');
Assert::same('<input type="button" name="button" value="Caption">', (string) $input->getControl());
});
test(function () { // container
$form = new Form;
$container = $form->addContainer('container');
$input = $container->addButton('button', 'Caption');
Assert::same('<input type="button" name="container[button]" value="Caption">', (string) $input->getControl());
});
test(function () { // SubmitButton
$form = new Form;
$input = $form->addSubmit('button', 'Caption');
Assert::null($input->getLabel());
Assert::type(Html::class, $input->getControl());
Assert::same('<input type="submit" name="button" value="Caption">', (string) $input->getControl());
Assert::same('<input type="submit" name="button" value="Another caption">', (string) $input->getControl('Another caption'));
});
test(function () { // SubmitButton with scope
$form = new Form;
$input = $form->addSubmit('button', 'Caption')->setValidationScope([]);
Assert::same('<input type="submit" name="button" value="Caption" formnovalidate>', (string) $input->getControl());
});
test(function () { // SubmitButton with scope
$form = new Form;
$text = $form->addText('text');
$select = $form->addSelect('select');
$input = $form->addSubmit('button', 'Caption')->setValidationScope([$text, $select]);
Assert::same('<input type="submit" name="button" value="Caption" formnovalidate data-nette-validation-scope=\'["text","select"]\'>', (string) $input->getControl());
});
test(function () { // forced ID
$form = new Form;
$input = $form->addButton('button', 'Caption');
$input->setHtmlId($input->getHtmlId());
Assert::same('<input type="button" name="button" id="frm-button" value="Caption">', (string) $input->getControl());
});
test(function () { // rendering options
$form = new Form;
$input = $form->addButton('button');
Assert::same('button', $input->getOption('type'));
Assert::null($input->getOption('rendered'));
$input->getControl();
Assert::true($input->getOption('rendered'));
});