forked from nette/forms
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rules: allow Form::VALID only in the addConditionOn [fixes nette#95]
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Forms\Rules. | ||
*/ | ||
|
||
use Nette\Forms\Form; | ||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
test(function () { | ||
$form = new Form(); | ||
$form->addText('foo') | ||
->setRequired('fill foo'); | ||
$form->addText('bar') | ||
->addConditionOn($form['foo'], Form::VALID) | ||
->setRequired('fill bar'); | ||
|
||
$form->validate(); | ||
Assert::same(['fill foo'], $form->getErrors()); | ||
|
||
$form['foo']->setValue('abc'); | ||
$form->validate(); | ||
Assert::same(['fill bar'], $form->getErrors()); | ||
|
||
$form['bar']->setValue('abc'); | ||
$form->validate(); | ||
Assert::same([], $form->getErrors()); | ||
}); | ||
|
||
|
||
test(function () { | ||
|
||
$form = new Form(); | ||
|
||
Assert::exception(function () use ($form) { | ||
$form->addText('foo') | ||
->addRule(Form::VALID); | ||
}, 'Nette\InvalidArgumentException', 'You cannot use Form::VALID in the addRule method.'); | ||
}); | ||
|
||
|
||
test(function () { | ||
|
||
$form = new Form(); | ||
|
||
Assert::exception(function () use ($form) { | ||
$form->addText('foo') | ||
->addCondition(Form::VALID); | ||
}, 'Nette\InvalidArgumentException', 'You cannot use Form::VALID in the addCondition method.'); | ||
}); | ||
|
||
|
||
test(function () { | ||
|
||
$form = new Form(); | ||
|
||
Assert::exception(function () use ($form) { | ||
$form->addText('foo') | ||
->addRule(~Form::VALID); | ||
}, 'Nette\InvalidArgumentException', 'You cannot use Form::VALID in the addRule method.'); | ||
}); |