feat(forms): add PHP enums for form builder
9 backed string enums covering purpose, field type, submission status/mode/review, field width, value storage hint, snapshot mode, webhook delivery status. FormPurpose/FormFieldType include helper methods per ARCH §3/§5. All with declare(strict_types=1) and values() helpers for validation rules. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Enums\FormBuilder;
|
||||
|
||||
use App\Enums\FormBuilder\FormFieldDisplayWidth;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FormFieldDisplayWidthTest extends TestCase
|
||||
{
|
||||
public function test_has_half_and_full_cases(): void
|
||||
{
|
||||
$this->assertSame('half', FormFieldDisplayWidth::HALF->value);
|
||||
$this->assertSame('full', FormFieldDisplayWidth::FULL->value);
|
||||
$this->assertCount(2, FormFieldDisplayWidth::cases());
|
||||
}
|
||||
|
||||
public function test_values_returns_string_array(): void
|
||||
{
|
||||
$this->assertSame(['half', 'full'], FormFieldDisplayWidth::values());
|
||||
}
|
||||
}
|
||||
90
api/tests/Unit/Enums/FormBuilder/FormFieldTypeTest.php
Normal file
90
api/tests/Unit/Enums/FormBuilder/FormFieldTypeTest.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Enums\FormBuilder;
|
||||
|
||||
use App\Enums\FormBuilder\FormFieldType;
|
||||
use App\Enums\FormBuilder\FormValueStorageHint;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FormFieldTypeTest extends TestCase
|
||||
{
|
||||
public function test_has_22_cases(): void
|
||||
{
|
||||
$this->assertCount(22, FormFieldType::cases());
|
||||
}
|
||||
|
||||
public function test_values_returns_string_array(): void
|
||||
{
|
||||
$values = FormFieldType::values();
|
||||
$this->assertContains('TEXT', $values);
|
||||
$this->assertContains('SIGNATURE', $values);
|
||||
$this->assertContains('TABLE_ROWS', $values);
|
||||
}
|
||||
|
||||
public function test_storage_hint_string_types(): void
|
||||
{
|
||||
$this->assertSame(FormValueStorageHint::STRING, FormFieldType::TEXT->recommendedValueStorageHint());
|
||||
$this->assertSame(FormValueStorageHint::STRING, FormFieldType::TEXTAREA->recommendedValueStorageHint());
|
||||
$this->assertSame(FormValueStorageHint::STRING, FormFieldType::EMAIL->recommendedValueStorageHint());
|
||||
$this->assertSame(FormValueStorageHint::STRING, FormFieldType::PHONE->recommendedValueStorageHint());
|
||||
$this->assertSame(FormValueStorageHint::STRING, FormFieldType::URL->recommendedValueStorageHint());
|
||||
$this->assertSame(FormValueStorageHint::STRING, FormFieldType::RADIO->recommendedValueStorageHint());
|
||||
$this->assertSame(FormValueStorageHint::STRING, FormFieldType::SELECT->recommendedValueStorageHint());
|
||||
}
|
||||
|
||||
public function test_storage_hint_typed(): void
|
||||
{
|
||||
$this->assertSame(FormValueStorageHint::NUMBER, FormFieldType::NUMBER->recommendedValueStorageHint());
|
||||
$this->assertSame(FormValueStorageHint::DATE, FormFieldType::DATE->recommendedValueStorageHint());
|
||||
$this->assertSame(FormValueStorageHint::DATE, FormFieldType::DATETIME->recommendedValueStorageHint());
|
||||
$this->assertSame(FormValueStorageHint::BOOL, FormFieldType::BOOLEAN->recommendedValueStorageHint());
|
||||
}
|
||||
|
||||
public function test_storage_hint_json_default(): void
|
||||
{
|
||||
$this->assertSame(FormValueStorageHint::JSON, FormFieldType::MULTISELECT->recommendedValueStorageHint());
|
||||
$this->assertSame(FormValueStorageHint::JSON, FormFieldType::CHECKBOX_LIST->recommendedValueStorageHint());
|
||||
$this->assertSame(FormValueStorageHint::JSON, FormFieldType::FILE_UPLOAD->recommendedValueStorageHint());
|
||||
$this->assertSame(FormValueStorageHint::JSON, FormFieldType::SIGNATURE->recommendedValueStorageHint());
|
||||
$this->assertSame(FormValueStorageHint::JSON, FormFieldType::TAG_PICKER->recommendedValueStorageHint());
|
||||
$this->assertSame(FormValueStorageHint::JSON, FormFieldType::TABLE_ROWS->recommendedValueStorageHint());
|
||||
}
|
||||
|
||||
public function test_is_filterable_true(): void
|
||||
{
|
||||
$this->assertTrue(FormFieldType::TEXT->isFilterable());
|
||||
$this->assertTrue(FormFieldType::SELECT->isFilterable());
|
||||
$this->assertTrue(FormFieldType::NUMBER->isFilterable());
|
||||
$this->assertTrue(FormFieldType::BOOLEAN->isFilterable());
|
||||
$this->assertTrue(FormFieldType::MULTISELECT->isFilterable());
|
||||
$this->assertTrue(FormFieldType::TAG_PICKER->isFilterable());
|
||||
}
|
||||
|
||||
public function test_is_filterable_false(): void
|
||||
{
|
||||
$this->assertFalse(FormFieldType::TEXTAREA->isFilterable());
|
||||
$this->assertFalse(FormFieldType::FILE_UPLOAD->isFilterable());
|
||||
$this->assertFalse(FormFieldType::IMAGE_UPLOAD->isFilterable());
|
||||
$this->assertFalse(FormFieldType::SIGNATURE->isFilterable());
|
||||
$this->assertFalse(FormFieldType::HEADING->isFilterable());
|
||||
$this->assertFalse(FormFieldType::PARAGRAPH->isFilterable());
|
||||
$this->assertFalse(FormFieldType::TABLE_ROWS->isFilterable());
|
||||
$this->assertFalse(FormFieldType::SECTION_PRIORITY->isFilterable());
|
||||
$this->assertFalse(FormFieldType::AVAILABILITY_PICKER->isFilterable());
|
||||
}
|
||||
|
||||
public function test_has_value_true_for_inputs(): void
|
||||
{
|
||||
$this->assertTrue(FormFieldType::TEXT->hasValue());
|
||||
$this->assertTrue(FormFieldType::SIGNATURE->hasValue());
|
||||
$this->assertTrue(FormFieldType::TABLE_ROWS->hasValue());
|
||||
}
|
||||
|
||||
public function test_has_value_false_for_presentational(): void
|
||||
{
|
||||
$this->assertFalse(FormFieldType::HEADING->hasValue());
|
||||
$this->assertFalse(FormFieldType::PARAGRAPH->hasValue());
|
||||
}
|
||||
}
|
||||
101
api/tests/Unit/Enums/FormBuilder/FormPurposeTest.php
Normal file
101
api/tests/Unit/Enums/FormBuilder/FormPurposeTest.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Enums\FormBuilder;
|
||||
|
||||
use App\Enums\FormBuilder\FormPurpose;
|
||||
use App\Enums\FormBuilder\FormSubmissionMode;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FormPurposeTest extends TestCase
|
||||
{
|
||||
public function test_has_22_cases(): void
|
||||
{
|
||||
$this->assertCount(22, FormPurpose::cases());
|
||||
}
|
||||
|
||||
public function test_values_contains_expected_strings(): void
|
||||
{
|
||||
$values = FormPurpose::values();
|
||||
$expected = [
|
||||
'event_registration', 'user_profile', 'artist_profile', 'company_profile',
|
||||
'artist_advance', 'supplier_intake', 'incident_report', 'feedback',
|
||||
'post_event_evaluation', 'signature_contract', 'signature_code_of_conduct',
|
||||
'signature_receipt', 'absence_report', 'check_out_inventory',
|
||||
'public_complaint', 'public_press_request', 'public_rsvp',
|
||||
'onboarding_wizard', 'event_setup_wizard', 'company_custom',
|
||||
'artist_custom', 'custom',
|
||||
];
|
||||
foreach ($expected as $v) {
|
||||
$this->assertContains($v, $values);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_default_subject_type_for_person_purposes(): void
|
||||
{
|
||||
$this->assertSame('person', FormPurpose::EVENT_REGISTRATION->defaultSubjectType());
|
||||
$this->assertSame('person', FormPurpose::POST_EVENT_EVALUATION->defaultSubjectType());
|
||||
$this->assertSame('person', FormPurpose::SIGNATURE_RECEIPT->defaultSubjectType());
|
||||
$this->assertSame('person', FormPurpose::ABSENCE_REPORT->defaultSubjectType());
|
||||
$this->assertSame('person', FormPurpose::CHECK_OUT_INVENTORY->defaultSubjectType());
|
||||
}
|
||||
|
||||
public function test_default_subject_type_for_entity_purposes(): void
|
||||
{
|
||||
$this->assertSame('user', FormPurpose::USER_PROFILE->defaultSubjectType());
|
||||
$this->assertSame('artist', FormPurpose::ARTIST_PROFILE->defaultSubjectType());
|
||||
$this->assertSame('company', FormPurpose::COMPANY_PROFILE->defaultSubjectType());
|
||||
$this->assertSame('artist', FormPurpose::ARTIST_ADVANCE->defaultSubjectType());
|
||||
$this->assertSame('company', FormPurpose::SUPPLIER_INTAKE->defaultSubjectType());
|
||||
$this->assertSame('organisation', FormPurpose::ONBOARDING_WIZARD->defaultSubjectType());
|
||||
$this->assertSame('event', FormPurpose::EVENT_SETUP_WIZARD->defaultSubjectType());
|
||||
}
|
||||
|
||||
public function test_default_subject_type_is_null_for_public_and_custom(): void
|
||||
{
|
||||
$this->assertNull(FormPurpose::PUBLIC_COMPLAINT->defaultSubjectType());
|
||||
$this->assertNull(FormPurpose::PUBLIC_PRESS_REQUEST->defaultSubjectType());
|
||||
$this->assertNull(FormPurpose::PUBLIC_RSVP->defaultSubjectType());
|
||||
$this->assertNull(FormPurpose::CUSTOM->defaultSubjectType());
|
||||
}
|
||||
|
||||
public function test_default_submission_mode_draft_single(): void
|
||||
{
|
||||
$this->assertSame(FormSubmissionMode::DRAFT_SINGLE, FormPurpose::EVENT_REGISTRATION->defaultSubmissionMode());
|
||||
$this->assertSame(FormSubmissionMode::DRAFT_SINGLE, FormPurpose::ARTIST_ADVANCE->defaultSubmissionMode());
|
||||
$this->assertSame(FormSubmissionMode::DRAFT_SINGLE, FormPurpose::SUPPLIER_INTAKE->defaultSubmissionMode());
|
||||
}
|
||||
|
||||
public function test_default_submission_mode_multiple(): void
|
||||
{
|
||||
$this->assertSame(FormSubmissionMode::MULTIPLE, FormPurpose::INCIDENT_REPORT->defaultSubmissionMode());
|
||||
$this->assertSame(FormSubmissionMode::MULTIPLE, FormPurpose::FEEDBACK->defaultSubmissionMode());
|
||||
$this->assertSame(FormSubmissionMode::MULTIPLE, FormPurpose::PUBLIC_COMPLAINT->defaultSubmissionMode());
|
||||
}
|
||||
|
||||
public function test_default_submission_mode_single(): void
|
||||
{
|
||||
$this->assertSame(FormSubmissionMode::SINGLE, FormPurpose::USER_PROFILE->defaultSubmissionMode());
|
||||
$this->assertSame(FormSubmissionMode::SINGLE, FormPurpose::ARTIST_PROFILE->defaultSubmissionMode());
|
||||
$this->assertSame(FormSubmissionMode::SINGLE, FormPurpose::ONBOARDING_WIZARD->defaultSubmissionMode());
|
||||
$this->assertSame(FormSubmissionMode::SINGLE, FormPurpose::CUSTOM->defaultSubmissionMode());
|
||||
}
|
||||
|
||||
public function test_allows_public_access(): void
|
||||
{
|
||||
$this->assertTrue(FormPurpose::PUBLIC_COMPLAINT->allowsPublicAccess());
|
||||
$this->assertTrue(FormPurpose::PUBLIC_PRESS_REQUEST->allowsPublicAccess());
|
||||
$this->assertTrue(FormPurpose::PUBLIC_RSVP->allowsPublicAccess());
|
||||
$this->assertTrue(FormPurpose::ARTIST_ADVANCE->allowsPublicAccess());
|
||||
$this->assertTrue(FormPurpose::SUPPLIER_INTAKE->allowsPublicAccess());
|
||||
}
|
||||
|
||||
public function test_disallows_public_access(): void
|
||||
{
|
||||
$this->assertFalse(FormPurpose::EVENT_REGISTRATION->allowsPublicAccess());
|
||||
$this->assertFalse(FormPurpose::USER_PROFILE->allowsPublicAccess());
|
||||
$this->assertFalse(FormPurpose::INCIDENT_REPORT->allowsPublicAccess());
|
||||
$this->assertFalse(FormPurpose::CUSTOM->allowsPublicAccess());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Enums\FormBuilder;
|
||||
|
||||
use App\Enums\FormBuilder\FormSchemaSnapshotMode;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FormSchemaSnapshotModeTest extends TestCase
|
||||
{
|
||||
public function test_has_expected_cases(): void
|
||||
{
|
||||
$this->assertSame('never', FormSchemaSnapshotMode::NEVER->value);
|
||||
$this->assertSame('on_submit', FormSchemaSnapshotMode::ON_SUBMIT->value);
|
||||
$this->assertSame('always', FormSchemaSnapshotMode::ALWAYS->value);
|
||||
$this->assertCount(3, FormSchemaSnapshotMode::cases());
|
||||
}
|
||||
|
||||
public function test_values_returns_string_array(): void
|
||||
{
|
||||
$this->assertSame(['never', 'on_submit', 'always'], FormSchemaSnapshotMode::values());
|
||||
}
|
||||
}
|
||||
24
api/tests/Unit/Enums/FormBuilder/FormSubmissionModeTest.php
Normal file
24
api/tests/Unit/Enums/FormBuilder/FormSubmissionModeTest.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Enums\FormBuilder;
|
||||
|
||||
use App\Enums\FormBuilder\FormSubmissionMode;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FormSubmissionModeTest extends TestCase
|
||||
{
|
||||
public function test_has_expected_cases(): void
|
||||
{
|
||||
$this->assertSame('single', FormSubmissionMode::SINGLE->value);
|
||||
$this->assertSame('multiple', FormSubmissionMode::MULTIPLE->value);
|
||||
$this->assertSame('draft_single', FormSubmissionMode::DRAFT_SINGLE->value);
|
||||
$this->assertCount(3, FormSubmissionMode::cases());
|
||||
}
|
||||
|
||||
public function test_values_returns_string_array(): void
|
||||
{
|
||||
$this->assertSame(['single', 'multiple', 'draft_single'], FormSubmissionMode::values());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Enums\FormBuilder;
|
||||
|
||||
use App\Enums\FormBuilder\FormSubmissionReviewStatus;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FormSubmissionReviewStatusTest extends TestCase
|
||||
{
|
||||
public function test_has_expected_cases(): void
|
||||
{
|
||||
$this->assertCount(4, FormSubmissionReviewStatus::cases());
|
||||
$this->assertSame('pending_review', FormSubmissionReviewStatus::PENDING_REVIEW->value);
|
||||
$this->assertSame('approved', FormSubmissionReviewStatus::APPROVED->value);
|
||||
$this->assertSame('rejected', FormSubmissionReviewStatus::REJECTED->value);
|
||||
$this->assertSame('changes_requested', FormSubmissionReviewStatus::CHANGES_REQUESTED->value);
|
||||
}
|
||||
|
||||
public function test_values_returns_string_array(): void
|
||||
{
|
||||
$this->assertSame(
|
||||
['pending_review', 'approved', 'rejected', 'changes_requested'],
|
||||
FormSubmissionReviewStatus::values()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Enums\FormBuilder;
|
||||
|
||||
use App\Enums\FormBuilder\FormSubmissionStatus;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FormSubmissionStatusTest extends TestCase
|
||||
{
|
||||
public function test_has_expected_cases(): void
|
||||
{
|
||||
$this->assertSame('draft', FormSubmissionStatus::DRAFT->value);
|
||||
$this->assertSame('submitted', FormSubmissionStatus::SUBMITTED->value);
|
||||
$this->assertSame('archived', FormSubmissionStatus::ARCHIVED->value);
|
||||
$this->assertCount(3, FormSubmissionStatus::cases());
|
||||
}
|
||||
|
||||
public function test_values_returns_array_of_strings(): void
|
||||
{
|
||||
$this->assertSame(['draft', 'submitted', 'archived'], FormSubmissionStatus::values());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Enums\FormBuilder;
|
||||
|
||||
use App\Enums\FormBuilder\FormValueStorageHint;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FormValueStorageHintTest extends TestCase
|
||||
{
|
||||
public function test_has_expected_cases(): void
|
||||
{
|
||||
$this->assertSame('json', FormValueStorageHint::JSON->value);
|
||||
$this->assertSame('string', FormValueStorageHint::STRING->value);
|
||||
$this->assertSame('number', FormValueStorageHint::NUMBER->value);
|
||||
$this->assertSame('date', FormValueStorageHint::DATE->value);
|
||||
$this->assertSame('bool', FormValueStorageHint::BOOL->value);
|
||||
$this->assertCount(5, FormValueStorageHint::cases());
|
||||
}
|
||||
|
||||
public function test_values_returns_string_array(): void
|
||||
{
|
||||
$this->assertSame(
|
||||
['json', 'string', 'number', 'date', 'bool'],
|
||||
FormValueStorageHint::values()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Enums\FormBuilder;
|
||||
|
||||
use App\Enums\FormBuilder\FormWebhookDeliveryStatus;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FormWebhookDeliveryStatusTest extends TestCase
|
||||
{
|
||||
public function test_has_expected_cases(): void
|
||||
{
|
||||
$this->assertSame('pending', FormWebhookDeliveryStatus::PENDING->value);
|
||||
$this->assertSame('delivered', FormWebhookDeliveryStatus::DELIVERED->value);
|
||||
$this->assertSame('failed', FormWebhookDeliveryStatus::FAILED->value);
|
||||
$this->assertSame('dead_letter', FormWebhookDeliveryStatus::DEAD_LETTER->value);
|
||||
$this->assertCount(4, FormWebhookDeliveryStatus::cases());
|
||||
}
|
||||
|
||||
public function test_values_returns_string_array(): void
|
||||
{
|
||||
$this->assertSame(
|
||||
['pending', 'delivered', 'failed', 'dead_letter'],
|
||||
FormWebhookDeliveryStatus::values()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user