adrema/tests/Feature/Form/FormRequest.php

92 lines
2.9 KiB
PHP
Raw Normal View History

2023-12-27 22:54:58 +01:00
<?php
namespace Tests\Feature\Form;
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-01-10 21:55:19 +01:00
* @method self mailTop(string $content)
* @method self mailBottom(string $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)
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'),
'mail_top' => $this->faker->text(),
'mail_bottom' => $this->faker->text(),
2024-04-15 16:23:32 +02:00
'header_image' => $this->getHeaderImagePayload(str()->uuid() . '.jpg'),
'mailattachments' => [],
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
}