2023-12-27 22:54:58 +01:00
|
|
|
<?php
|
|
|
|
|
2023-12-31 22:35:13 +01:00
|
|
|
namespace Database\Factories\Form\Models;
|
2023-12-27 22:54:58 +01:00
|
|
|
|
|
|
|
use App\Form\Models\Form;
|
2024-01-14 15:52:54 +01:00
|
|
|
use Database\Factories\Traits\FakesMedia;
|
2023-12-27 22:54:58 +01:00
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
2024-03-15 01:19:52 +01:00
|
|
|
use Tests\Feature\Form\FormtemplateFieldRequest;
|
2024-01-01 16:43:40 +01:00
|
|
|
use Tests\Feature\Form\FormtemplateSectionRequest;
|
2024-04-20 00:04:20 +02:00
|
|
|
use Tests\RequestFactories\EditorRequestFactory;
|
2023-12-27 22:54:58 +01:00
|
|
|
|
|
|
|
/**
|
2023-12-31 21:02:40 +01:00
|
|
|
* @extends Factory<Form>
|
2023-12-31 22:35:13 +01:00
|
|
|
* @method self name(string $name)
|
|
|
|
* @method self from(string $from)
|
|
|
|
* @method self to(string $to)
|
|
|
|
* @method self excerpt(string $excerpt)
|
2024-01-10 21:54:35 +01:00
|
|
|
* @method self registrationFrom(string|null $date)
|
|
|
|
* @method self registrationUntil(string|null $date)
|
2024-05-27 19:14:42 +02:00
|
|
|
* @method self isActive(bool $isActive)
|
|
|
|
* @method self isPrivate(bool $isPrivate)
|
2023-12-27 22:54:58 +01:00
|
|
|
*/
|
|
|
|
class FormFactory extends Factory
|
|
|
|
{
|
2024-01-14 15:52:54 +01:00
|
|
|
use FakesMedia;
|
|
|
|
|
2023-12-27 22:54:58 +01:00
|
|
|
/**
|
|
|
|
* The name of the factory's corresponding model.
|
|
|
|
*
|
2023-12-31 21:02:40 +01:00
|
|
|
* @var class-string<Form>
|
2023-12-27 22:54:58 +01:00
|
|
|
*/
|
|
|
|
protected $model = Form::class;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Define the model's default state.
|
|
|
|
*
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
|
|
|
public function definition()
|
|
|
|
{
|
|
|
|
return [
|
2023-12-31 22:35:13 +01:00
|
|
|
'name' => $this->faker->words(4, true),
|
2024-04-20 00:04:20 +02:00
|
|
|
'description' => EditorRequestFactory::new()->create(),
|
2023-12-31 22:35:13 +01:00
|
|
|
'excerpt' => $this->faker->words(10, true),
|
|
|
|
'config' => ['sections' => []],
|
2024-03-13 15:48:08 +01:00
|
|
|
'from' => $this->faker->dateTimeBetween('+1 week', '+4 weeks')->format('Y-m-d H:i:s'),
|
|
|
|
'to' => $this->faker->dateTimeBetween('+1 week', '+4 weeks')->format('Y-m-d H:i:s'),
|
2024-01-12 22:52:42 +01:00
|
|
|
'registration_from' => $this->faker->dateTimeBetween('-2 weeks', 'now')->format('Y-m-d H:i:s'),
|
|
|
|
'registration_until' => $this->faker->dateTimeBetween('now', '+2 weeks')->format('Y-m-d H:i:s'),
|
2024-04-20 00:04:20 +02:00
|
|
|
'mail_top' => EditorRequestFactory::new()->create(),
|
|
|
|
'mail_bottom' => EditorRequestFactory::new()->create(),
|
2024-05-27 18:49:11 +02:00
|
|
|
'is_active' => true,
|
|
|
|
'is_private' => false,
|
2023-12-27 22:54:58 +01:00
|
|
|
];
|
|
|
|
}
|
2023-12-31 22:35:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array<int, FormtemplateSectionRequest> $sections
|
|
|
|
*/
|
|
|
|
public function sections(array $sections): self
|
|
|
|
{
|
2024-01-10 22:14:27 +01:00
|
|
|
return $this->state(['config' => ['sections' => array_map(fn ($section) => $section->create(), $sections)]]);
|
2023-12-31 22:35:13 +01:00
|
|
|
}
|
|
|
|
|
2024-03-15 01:19:52 +01:00
|
|
|
/**
|
2024-03-15 01:59:22 +01:00
|
|
|
* @param array<int, FormtemplateFieldRequest> $fields
|
2024-03-15 01:19:52 +01:00
|
|
|
*/
|
|
|
|
public function fields(array $fields): self
|
|
|
|
{
|
|
|
|
return $this->sections([FormtemplateSectionRequest::new()->fields($fields)]);
|
|
|
|
}
|
|
|
|
|
2023-12-31 22:35:13 +01:00
|
|
|
/**
|
2024-01-10 21:31:34 +01:00
|
|
|
* @param mixed $parameters
|
2023-12-31 22:35:13 +01:00
|
|
|
*/
|
|
|
|
public function __call($method, $parameters): self
|
|
|
|
{
|
|
|
|
return $this->state([str($method)->snake()->toString() => $parameters[0]]);
|
|
|
|
}
|
2024-04-20 00:04:20 +02:00
|
|
|
|
|
|
|
public function mailTop(EditorRequestFactory $factory): self
|
|
|
|
{
|
|
|
|
return $this->state(['mail_top' => $factory->create()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function mailBottom(EditorRequestFactory $factory): self
|
|
|
|
{
|
|
|
|
return $this->state(['mail_bottom' => $factory->create()]);
|
|
|
|
}
|
2024-04-24 00:02:27 +02:00
|
|
|
|
|
|
|
public function description(EditorRequestFactory $factory): self
|
|
|
|
{
|
|
|
|
return $this->state(['description' => $factory->create()]);
|
|
|
|
}
|
2023-12-27 22:54:58 +01:00
|
|
|
}
|