diff --git a/app/Form/Actions/PreventionRememberAction.php b/app/Form/Actions/PreventionRememberAction.php index c6ff78cd..e999337a 100644 --- a/app/Form/Actions/PreventionRememberAction.php +++ b/app/Form/Actions/PreventionRememberAction.php @@ -27,7 +27,7 @@ class PreventionRememberAction return; } - $body = app(PreventionSettings::class)->formmail + $body = app(PreventionSettings::class)->refresh()->formmail ->placeholder('formname', $participant->form->name) ->append($participant->form->prevention_text); diff --git a/app/Lib/Editor/EditorData.php b/app/Lib/Editor/EditorData.php index 094b3fb7..f395a50c 100644 --- a/app/Lib/Editor/EditorData.php +++ b/app/Lib/Editor/EditorData.php @@ -42,15 +42,14 @@ class EditorData extends Data implements Editorable public function append(Editorable $editorable): self { - return self::from([ - ...$this->toArray(), - 'blocks' => array_merge($this->blocks, $editorable->toEditorData()->blocks), - ]); + $this->blocks = array_merge($this->blocks, $editorable->toEditorData()->blocks); + + return $this; } public function replaceWithList(string $blockContent, array $replacements): self { - $blocks = collect($this->blocks)->map(function ($block) use ($blockContent, $replacements) { + $this->blocks = collect($this->blocks)->map(function ($block) use ($blockContent, $replacements) { if (data_get($block, 'type') !== 'paragraph') { return $block; } @@ -72,10 +71,8 @@ class EditorData extends Data implements Editorable return $block; })->toArray(); - return self::from([ - ...$this->toArray(), - 'blocks' => $blocks, - ]); + + return $this; } public function toEditorData(): EditorData diff --git a/tests/Feature/Member/PreventionTest.php b/tests/Feature/Member/PreventionTest.php index 9f64cc31..0fb1809a 100644 --- a/tests/Feature/Member/PreventionTest.php +++ b/tests/Feature/Member/PreventionTest.php @@ -186,7 +186,7 @@ class PreventionTest extends TestCase public function testItRendersSetttingMail(): void { Mail::fake(); - app(PreventionSettings::class)->fake([ + app(PreventionSettings::class)->fill([ 'formmail' => EditorRequestFactory::new()->paragraphs(["lorem lala {formname} g", "{wanted}", "bbb"])->toData() ])->save(); $form = $this->createForm(); @@ -203,7 +203,7 @@ class PreventionTest extends TestCase public function testItAppendsTextOfForm(): void { Mail::fake(); - app(PreventionSettings::class)->fake([ + app(PreventionSettings::class)->fill([ 'formmail' => EditorRequestFactory::new()->paragraphs(["::first::"])->toData() ])->save(); $form = $this->createForm(); @@ -217,6 +217,24 @@ class PreventionTest extends TestCase ])); } + public function testItDoesntAppendTextTwice(): void + { + Mail::fake(); + app(PreventionSettings::class)->fill(['frommail' => EditorRequestFactory::new()->paragraphs(["::first::"])->toData()])->save(); + tap($this->createForm(), function ($f) { + $f->update(['prevention_text' => EditorRequestFactory::new()->paragraphs(['oberhausen'])->toData()]); + $this->createParticipant($f); + }); + tap($this->createForm(), function ($f) { + $f->update(['prevention_text' => EditorRequestFactory::new()->paragraphs(['siegburg'])->toData()]); + $this->createParticipant($f); + }); + + PreventionRememberAction::run(); + + Mail::assertSent(PreventionRememberMail::class, fn ($mail) => $mail->bodyText->hasAll(['oberhausen']) && !$mail->bodyText->hasAll(['siegburg'])); + } + public function testItDisplaysBodyTextInMail(): void { $form = $this->createForm(); diff --git a/tests/Unit/EditorDataTest.php b/tests/Unit/EditorDataTest.php index 45670294..0803ac62 100644 --- a/tests/Unit/EditorDataTest.php +++ b/tests/Unit/EditorDataTest.php @@ -12,7 +12,7 @@ class EditorDataTest extends TestCase { $data = EditorRequestFactory::new()->paragraphs(['{search}'])->toData(); - $data = $data->replaceWithList('search', ['A', 'B']); + $data->replaceWithList('search', ['A', 'B']); $this->assertEquals('A', data_get($data->blocks, '0.data.items.0.content')); }