adrema/tests/RequestFactories/EditorRequestFactory.php

78 lines
2.0 KiB
PHP
Raw Normal View History

2024-02-02 01:05:45 +01:00
<?php
namespace Tests\RequestFactories;
2024-07-04 23:54:37 +02:00
use App\Lib\Editor\EditorData;
2024-02-02 01:05:45 +01:00
use Worksome\RequestFactories\RequestFactory;
class EditorRequestFactory extends RequestFactory
{
/**
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'time' => 45069432,
'blocks' => [
['id' => 'TTzz66', 'type' => 'paragraph', 'data' => ['text' => 'lorem']]
],
'version' => '1.0',
];
}
2024-04-24 15:39:07 +02:00
/**
* @param array<string, mixed> $conditions
*/
public function text(int $id, string $text, array $conditions = ['mode' => 'all', 'ifs' => []]): self
2024-02-02 01:05:45 +01:00
{
return $this->state($this->paragraphBlock($id, $text, $conditions));
2024-02-02 01:05:45 +01:00
}
2024-02-09 00:21:33 +01:00
/**
2024-04-24 15:39:07 +02:00
* @param array<string, mixed> $conditions
2024-02-09 00:21:33 +01:00
* @return array<string, mixed>
*/
public function paragraphBlock(int $id, string $text, array $conditions = ['mode' => 'all', 'ifs' => []]): array
2024-02-02 01:05:45 +01:00
{
return [
'time' => 1,
'version' => '1.0',
'blocks' => [
[
'id' => $id,
'type' => 'paragraph',
'data' => ['text' => $text],
'tunes' => [
'condition' => $conditions
]
]
2024-02-02 01:05:45 +01:00
],
];
}
2024-07-04 23:54:37 +02:00
/**
* @param array<int, string> $paragraphs
*/
public function paragraphs(array $paragraphs): self
{
return $this->state([
'time' => 1,
'version' => '1.0',
'blocks' => collect($paragraphs)->map(fn ($paragraph) => [
'id' => $this->faker->numberBetween([0, 10000]),
'type' => 'paragraph',
'data' => ['text' => $paragraph],
'tunes' => [
'condition' => ['mode' => 'all', 'ifs' => []]
]
])->toArray(),
]);
}
public function toData(): EditorData
{
return EditorData::from($this->create());
}
2024-02-02 01:05:45 +01:00
}