adrema/tests/Feature/Form/FormRequest.php

84 lines
2.6 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;
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)
2023-12-31 21:02:40 +01:00
* @method self description(string $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),
'description' => $this->faker->text(),
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-01-12 23:29:18 +01:00
'header_image' => $this->getHeaderImagePayload(str()->uuid() . '.jpg')
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
}