test(form-builder): cover purpose registry and morph-map alignment

- PurposeRegistryTest: all seven purposes load with expected shape;
  `get()` throws PurposeNotFoundException on unknown slug;
  `allSubjectTypes()` returns exactly [artist, company, person, user];
  `publicAccessibleSlugs()` is only `[event_registration]`.
- PurposeSchemaLifecycleTest: data-provider-driven create → publish
  for all seven purposes; negative tests for event_registration (three
  missing bindings) and supplier_intake (company.name missing); partial
  binding test reports only the missing subset.
- CustomPurposeEscapeRemovedTest: column gone, config file gone,
  FormPurpose::CUSTOM gone, store endpoint rejects `'custom'`, resource
  payload omits the field.
- SubjectTypeRegistryConsolidationTest: submission validation accepts
  registry subject types, rejects everything else including the legacy
  `event` alias that used to be allowed.
- MorphMapAlignmentTest: compile-time guard that every
  PurposeRegistry::allSubjectTypes() alias appears in the morph-map and
  in AppServiceProvider::PURPOSE_SUBJECT_FQCN.
- FormPurposeTest rewritten to cover the seven v1.0 cases and the
  registry-delegation helpers (now extends Tests\TestCase for the
  container).
- Public/listener tests swap the removed PUBLIC_RSVP / PUBLIC_COMPLAINT
  / FEEDBACK references for valid v1.0 purposes, preserving their
  negative-path assertions.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-24 14:36:09 +02:00
parent a71201f4d3
commit 55ba4f24c0
13 changed files with 555 additions and 82 deletions

View File

@@ -6,96 +6,59 @@ namespace Tests\Unit\Enums\FormBuilder;
use App\Enums\FormBuilder\FormPurpose;
use App\Enums\FormBuilder\FormSubmissionMode;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
class FormPurposeTest extends TestCase
final class FormPurposeTest extends TestCase
{
public function test_has_22_cases(): void
public function test_has_seven_cases(): void
{
$this->assertCount(22, FormPurpose::cases());
$this->assertCount(7, FormPurpose::cases());
}
public function test_values_contains_expected_strings(): void
public function test_values_match_v1_vocabulary(): 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);
}
$this->assertSame(
[
'event_registration',
'artist_advance',
'supplier_intake',
'post_event_evaluation',
'incident_report',
'signature_contract',
'user_profile',
],
FormPurpose::values(),
);
}
public function test_default_subject_type_for_person_purposes(): void
public function test_default_submission_mode_delegates_to_registry(): void
{
$this->assertSame(FormSubmissionMode::SINGLE, FormPurpose::EVENT_REGISTRATION->defaultSubmissionMode());
$this->assertSame(FormSubmissionMode::DRAFT_SINGLE, FormPurpose::ARTIST_ADVANCE->defaultSubmissionMode());
$this->assertSame(FormSubmissionMode::SINGLE, FormPurpose::SUPPLIER_INTAKE->defaultSubmissionMode());
$this->assertSame(FormSubmissionMode::MULTIPLE, FormPurpose::INCIDENT_REPORT->defaultSubmissionMode());
$this->assertSame(FormSubmissionMode::SINGLE, FormPurpose::USER_PROFILE->defaultSubmissionMode());
}
public function test_default_subject_type_delegates_to_registry(): 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());
$this->assertSame('person', FormPurpose::POST_EVENT_EVALUATION->defaultSubjectType());
$this->assertSame('person', FormPurpose::INCIDENT_REPORT->defaultSubjectType());
$this->assertSame('user', FormPurpose::SIGNATURE_CONTRACT->defaultSubjectType());
$this->assertSame('user', FormPurpose::USER_PROFILE->defaultSubjectType());
}
public function test_default_subject_type_is_null_for_public_and_custom(): void
public function test_only_event_registration_allows_public_access(): 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->assertTrue(FormPurpose::EVENT_REGISTRATION->allowsPublicAccess());
$this->assertFalse(FormPurpose::ARTIST_ADVANCE->allowsPublicAccess());
$this->assertFalse(FormPurpose::SUPPLIER_INTAKE->allowsPublicAccess());
$this->assertFalse(FormPurpose::POST_EVENT_EVALUATION->allowsPublicAccess());
$this->assertFalse(FormPurpose::INCIDENT_REPORT->allowsPublicAccess());
$this->assertFalse(FormPurpose::CUSTOM->allowsPublicAccess());
$this->assertFalse(FormPurpose::SIGNATURE_CONTRACT->allowsPublicAccess());
$this->assertFalse(FormPurpose::USER_PROFILE->allowsPublicAccess());
}
}