create(); $library = FormFieldLibrary::factory()->create([ 'organisation_id' => $org->id, 'slug' => 'kenteken', ]); FormFieldValidationRule::factory()->forLibrary($library) ->ofType(FormFieldValidationRuleType::Regex, ['pattern' => '/^[A-Z]{3}$/'])->create(); FormFieldValidationRule::factory()->forLibrary($library) ->ofType(FormFieldValidationRuleType::MaxLength, ['value' => 8])->create(); $schema = FormSchema::factory()->create(['organisation_id' => $org->id]); /** @var FormField $field */ $field = app(FormFieldService::class)->insertFromLibrary($schema, $library); $rules = FormFieldValidationRule::query() ->where('owner_type', 'form_field') ->where('owner_id', $field->id) ->get() ->keyBy(fn ($r) => $r->rule_type->value); $this->assertCount(2, $rules); $this->assertSame('/^[A-Z]{3}$/', $rules['regex']->parameters['pattern']); $this->assertSame(8, $rules['max_length']->parameters['value']); } public function test_library_without_rules_produces_field_without_rules(): void { $org = Organisation::factory()->create(); $library = FormFieldLibrary::factory()->create(['organisation_id' => $org->id]); $schema = FormSchema::factory()->create(['organisation_id' => $org->id]); /** @var FormField $field */ $field = app(FormFieldService::class)->insertFromLibrary($schema, $library); $count = FormFieldValidationRule::query() ->where('owner_type', 'form_field') ->where('owner_id', $field->id) ->count(); $this->assertSame(0, $count); } }