create(); $schema = FormSchema::factory()->create(['organisation_id' => $org->id]); $library = FormFieldLibrary::factory() ->withOptions([ ['value' => 'red', 'label' => 'Red', 'sort_order' => 0, 'translations' => ['nl' => 'Rood']], ['value' => 'green', 'label' => 'Green', 'sort_order' => 1], ]) ->create(['organisation_id' => $org->id]); $field = app(FormFieldService::class)->insertFromLibrary($schema, $library); $optionService = app(FormFieldOptionService::class); $copied = $optionService->optionsFor($field); $libraryOptions = $optionService->optionsFor($library); $this->assertCount(2, $copied); $this->assertSame(['red', 'green'], $copied->pluck('value')->all()); $this->assertSame([0, 1], $copied->pluck('sort_order')->all()); $this->assertSame(['nl' => 'Rood'], $copied->firstWhere('value', 'red')->translations); $this->assertNull($copied->firstWhere('value', 'green')->translations); // Distinct row IDs — options are CLONED, not shared. $this->assertNotSame( $libraryOptions->pluck('id')->sort()->values()->all(), $copied->pluck('id')->sort()->values()->all(), ); } public function test_insert_from_library_does_not_carry_legacy_options_translations_key(): void { $org = Organisation::factory()->create(); $schema = FormSchema::factory()->create(['organisation_id' => $org->id]); $library = FormFieldLibrary::factory() ->withOptions(['a', 'b']) ->create([ 'organisation_id' => $org->id, // Library carries label/help_text translations only — no // {locale}.options[] parallel array. WS-5d strips that key // from the FormField's translations bag too. 'translations' => ['nl' => ['label' => 'Bibliotheek']], ]); $field = app(FormFieldService::class)->insertFromLibrary($schema, $library); $bag = $field->fresh()->translations ?? []; if (is_array($bag)) { foreach ($bag as $localeBag) { $this->assertArrayNotHasKey('options', is_array($localeBag) ? $localeBag : []); } } } }