Add EditorData for forms texts
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
1ef7995ec2
commit
c3f6d3827b
|
@ -32,9 +32,9 @@ class Form extends Model implements HasMedia
|
||||||
public $casts = [
|
public $casts = [
|
||||||
'config' => FormConfigData::class,
|
'config' => FormConfigData::class,
|
||||||
'meta' => 'json',
|
'meta' => 'json',
|
||||||
'description' => 'json',
|
'description' => EditorData::class,
|
||||||
'mail_top' => 'json',
|
'mail_top' => EditorData::class,
|
||||||
'mail_bottom' => 'json',
|
'mail_bottom' => EditorData::class,
|
||||||
'is_active' => 'boolean',
|
'is_active' => 'boolean',
|
||||||
'is_private' => 'boolean',
|
'is_private' => 'boolean',
|
||||||
'export' => ExportData::class,
|
'export' => ExportData::class,
|
||||||
|
|
|
@ -11,9 +11,9 @@ abstract class ConditionResolver
|
||||||
* @param array<string, mixed> $content
|
* @param array<string, mixed> $content
|
||||||
* @return array<string, mixed>
|
* @return array<string, mixed>
|
||||||
*/
|
*/
|
||||||
public function makeBlocks(array $content): array
|
public function makeBlocks(EditorData $data): array
|
||||||
{
|
{
|
||||||
return array_filter(data_get($content, 'blocks', []), fn ($block) => $this->filterBlock($block));
|
return array_filter($data->blocks, fn ($block) => $this->filterBlock($block));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,15 +43,15 @@ class FormFactory extends Factory
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => $this->faker->words(4, true),
|
'name' => $this->faker->words(4, true),
|
||||||
'description' => EditorRequestFactory::new()->create(),
|
'description' => EditorRequestFactory::new()->toData(),
|
||||||
'excerpt' => $this->faker->words(10, true),
|
'excerpt' => $this->faker->words(10, true),
|
||||||
'config' => ['sections' => []],
|
'config' => ['sections' => []],
|
||||||
'from' => $this->faker->dateTimeBetween('+1 week', '+4 weeks')->format('Y-m-d H:i:s'),
|
'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'),
|
'to' => $this->faker->dateTimeBetween('+1 week', '+4 weeks')->format('Y-m-d H:i:s'),
|
||||||
'registration_from' => $this->faker->dateTimeBetween('-2 weeks', 'now')->format('Y-m-d H:i:s'),
|
'registration_from' => $this->faker->dateTimeBetween('-2 weeks', 'now')->format('Y-m-d H:i:s'),
|
||||||
'registration_until' => $this->faker->dateTimeBetween('now', '+2 weeks')->format('Y-m-d H:i:s'),
|
'registration_until' => $this->faker->dateTimeBetween('now', '+2 weeks')->format('Y-m-d H:i:s'),
|
||||||
'mail_top' => EditorRequestFactory::new()->create(),
|
'mail_top' => EditorRequestFactory::new()->toData(),
|
||||||
'mail_bottom' => EditorRequestFactory::new()->create(),
|
'mail_bottom' => EditorRequestFactory::new()->toData(),
|
||||||
'is_active' => true,
|
'is_active' => true,
|
||||||
'is_private' => false,
|
'is_private' => false,
|
||||||
'export' => ExportData::from([]),
|
'export' => ExportData::from([]),
|
||||||
|
@ -85,16 +85,16 @@ class FormFactory extends Factory
|
||||||
|
|
||||||
public function mailTop(EditorRequestFactory $factory): self
|
public function mailTop(EditorRequestFactory $factory): self
|
||||||
{
|
{
|
||||||
return $this->state(['mail_top' => $factory->create()]);
|
return $this->state(['mail_top' => $factory->toData()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function mailBottom(EditorRequestFactory $factory): self
|
public function mailBottom(EditorRequestFactory $factory): self
|
||||||
{
|
{
|
||||||
return $this->state(['mail_bottom' => $factory->create()]);
|
return $this->state(['mail_bottom' => $factory->toData()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function description(EditorRequestFactory $factory): self
|
public function description(EditorRequestFactory $factory): self
|
||||||
{
|
{
|
||||||
return $this->state(['description' => $factory->create()]);
|
return $this->state(['description' => $factory->toData()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('forms', function (Blueprint $table) {
|
||||||
|
$table->json('description')->after('name')->default(json_encode(['time' => 4, 'blocks' => [], 'version' => '1.0']))->change();
|
||||||
|
$table->json('mail_top')->after('name')->default(json_encode(['time' => 4, 'blocks' => [], 'version' => '1.0']))->change();
|
||||||
|
$table->json('mail_bottom')->after('name')->default(json_encode(['time' => 4, 'blocks' => [], 'version' => '1.0']))->change();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('formtemplates', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('mail_top');
|
||||||
|
$table->dropColumn('mail_bottom');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
|
@ -241,24 +241,6 @@ class FormRegisterMailTest extends FormTestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItSendsEmailWhenMailTopIsEmpty(): void
|
|
||||||
{
|
|
||||||
$this->login()->loginNami()->withoutExceptionHandling();
|
|
||||||
|
|
||||||
$participant = Participant::factory()->for(
|
|
||||||
Form::factory()
|
|
||||||
->fields([
|
|
||||||
$this->textField('firstname')->specialType(SpecialType::FIRSTNAME),
|
|
||||||
$this->textField('lastname')->specialType(SpecialType::LASTNAME),
|
|
||||||
])->state(['mail_top' => []])
|
|
||||||
)
|
|
||||||
->data(['firstname' => 'Max', 'lastname' => 'Muster'])
|
|
||||||
->create();
|
|
||||||
|
|
||||||
$mail = new ConfirmRegistrationMail($participant);
|
|
||||||
$mail->assertSeeInText('Max');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider blockDataProvider
|
* @dataProvider blockDataProvider
|
||||||
* @param array<string, mixed> $conditions
|
* @param array<string, mixed> $conditions
|
||||||
|
|
|
@ -73,6 +73,14 @@ class FormRequest extends RequestFactory
|
||||||
return $this->state([str($method)->snake()->toString() => $args[0]]);
|
return $this->state([str($method)->snake()->toString() => $args[0]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, FormtemplateFieldRequest> $fields
|
||||||
|
*/
|
||||||
|
public function fields(array $fields): self
|
||||||
|
{
|
||||||
|
return $this->sections([FormtemplateSectionRequest::new()->fields($fields)]);
|
||||||
|
}
|
||||||
|
|
||||||
public function headerImage(string $fileName): self
|
public function headerImage(string $fileName): self
|
||||||
{
|
{
|
||||||
UploadedFile::fake()->image($fileName, 1000, 1000)->storeAs('media-library', $fileName, 'temp');
|
UploadedFile::fake()->image($fileName, 1000, 1000)->storeAs('media-library', $fileName, 'temp');
|
||||||
|
|
|
@ -41,9 +41,9 @@ class FormStoreActionTest extends FormTestCase
|
||||||
$this->assertEquals('formname', $form->name);
|
$this->assertEquals('formname', $form->name);
|
||||||
$this->assertEquals('lorem ipsum', $form->prevention_text->blocks[0]['data']['text']);
|
$this->assertEquals('lorem ipsum', $form->prevention_text->blocks[0]['data']['text']);
|
||||||
$this->assertEquals('avff', $form->excerpt);
|
$this->assertEquals('avff', $form->excerpt);
|
||||||
$this->assertEquals($description->paragraphBlock(10, 'Lorem'), $form->description);
|
$this->assertEquals('Lorem', $form->description->blocks[0]['data']['text']);
|
||||||
$this->assertEquals(json_decode('{"time":1,"blocks":[{"id":11,"type":"paragraph","data":{"text":"lala"},"tunes":{"condition":{"mode":"all","ifs":[]}}}],"version":"1.0"}', true), $form->mail_top);
|
$this->assertEquals('lala', $form->mail_top->blocks[0]['data']['text']);
|
||||||
$this->assertEquals(json_decode('{"time":1,"blocks":[{"id":12,"type":"paragraph","data":{"text":"lalab"},"tunes":{"condition":{"mode":"all","ifs":[]}}}],"version":"1.0"}', true), $form->mail_bottom);
|
$this->assertEquals('lalab', $form->mail_bottom->blocks[0]['data']['text']);
|
||||||
$this->assertEquals('2023-05-04 01:00', $form->registration_from->format('Y-m-d H:i'));
|
$this->assertEquals('2023-05-04 01:00', $form->registration_from->format('Y-m-d H:i'));
|
||||||
$this->assertEquals(true, $form->is_active);
|
$this->assertEquals(true, $form->is_active);
|
||||||
$this->assertEquals('2023-07-07 01:00', $form->registration_until->format('Y-m-d H:i'));
|
$this->assertEquals('2023-07-07 01:00', $form->registration_until->format('Y-m-d H:i'));
|
||||||
|
|
|
@ -19,10 +19,8 @@ class FormUpdateActionTest extends FormTestCase
|
||||||
{
|
{
|
||||||
$this->login()->loginNami()->withoutExceptionHandling();
|
$this->login()->loginNami()->withoutExceptionHandling();
|
||||||
$form = Form::factory()->create();
|
$form = Form::factory()->create();
|
||||||
$payload = FormRequest::new()->sections([
|
$payload = FormRequest::new()->fields([
|
||||||
FormtemplateSectionRequest::new()->fields([
|
|
||||||
$this->dateField()->state(['max_today' => true]),
|
$this->dateField()->state(['max_today' => true]),
|
||||||
])
|
|
||||||
])->create();
|
])->create();
|
||||||
|
|
||||||
$this->patchJson(route('form.update', ['form' => $form]), $payload)
|
$this->patchJson(route('form.update', ['form' => $form]), $payload)
|
||||||
|
@ -33,6 +31,24 @@ class FormUpdateActionTest extends FormTestCase
|
||||||
$this->assertTrue($form->config->sections->get(0)->fields->get(0)->maxToday);
|
$this->assertTrue($form->config->sections->get(0)->fields->get(0)->maxToday);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItSetsTexts(): void
|
||||||
|
{
|
||||||
|
$this->login()->loginNami()->withoutExceptionHandling();
|
||||||
|
$form = Form::factory()->create();
|
||||||
|
$payload = FormRequest::new()->fields([])
|
||||||
|
->mailTop(EditorRequestFactory::new()->text(11, 'lala'))
|
||||||
|
->mailBottom(EditorRequestFactory::new()->text(12, 'lalab'))
|
||||||
|
->description(EditorRequestFactory::new()->text(12, 'desc'))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$this->patchJson(route('form.update', ['form' => $form]), $payload)
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
$this->assertEquals('lala', $form->fresh()->mail_top->blocks[0]['data']['text']);
|
||||||
|
$this->assertEquals('lalab', $form->fresh()->mail_bottom->blocks[0]['data']['text']);
|
||||||
|
$this->assertEquals('desc', $form->fresh()->description->blocks[0]['data']['text']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testItClearsFrontendCacheWhenFormUpdated(): void
|
public function testItClearsFrontendCacheWhenFormUpdated(): void
|
||||||
{
|
{
|
||||||
$this->login()->loginNami()->withoutExceptionHandling();
|
$this->login()->loginNami()->withoutExceptionHandling();
|
||||||
|
@ -56,17 +72,14 @@ class FormUpdateActionTest extends FormTestCase
|
||||||
public function testItUpdatesActiveColumnsWhenFieldRemoved(): void
|
public function testItUpdatesActiveColumnsWhenFieldRemoved(): void
|
||||||
{
|
{
|
||||||
$this->login()->loginNami()->withoutExceptionHandling();
|
$this->login()->loginNami()->withoutExceptionHandling();
|
||||||
$form = Form::factory()
|
$form = Form::factory()->fields([
|
||||||
->sections([FormtemplateSectionRequest::new()->fields([
|
|
||||||
$this->textField('firstname'),
|
$this->textField('firstname'),
|
||||||
$this->textField('geb'),
|
$this->textField('geb'),
|
||||||
$this->textField('lastname'),
|
$this->textField('lastname'),
|
||||||
])])
|
|
||||||
->create();
|
|
||||||
$payload = FormRequest::new()->sections([
|
|
||||||
FormtemplateSectionRequest::new()->fields([
|
|
||||||
$this->textField('firstname'),
|
|
||||||
])
|
])
|
||||||
|
->create();
|
||||||
|
$payload = FormRequest::new()->fields([
|
||||||
|
$this->textField('firstname'),
|
||||||
])->create();
|
])->create();
|
||||||
|
|
||||||
$this->patchJson(route('form.update', ['form' => $form]), $payload)->assertSessionDoesntHaveErrors()->assertOk();
|
$this->patchJson(route('form.update', ['form' => $form]), $payload)->assertSessionDoesntHaveErrors()->assertOk();
|
||||||
|
@ -113,14 +126,12 @@ class FormUpdateActionTest extends FormTestCase
|
||||||
{
|
{
|
||||||
$this->login()->loginNami()->withoutExceptionHandling();
|
$this->login()->loginNami()->withoutExceptionHandling();
|
||||||
$form = Form::factory()
|
$form = Form::factory()
|
||||||
->sections([FormtemplateSectionRequest::new()->fields([])])
|
->fields([])
|
||||||
->create();
|
->create();
|
||||||
$payload = FormRequest::new()->sections([
|
$payload = FormRequest::new()->fields([
|
||||||
FormtemplateSectionRequest::new()->fields([
|
|
||||||
$this->textField('firstname'),
|
$this->textField('firstname'),
|
||||||
$this->textField('geb'),
|
$this->textField('geb'),
|
||||||
$this->textField('lastname'),
|
$this->textField('lastname'),
|
||||||
])
|
|
||||||
])->create();
|
])->create();
|
||||||
|
|
||||||
$this->patchJson(route('form.update', ['form' => $form]), $payload)->assertSessionDoesntHaveErrors()->assertOk();
|
$this->patchJson(route('form.update', ['form' => $form]), $payload)->assertSessionDoesntHaveErrors()->assertOk();
|
||||||
|
|
Loading…
Reference in New Issue