-
-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathControls.Checkbox.render.phpt
More file actions
82 lines (55 loc) · 2.33 KB
/
Controls.Checkbox.render.phpt
File metadata and controls
82 lines (55 loc) · 2.33 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
<?php
/**
* Test: Nette\Forms\Controls\Checkbox.
*/
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, int $count = null): string
{
return strtoupper($s);
}
}
test(function () {
$form = new Form;
$input = $form->addCheckbox('on', 'Label');
Assert::null($input->getLabel());
Assert::type(Html::class, $input->getControl());
Assert::same('<label for="frm-on"><input type="checkbox" name="on" id="frm-on">Label</label>', (string) $input->getControl());
Assert::type(Html::class, $input->getLabelPart());
Assert::same('<label for="frm-on">Label</label>', (string) $input->getLabelPart());
Assert::type(Html::class, $input->getControlPart());
Assert::same('<input type="checkbox" name="on" id="frm-on">', (string) $input->getControlPart());
$input->setCurrentValue(true);
Assert::same('<label for="frm-on"><input type="checkbox" name="on" id="frm-on" checked>Label</label>', (string) $input->getControl());
Assert::same('<input type="checkbox" name="on" id="frm-on" checked>', (string) $input->getControlPart());
});
test(function () { // Html with translator
$form = new Form;
$input = $form->addCheckbox('on', 'Label');
$input->setTranslator(new Translator);
Assert::same('<label for="frm-on"><input type="checkbox" name="on" id="frm-on">Label</label>', (string) $input->getControl());
});
test(function () { // validation rules
$form = new Form;
$input = $form->addCheckbox('on')->setRequired('required');
Assert::same('<label for="frm-on"><input type="checkbox" name="on" id="frm-on" required data-nette-rules=\'[{"op":":filled","msg":"required"}]\'></label>', (string) $input->getControl());
});
test(function () { // container
$form = new Form;
$container = $form->addContainer('container');
$input = $container->addCheckbox('on');
Assert::same('<label for="frm-container-on"><input type="checkbox" name="container[on]" id="frm-container-on"></label>', (string) $input->getControl());
});
test(function () { // rendering options
$form = new Form;
$input = $form->addCheckbox('on');
Assert::same('checkbox', $input->getOption('type'));
Assert::null($input->getOption('rendered'));
$input->getControl();
Assert::true($input->getOption('rendered'));
});