2023-03-14 23:55:50 +01:00
|
|
|
<?php
|
|
|
|
|
2024-01-28 11:42:32 +01:00
|
|
|
namespace Tests\EndToEnd\Member;
|
2023-03-14 23:55:50 +01:00
|
|
|
|
|
|
|
use App\Member\Member;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
2024-01-28 11:42:32 +01:00
|
|
|
use Tests\EndToEndTestCase;
|
2023-03-14 23:55:50 +01:00
|
|
|
|
2024-01-28 11:42:32 +01:00
|
|
|
class ExportCsvActionTest extends EndToEndTestCase
|
2023-03-14 23:55:50 +01:00
|
|
|
{
|
|
|
|
public function testItExportsACsvFile(): void
|
|
|
|
{
|
|
|
|
Storage::fake('temp');
|
|
|
|
|
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
2023-05-15 15:12:12 +02:00
|
|
|
Member::factory()->defaults()->postBillKind()->create(['firstname' => 'Jane', 'main_phone' => '+49 176 70343221', 'email' => 'max@muster.de']);
|
2023-03-14 23:55:50 +01:00
|
|
|
Member::factory()->defaults()->emailBillKind()->create(['firstname' => 'Max']);
|
|
|
|
|
2024-01-28 11:42:32 +01:00
|
|
|
sleep(1);
|
2023-03-14 23:55:50 +01:00
|
|
|
$response = $this->callFilter('member-export', ['bill_kind' => 'Post']);
|
|
|
|
|
|
|
|
$response->assertDownload('mitglieder.csv');
|
|
|
|
$contents = Storage::disk('temp')->get('mitglieder.csv');
|
|
|
|
$this->assertTrue(str_contains($contents, 'Jane'));
|
2023-03-15 00:08:20 +01:00
|
|
|
$this->assertTrue(str_contains($contents, '+49 176 70343221'));
|
2023-05-15 15:12:12 +02:00
|
|
|
$this->assertTrue(str_contains($contents, 'max@muster.de'));
|
2023-03-14 23:55:50 +01:00
|
|
|
$this->assertFalse(str_contains($contents, 'Max'));
|
|
|
|
}
|
2024-01-28 11:42:32 +01:00
|
|
|
|
|
|
|
public function testItOrdersByLastname(): void
|
|
|
|
{
|
|
|
|
Storage::fake('temp');
|
|
|
|
|
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
|
|
|
Member::factory()->defaults()->create(['lastname' => 'C']);
|
|
|
|
Member::factory()->defaults()->create(['lastname' => 'A']);
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
$response = $this->callFilter('member-export', []);
|
|
|
|
|
|
|
|
$response->assertDownload('mitglieder.csv');
|
|
|
|
$contents = Storage::disk('temp')->get('mitglieder.csv');
|
|
|
|
$this->assertEquals(['A', 'C'], collect(explode("\n", $contents))
|
|
|
|
->filter(fn ($line) => $line !== '')
|
|
|
|
->filter(fn ($line) => !str($line)->startsWith('Nachname'))
|
|
|
|
->map(fn ($line) => (string) str($line)->substr(0, 1))
|
|
|
|
->values()
|
|
|
|
->toArray());
|
|
|
|
}
|
2023-03-14 23:55:50 +01:00
|
|
|
}
|