adrema/database/factories/Form/Models/FormFactory.php

102 lines
3.2 KiB
PHP
Raw Normal View History

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
2024-06-29 18:02:23 +02:00
use App\Form\Data\ExportData;
2023-12-27 22:54:58 +01:00
use App\Form\Models\Form;
2024-07-12 18:05:11 +02:00
use App\Lib\Editor\Condition;
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;
use Illuminate\Support\Carbon;
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;
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)
2024-06-29 18:02:23 +02:00
* @method self export(ExportData $data)
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-07-14 19:29:42 +02:00
'description' => EditorRequestFactory::new()->toData(),
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'),
'registration_from' => $this->faker->dateTimeBetween(Carbon::parse('-2 weeks'), now())->format('Y-m-d H:i:s'),
'registration_until' => $this->faker->dateTimeBetween(now(), Carbon::parse('+2 weeks'))->format('Y-m-d H:i:s'),
2024-07-14 19:29:42 +02:00
'mail_top' => EditorRequestFactory::new()->toData(),
'mail_bottom' => EditorRequestFactory::new()->toData(),
2024-05-27 18:49:11 +02:00
'is_active' => true,
'is_private' => false,
2024-06-30 18:51:14 +02:00
'export' => ExportData::from([]),
2024-07-12 18:05:11 +02:00
'prevention_conditions' => Condition::defaults(),
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]]);
}
public function mailTop(EditorRequestFactory $factory): self
{
2024-07-14 19:29:42 +02:00
return $this->state(['mail_top' => $factory->toData()]);
}
public function mailBottom(EditorRequestFactory $factory): self
{
2024-07-14 19:29:42 +02:00
return $this->state(['mail_bottom' => $factory->toData()]);
}
2024-04-24 00:02:27 +02:00
public function description(EditorRequestFactory $factory): self
{
2024-07-14 19:29:42 +02:00
return $this->state(['description' => $factory->toData()]);
2024-04-24 00:02:27 +02:00
}
2023-12-27 22:54:58 +01:00
}