From 56af6f4cbfc6052f6af122cbfc767ec65c33bd26 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Wed, 12 Nov 2025 03:30:38 +0100 Subject: [PATCH] Fix tests --- .../Actions/CreateExcelDocumentAction.php | 2 +- app/Form/Data/FieldCollection.php | 2 +- .../Form/ParticipantExportActionTest.php | 25 ++++++++++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/Form/Actions/CreateExcelDocumentAction.php b/app/Form/Actions/CreateExcelDocumentAction.php index 42a48199..cdcf52bb 100644 --- a/app/Form/Actions/CreateExcelDocumentAction.php +++ b/app/Form/Actions/CreateExcelDocumentAction.php @@ -73,7 +73,7 @@ class CreateExcelDocumentAction public function rowsFor(Collection $participants): array { return $participants->map(fn ($participant) => $participant->getFields()->presentValues() ->put('Abgemeldet am', $participant->cancelled_at?->format('d.m.Y H:i:s') ?: '') - ->prepend('ID', $participant->id) + ->prepend((string) $participant->id, 'ID') )->toArray(); } diff --git a/app/Form/Data/FieldCollection.php b/app/Form/Data/FieldCollection.php index 261892f4..e6628429 100644 --- a/app/Form/Data/FieldCollection.php +++ b/app/Form/Data/FieldCollection.php @@ -111,7 +111,7 @@ class FieldCollection extends Collection */ public function presentValues(): Collection { - return $this->mapWithKeys(fn ($field) => [$field->name => $field->present()]); + return $this->mapWithKeys(fn ($field) => [$field->name => $field->presentRaw()]); } public function hasSpecialType(SpecialType $specialType): bool diff --git a/tests/Feature/Form/ParticipantExportActionTest.php b/tests/Feature/Form/ParticipantExportActionTest.php index 5c182567..9f3603d7 100644 --- a/tests/Feature/Form/ParticipantExportActionTest.php +++ b/tests/Feature/Form/ParticipantExportActionTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Form; +use DB; use App\Form\Models\Form; use App\Form\Models\Participant; use Illuminate\Foundation\Testing\DatabaseTransactions; @@ -20,15 +21,14 @@ it('testItShowsParticipantsAndColumns', function () { $this->login()->loginNami()->withoutExceptionHandling(); $form = Form::factory() ->has(Participant::factory()->data(['stufe' => 'Pfadfinder', 'vorname' => 'Max', 'select' => ['A', 'B']])) - ->sections([ - FormtemplateSectionRequest::new()->fields([ - $this->textField('vorname')->name('Vorname'), - $this->checkboxesField('select')->name('Abcselect')->options(['A', 'B', 'C']), - $this->dropdownField('stufe')->name('Stufe')->options(['Wölfling', 'Jungpfadfinder', 'Pfadfinder']), - ]), + ->fields([ + $this->textField('vorname')->name('Vorname'), + $this->checkboxesField('select')->name('Abcselect')->options(['A', 'B', 'C']), + $this->dropdownField('stufe')->name('Stufe')->options(['Wölfling', 'Jungpfadfinder', 'Pfadfinder']), ]) ->name('ZEM 2024') ->create(); + DB::table('participants')->where('id', $form->participants->first()->id)->update(['id' => 9909]); $this->get(route('form.export', ['form' => $form]))->assertDownload('tn-zem-2024.xlsx'); $contents = Storage::disk('temp')->get('tn-zem-2024.xlsx'); @@ -37,4 +37,17 @@ it('testItShowsParticipantsAndColumns', function () { $this->assertExcelContent('Pfadfinder', $contents); $this->assertExcelContent('Stufe', $contents); $this->assertExcelContent('Abcselect', $contents); + $this->assertExcelContent('9909', $contents); +}); + +it('shows cancelled at', function () { + Storage::fake('temp'); + $this->login()->loginNami()->withoutExceptionHandling(); + $form = Form::factory()->name('ZEM 2024') + ->has(Participant::factory()->state(['cancelled_at' => now()->subWeek()])) + ->create(); + + $this->get(route('form.export', ['form' => $form]))->assertDownload('tn-zem-2024.xlsx'); + $contents = Storage::disk('temp')->get('tn-zem-2024.xlsx'); + $this->assertExcelContent(now()->subWeek()->format('d.m.Y'), $contents); });