adrema/tests/Lib/CreatesFormFields.php

81 lines
2.8 KiB
PHP
Raw Permalink Normal View History

2024-02-20 02:02:42 +01:00
<?php
namespace Tests\Lib;
use App\Form\Fields\CheckboxesField;
use App\Form\Fields\CheckboxField;
use App\Form\Fields\DateField;
use App\Form\Fields\DropdownField;
2024-04-13 21:57:58 +02:00
use App\Form\Fields\EmailField;
2024-02-20 02:02:42 +01:00
use App\Form\Fields\GroupField;
use App\Form\Fields\NamiField;
2024-04-14 11:47:48 +02:00
use App\Form\Fields\NumberField;
2024-02-20 02:02:42 +01:00
use App\Form\Fields\RadioField;
use App\Form\Fields\TextareaField;
use App\Form\Fields\TextField;
use Faker\Generator;
use Tests\Feature\Form\FormtemplateFieldRequest;
trait CreatesFormFields
{
2024-09-21 22:46:38 +02:00
protected static function namiField(?string $key = null): FormtemplateFieldRequest
2024-02-20 02:02:42 +01:00
{
2024-09-21 22:46:38 +02:00
return FormtemplateFieldRequest::type(NamiField::class)->key($key ?? static::randomKey());
2024-02-20 02:02:42 +01:00
}
2024-09-21 22:46:38 +02:00
protected static function textField(?string $key = null): FormtemplateFieldRequest
2024-02-20 02:02:42 +01:00
{
2024-09-21 22:46:38 +02:00
return FormtemplateFieldRequest::type(TextField::class)->key($key ?? static::randomKey());
2024-02-20 02:02:42 +01:00
}
2024-09-21 22:46:38 +02:00
protected static function numberField(?string $key = null): FormtemplateFieldRequest
2024-04-14 11:47:48 +02:00
{
2024-09-21 22:46:38 +02:00
return FormtemplateFieldRequest::type(NumberField::class)->key($key ?? static::randomKey());
2024-04-14 11:47:48 +02:00
}
2024-09-21 22:46:38 +02:00
protected static function emailField(?string $key = null): FormtemplateFieldRequest
2024-04-13 21:57:58 +02:00
{
2024-09-21 22:46:38 +02:00
return FormtemplateFieldRequest::type(EmailField::class)->key($key ?? static::randomKey());
2024-04-13 21:57:58 +02:00
}
2024-09-21 22:46:38 +02:00
protected static function checkboxesField(?string $key = null): FormtemplateFieldRequest
2024-02-20 02:02:42 +01:00
{
2024-09-21 22:46:38 +02:00
return FormtemplateFieldRequest::type(CheckboxesField::class)->key($key ?? static::randomKey());
2024-02-20 02:02:42 +01:00
}
2024-09-21 22:46:38 +02:00
protected static function textareaField(?string $key = null): FormtemplateFieldRequest
2024-02-20 02:02:42 +01:00
{
2024-09-21 22:46:38 +02:00
return FormtemplateFieldRequest::type(TextareaField::class)->key($key ?? static::randomKey());
2024-02-20 02:02:42 +01:00
}
2024-09-21 22:46:38 +02:00
protected static function dropdownField(?string $key = null): FormtemplateFieldRequest
2024-02-20 02:02:42 +01:00
{
2024-09-21 22:46:38 +02:00
return FormtemplateFieldRequest::type(DropdownField::class)->key($key ?? static::randomKey());
2024-02-20 02:02:42 +01:00
}
2024-09-21 22:46:38 +02:00
protected static function dateField(?string $key = null): FormtemplateFieldRequest
2024-02-20 02:02:42 +01:00
{
2024-09-21 22:46:38 +02:00
return FormtemplateFieldRequest::type(DateField::class)->key($key ?? static::randomKey());
2024-02-20 02:02:42 +01:00
}
2024-09-21 22:46:38 +02:00
protected static function radioField(?string $key = null): FormtemplateFieldRequest
2024-02-20 02:02:42 +01:00
{
2024-09-21 22:46:38 +02:00
return FormtemplateFieldRequest::type(RadioField::class)->key($key ?? static::randomKey());
2024-02-20 02:02:42 +01:00
}
2024-09-21 22:46:38 +02:00
protected static function checkboxField(?string $key = null): FormtemplateFieldRequest
2024-02-20 02:02:42 +01:00
{
2024-09-21 22:46:38 +02:00
return FormtemplateFieldRequest::type(CheckboxField::class)->key($key ?? static::randomKey());
2024-02-20 02:02:42 +01:00
}
2024-09-21 22:46:38 +02:00
protected static function groupField(?string $key = null): FormtemplateFieldRequest
2024-02-20 02:02:42 +01:00
{
2024-09-21 22:46:38 +02:00
return FormtemplateFieldRequest::type(GroupField::class)->key($key ?? static::randomKey());
2024-02-20 02:02:42 +01:00
}
2024-09-21 22:46:38 +02:00
protected static function randomKey(): string
2024-02-20 02:02:42 +01:00
{
2024-04-13 21:57:58 +02:00
return preg_replace('/[\-0-9]/', '', str()->uuid() . str()->uuid());
2024-02-20 02:02:42 +01:00
}
}