feat(form-builder): form_field_validation_rules table + polymorphic owner + scope + cascade

This commit is contained in:
2026-04-24 22:01:36 +02:00
parent 87fc964ead
commit fedaed1b32
17 changed files with 798 additions and 37 deletions

View File

@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Enums\FormBuilder;
use App\Enums\FormBuilder\FormFieldValidationRuleType;
use PHPUnit\Framework\TestCase;
/**
* Guard: the enum is the canonical catalogue. If a rule_type string is
* added to the catalogue in docs/code elsewhere, the corresponding case
* MUST exist here. New catalogue entries are reviewed architecturally
* this test is the compile-time pairing.
*/
final class FormFieldValidationRuleTypeEnumTest extends TestCase
{
public function test_catalogue_contains_every_documented_case(): void
{
$expected = [
'min_length',
'max_length',
'min_value',
'max_value',
'regex',
'email_format',
'url_format',
'phone_e164',
'allowed_mime_types',
'max_file_size',
'min_selected',
'max_selected',
'date_min',
'date_max',
'callback',
];
$actual = array_map(
static fn (FormFieldValidationRuleType $c): string => $c->value,
FormFieldValidationRuleType::cases(),
);
sort($expected);
sort($actual);
$this->assertSame($expected, $actual);
}
public function test_from_string_roundtrip_matches_value(): void
{
foreach (FormFieldValidationRuleType::cases() as $case) {
$this->assertSame(
$case,
FormFieldValidationRuleType::from($case->value),
);
}
}
public function test_tryfrom_unknown_key_returns_null(): void
{
// Explicit: legacy keys that were NOT migrated to the enum must not
// silently resolve. These come from the Phase A seed scan.
$this->assertNull(FormFieldValidationRuleType::tryFrom('required'));
$this->assertNull(FormFieldValidationRuleType::tryFrom('unique'));
$this->assertNull(FormFieldValidationRuleType::tryFrom('max_priorities'));
$this->assertNull(FormFieldValidationRuleType::tryFrom('tag_categories'));
$this->assertNull(FormFieldValidationRuleType::tryFrom('storage_disk'));
// Legacy ambiguous keys that need field-type dispatch at backfill:
$this->assertNull(FormFieldValidationRuleType::tryFrom('min'));
$this->assertNull(FormFieldValidationRuleType::tryFrom('max'));
}
}