adrema/tests/Feature/Form/FormRequest.php

97 lines
3.1 KiB
PHP
Raw Normal View History

2023-12-27 22:54:58 +01:00
<?php
namespace Tests\Feature\Form;
2024-06-29 18:54:56 +02:00
use App\Form\Data\ExportData;
2024-01-12 23:29:18 +01:00
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
2024-02-02 01:05:45 +01:00
use Tests\RequestFactories\EditorRequestFactory;
2023-12-27 22:54:58 +01:00
use Worksome\RequestFactories\RequestFactory;
/**
* @method self name(string $name)
2024-01-10 21:31:34 +01:00
* @method self from(string $date)
* @method self to(string $date)
2024-02-02 01:05:45 +01:00
* @method self description(?EditorRequestFactory $description)
2024-04-19 17:42:59 +02:00
* @method self mailTop(?EditorRequestFactory $content)
* @method self mailBottom(?EditorRequestFactory $content)
2023-12-31 21:02:40 +01:00
* @method self excerpt(string $description)
2024-01-10 21:31:34 +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:54:56 +02:00
* @method self export(ExportData $export)
2023-12-27 22:54:58 +01:00
*/
class FormRequest extends RequestFactory
{
/**
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => $this->faker->words(4, true),
2024-02-02 01:05:45 +01:00
'description' => [
'time' => 45069432,
'blocks' => [
['id' => 'TTzz66', 'type' => 'paragraph', 'data' => ['text' => 'lorem']]
],
'version' => '1.0',
],
2023-12-31 21:02:40 +01:00
'excerpt' => $this->faker->words(10, true),
2023-12-27 22:54:58 +01:00
'config' => ['sections' => []],
2023-12-31 21:46:52 +01:00
'from' => $this->faker->dateTime()->format('Y-m-d H:i:s'),
'to' => $this->faker->dateTime()->format('Y-m-d H:i:s'),
'registration_from' => $this->faker->dateTime()->format('Y-m-d H:i:s'),
'registration_until' => $this->faker->dateTime()->format('Y-m-d H:i:s'),
2024-04-19 17:42:59 +02:00
'mail_top' => EditorRequestFactory::new()->create(),
'mail_bottom' => EditorRequestFactory::new()->create(),
2024-04-15 16:23:32 +02:00
'header_image' => $this->getHeaderImagePayload(str()->uuid() . '.jpg'),
'mailattachments' => [],
2024-06-30 18:10:53 +02:00
'export' => ExportData::from([])->toArray(),
2023-12-27 22:54:58 +01:00
];
}
/**
* @param array<int, FormtemplateSectionRequest> $sections
*/
public function sections(array $sections): self
{
return $this->state(['config.sections' => $sections]);
}
/**
* @param mixed $args
*/
public function __call(string $method, $args): self
{
2023-12-31 21:46:52 +01:00
return $this->state([str($method)->snake()->toString() => $args[0]]);
2023-12-27 22:54:58 +01:00
}
2024-01-12 23:29:18 +01:00
public function headerImage(string $fileName): self
{
UploadedFile::fake()->image($fileName, 1000, 1000)->storeAs('media-library', $fileName, 'temp');
Storage::disk('temp')->assertExists('media-library/' . $fileName);
return $this->state([
'header_image' => $this->getHeaderImagePayload($fileName)
]);
}
/**
* @return array<string, mixed>
*/
private function getHeaderImagePayload(string $fileName): array
{
UploadedFile::fake()->image($fileName, 1000, 1000)->storeAs('media-library', $fileName, 'temp');
Storage::disk('temp')->assertExists('media-library/' . $fileName);
return [
'file_name' => $fileName,
'collection_name' => 'headerImage',
];
}
2023-12-27 22:54:58 +01:00
}