Files
crewli/api/tests/Feature/FormBuilder/Purposes/AllPurposesGuardWiringTest.php
bert.hausmans e3c9211e3f feat(form-builder): wire PurposeGuardProvider per purpose (WS-6)
Adds PurposeGuardProvider as a parallel interface to PurposeDefinition
(value object stays untouched). Seven concrete providers, one per v1.0
purpose, each declaring its publish-guard list. Registry resolves and
caches providers via guards_class config key.

Universal guards (MaxOneIdentityKeyPerTargetEntity,
AppendStrategyRequiresCollectionTarget, NoAmbiguousTrustLevels,
IdentityKeyBindingsOnlyInFirstSection) wire into every purpose. The
section guard is a cheap no-op when section_level_submit=false.

ArtistAdvanceGuards omits RequiresIdentityKeyBinding because the
artist subject is resolved via portal token, not form data. Same
reasoning for supplier_intake (production_request) and the auth-based
purposes.

Includes a cross-cutting BindingTypeRegistryConsistencyTest that
verifies tasks 5/7/8 do not contradict each other (registry ↔ guards ↔
purpose required_bindings).

Refs: RFC-WS-6.md §3 (Q9, Q13)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-25 23:01:19 +02:00

42 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\FormBuilder\Purposes;
use App\FormBuilder\Purposes\PurposeGuardProvider;
use App\FormBuilder\Purposes\PurposeRegistry;
use Tests\TestCase;
final class AllPurposesGuardWiringTest extends TestCase
{
public function test_every_purpose_has_a_guards_class(): void
{
/** @var array<string, mixed> $config */
$config = config('form_builder.purposes');
$this->assertNotEmpty($config);
foreach ($config as $slug => $attrs) {
$this->assertArrayHasKey(
'guards_class',
$attrs,
"Purpose '{$slug}' is missing the guards_class config key.",
);
}
}
public function test_registry_resolves_provider_for_every_purpose(): void
{
$registry = $this->app->make(PurposeRegistry::class);
foreach (array_keys($registry->all()) as $slug) {
$provider = $registry->guardProviderFor($slug);
$this->assertInstanceOf(PurposeGuardProvider::class, $provider);
$this->assertNotEmpty(
$provider->publishGuards(),
"Provider for '{$slug}' returned no guards.",
);
}
}
}