schemaWithSnapshot(); $field = FormField::factory()->create([ 'form_schema_id' => $schema->id, 'field_type' => FormFieldType::EMAIL->value, 'slug' => 'email', 'label' => 'E-mail', ]); FormFieldBinding::factory()->forField($field)->entityOwned('person', 'email')->create(); $submission = $this->submitFor($schema); $snapshot = $submission->fresh()->schema_snapshot; $this->assertIsArray($snapshot); $embedded = collect($snapshot['fields'])->firstWhere('id', $field->id); $this->assertNotNull($embedded); $this->assertSame([ 'mode' => 'entity_owned', 'entity' => 'person', 'column' => 'email', ], $embedded['binding']); } public function test_snapshot_embeds_mirrored_binding_with_sync_direction(): void { $schema = $this->schemaWithSnapshot(); $field = FormField::factory()->create([ 'form_schema_id' => $schema->id, 'field_type' => FormFieldType::TEXT->value, 'slug' => 'noodcontact', 'label' => 'Noodcontact', ]); FormFieldBinding::factory()->forField($field)->mirrored('user_profile', 'emergency_contact_name')->create(); $submission = $this->submitFor($schema); $snapshot = $submission->fresh()->schema_snapshot; $embedded = collect($snapshot['fields'])->firstWhere('id', $field->id); $this->assertSame([ 'mode' => 'mirrored', 'entity' => 'user_profile', 'column' => 'emergency_contact_name', 'sync_direction' => 'write_on_submit', ], $embedded['binding']); } public function test_snapshot_embeds_null_binding_for_form_owned_field(): void { $schema = $this->schemaWithSnapshot(); $field = FormField::factory()->create([ 'form_schema_id' => $schema->id, 'field_type' => FormFieldType::TEXT->value, 'slug' => 'motivatie', 'label' => 'Motivatie', ]); $submission = $this->submitFor($schema); $snapshot = $submission->fresh()->schema_snapshot; $embedded = collect($snapshot['fields'])->firstWhere('id', $field->id); $this->assertNull($embedded['binding']); } private function schemaWithSnapshot(): FormSchema { $org = Organisation::factory()->create(); return FormSchema::factory()->create([ 'organisation_id' => $org->id, 'purpose' => FormPurpose::USER_PROFILE->value, 'snapshot_mode' => FormSchemaSnapshotMode::ALWAYS->value, ]); } private function submitFor(FormSchema $schema): FormSubmission { $user = User::factory()->create(); $service = $this->app->make(FormSubmissionService::class); $submission = $service->createDraft($schema, $user, $user); return $service->submit($submission, $user); } }