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>
70 lines
2.3 KiB
PHP
70 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\FormBuilder\Purposes;
|
|
|
|
use App\Enums\FormBuilder\FormFieldBindingMergeStrategy;
|
|
use App\Enums\FormBuilder\FormPurpose;
|
|
use App\FormBuilder\Purposes\Guards\ArtistAdvanceGuards;
|
|
use App\Models\FormBuilder\FormField;
|
|
use App\Models\FormBuilder\FormFieldBinding;
|
|
use App\Models\FormBuilder\FormSchema;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
final class ArtistAdvanceGuardsIntegrationTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_valid_schema_passes_all_guards(): void
|
|
{
|
|
$schema = $this->buildValidSchema();
|
|
$provider = $this->app->make(ArtistAdvanceGuards::class);
|
|
|
|
foreach ($provider->publishGuards() as $guard) {
|
|
$result = $guard->evaluate($schema);
|
|
$this->assertTrue(
|
|
$result->passed,
|
|
"Guard {$guard->code()} failed: {$result->messageKey}",
|
|
);
|
|
}
|
|
}
|
|
|
|
public function test_append_on_scalar_target_fails(): void
|
|
{
|
|
$schema = $this->buildValidSchema();
|
|
FormFieldBinding::query()
|
|
->withoutGlobalScopes()
|
|
->whereIn('owner_id', $schema->fields->pluck('id'))
|
|
->where('target_attribute', 'stage_name')
|
|
->update(['merge_strategy' => FormFieldBindingMergeStrategy::Append->value]);
|
|
$schema->load('fields.bindings');
|
|
|
|
$provider = $this->app->make(ArtistAdvanceGuards::class);
|
|
|
|
$failedCodes = [];
|
|
foreach ($provider->publishGuards() as $guard) {
|
|
$result = $guard->evaluate($schema);
|
|
if (! $result->passed) {
|
|
$failedCodes[] = $guard->code();
|
|
}
|
|
}
|
|
|
|
$this->assertContains('append_strategy_requires_collection_target', $failedCodes);
|
|
}
|
|
|
|
private function buildValidSchema(): FormSchema
|
|
{
|
|
$schema = FormSchema::factory()->create([
|
|
'purpose' => FormPurpose::ARTIST_ADVANCE->value,
|
|
]);
|
|
$field = FormField::factory()->create(['form_schema_id' => $schema->id]);
|
|
FormFieldBinding::factory()->forField($field)->entityOwned('artist', 'stage_name')
|
|
->create(['trust_level' => 70]);
|
|
$schema->load(['fields.bindings', 'sections']);
|
|
|
|
return $schema;
|
|
}
|
|
}
|