-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validator: added support for enums (#282)
Co-authored-by: martin.sedlacek <martin.sedlacek@motv.eu>
- Loading branch information
Showing
2 changed files
with
42 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,38 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Forms\Controls\BaseControl & enum | ||
* @phpVersion 8.1 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\Forms\Form; | ||
use Nette\Forms\Validator; | ||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
enum TestEnum: string | ||
{ | ||
case CASE_1 = 'case 1'; | ||
case CASE_2 = 'case 2'; | ||
} | ||
|
||
|
||
before(function () { | ||
Form::initialize(true); | ||
}); | ||
|
||
|
||
test('validators for enums', function () { | ||
$form = new Form; | ||
$input = $form->addText('text'); | ||
$input->setValue(TestEnum::CASE_1->value); | ||
|
||
Assert::true(Validator::validateEqual($input, TestEnum::CASE_1)); | ||
Assert::true(Validator::validateEqual($input, 'case 1')); | ||
Assert::false(Validator::validateEqual($input, TestEnum::CASE_2)); | ||
Assert::false(Validator::validateEqual($input, 1)); | ||
}); |