create(); $schema = FormSchema::factory()->create(['organisation_id' => $org->id]); $field = FormField::factory()->create(['form_schema_id' => $schema->id]); FormFieldBinding::factory()->forField($field)->entityOwned('person', 'email')->create(); FormFieldBinding::factory()->forField($field)->mirrored('user_profile', 'bio')->create(); $this->assertSame(2, FormFieldBinding::query() ->withoutGlobalScopes() ->where('owner_type', 'form_field') ->where('owner_id', $field->id) ->count(), ); $field->delete(); // soft delete on FormField $this->assertSame(0, FormFieldBinding::query() ->withoutGlobalScopes() ->where('owner_type', 'form_field') ->where('owner_id', $field->id) ->count(), ); } public function test_delete_of_library_entry_cascades_bindings(): void { $org = Organisation::factory()->create(); $library = FormFieldLibrary::factory()->create(['organisation_id' => $org->id]); FormFieldBinding::factory()->forLibrary($library)->entityOwned('person', 'first_name')->create(); $this->assertSame(1, FormFieldBinding::query() ->withoutGlobalScopes() ->where('owner_type', 'form_field_library') ->where('owner_id', $library->id) ->count(), ); $library->delete(); $this->assertSame(0, FormFieldBinding::query() ->withoutGlobalScopes() ->where('owner_type', 'form_field_library') ->where('owner_id', $library->id) ->count(), ); } public function test_deleting_one_field_does_not_cascade_others(): void { $org = Organisation::factory()->create(); $schema = FormSchema::factory()->create(['organisation_id' => $org->id]); $a = FormField::factory()->create(['form_schema_id' => $schema->id]); $b = FormField::factory()->create(['form_schema_id' => $schema->id]); FormFieldBinding::factory()->forField($a)->entityOwned('person', 'email')->create(); FormFieldBinding::factory()->forField($b)->entityOwned('person', 'phone')->create(); $a->delete(); $this->assertSame(1, FormFieldBinding::query() ->withoutGlobalScopes() ->where('owner_type', 'form_field') ->where('owner_id', $b->id) ->count(), ); } }