Skip to content

Commit

Permalink
Validator: added support for enums (#282)
Browse files Browse the repository at this point in the history
Co-authored-by: martin.sedlacek <[email protected]>
  • Loading branch information
2 people authored and dg committed Oct 5, 2023
1 parent 8c73059 commit a2a9c8c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/Forms/Controls.BaseControl.enum.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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';
}


setUp(function () {
ob_start();
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));
});

0 comments on commit a2a9c8c

Please sign in to comment.