create(); $schema = FormSchema::factory()->create(['organisation_id' => $org->id]); $field = FormField::factory()->create(['form_schema_id' => $schema->id, 'slug' => 'subject']); FormField::factory()->create(['form_schema_id' => $schema->id, 'slug' => 'gate']); FormField::factory()->create(['form_schema_id' => $schema->id, 'slug' => 'region']); app(FormFieldConditionalLogicService::class)->replaceLogic($field, [ 'operator' => 'all', 'children' => [ ['field_slug' => 'gate', 'operator' => 'equals', 'value' => 'yes'], [ 'operator' => 'any', 'children' => [ ['field_slug' => 'region', 'operator' => 'equals', 'value' => 'NL'], ['field_slug' => 'region', 'operator' => 'equals', 'value' => 'BE'], ], ], ], ]); $resource = new FormFieldResource($field->fresh()); $payload = $resource->toArray(Request::create('/', 'GET')); $this->assertSame([ 'show_when' => [ 'all' => [ ['field_slug' => 'gate', 'operator' => 'equals', 'value' => 'yes'], [ 'any' => [ ['field_slug' => 'region', 'operator' => 'equals', 'value' => 'NL'], ['field_slug' => 'region', 'operator' => 'equals', 'value' => 'BE'], ], ], ], ], ], $payload['conditional_logic']); } public function test_form_field_resource_yields_null_when_no_logic(): void { $org = Organisation::factory()->create(); $schema = FormSchema::factory()->create(['organisation_id' => $org->id]); $field = FormField::factory()->create(['form_schema_id' => $schema->id]); $resource = new FormFieldResource($field->fresh()); $payload = $resource->toArray(Request::create('/', 'GET')); $this->assertNull($payload['conditional_logic']); } }