-
-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathControls.SelectBox.isOk.phpt
More file actions
50 lines (35 loc) · 1.12 KB
/
Controls.SelectBox.isOk.phpt
File metadata and controls
50 lines (35 loc) · 1.12 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
<?php
/**
* Test: Nette\Forms\Controls\SelectBox::isOk()
*/
declare(strict_types=1);
use Nette\Forms\Form;
use Nette\Forms\Validator;
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
$form = new Form;
$select = $form->addSelect('foo', null, ['bar' => 'Bar']);
Assert::true($select->isOk());
$select->setDisabled(true);
Assert::true($select->isOk());
$select->setDisabled(false);
$select->setPrompt('Empty');
Assert::true($select->isOk());
$select->setPrompt(false);
$select->setValue('bar');
Assert::true($select->isOk());
$select->setValue(null);
$select->setItems([]);
Assert::true($select->isOk());
$select->setItems(['bar' => 'Bar']);
$select->getControlPrototype()->size = 2;
Assert::true($select->isOk());
$select->getControlPrototype()->size = 1;
Assert::false($select->isOk());
// error message is processed via Rules
$_SERVER['REQUEST_METHOD'] = 'POST';
Validator::$messages[Nette\Forms\Controls\SelectBox::VALID] = 'SelectBox "%label" must be filled.';
$form = new Form;
$form->addSelect('foo', 'Foo', ['bar' => 'Bar']);
$form->fireEvents();
Assert::same(['SelectBox "Foo" must be filled.'], $form->getErrors());