2022-12-06 21:25:47 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Letter;
|
|
|
|
|
|
|
|
use App\Letter\BillDocument;
|
|
|
|
use App\Letter\DocumentFactory;
|
|
|
|
use App\Letter\LetterSettings;
|
2022-12-07 00:40:53 +01:00
|
|
|
use App\Letter\Queries\LetterMemberQuery;
|
|
|
|
use App\Letter\Queries\SingleMemberQuery;
|
2022-12-06 21:25:47 +01:00
|
|
|
use App\Letter\RememberDocument;
|
|
|
|
use App\Member\Member;
|
|
|
|
use App\Payment\Payment;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2022-12-13 23:11:32 +01:00
|
|
|
use Tests\RequestFactories\Child;
|
2022-12-06 21:25:47 +01:00
|
|
|
use Tests\TestCase;
|
|
|
|
use Zoomyboy\Tex\Tex;
|
|
|
|
|
|
|
|
class DocumentFactoryTest extends TestCase
|
|
|
|
{
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @testWith ["\\App\\Letter\\BillDocument"]
|
|
|
|
* ["\\App\\Letter\\RememberDocument"]
|
|
|
|
*/
|
|
|
|
public function testItDoesntReturnARepositoryWhenMemberDoesntHavePayments(): void
|
|
|
|
{
|
|
|
|
$member = Member::factory()->defaults()->create();
|
2022-12-07 00:40:53 +01:00
|
|
|
$letter = app(DocumentFactory::class)->singleLetter(BillDocument::class, $this->query($member));
|
2022-12-06 21:25:47 +01:00
|
|
|
$this->assertNull($letter);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItDisplaysMemberInformation(): void
|
|
|
|
{
|
|
|
|
$member = Member::factory()
|
|
|
|
->defaults()
|
|
|
|
->state([
|
|
|
|
'firstname' => '::firstname::',
|
|
|
|
'lastname' => '::lastname::',
|
|
|
|
'address' => '::street::',
|
|
|
|
'zip' => '::zip::',
|
|
|
|
'location' => '::location::',
|
|
|
|
])
|
2022-12-13 23:11:32 +01:00
|
|
|
->has(Payment::factory()->notPaid()->nr('1995')->subscription('::subName::', [
|
|
|
|
new Child('a', 1000),
|
|
|
|
new Child('a', 500),
|
|
|
|
]))
|
2022-12-06 21:25:47 +01:00
|
|
|
->create();
|
|
|
|
|
2022-12-07 00:40:53 +01:00
|
|
|
$letter = app(DocumentFactory::class)->singleLetter(BillDocument::class, $this->query($member));
|
2022-12-06 21:25:47 +01:00
|
|
|
|
|
|
|
$letter->assertHasAllContent([
|
|
|
|
'Rechnung',
|
|
|
|
'15.00',
|
2022-12-14 00:23:03 +01:00
|
|
|
'::subName:: 1995 für ::firstname:: ::lastname::',
|
2022-12-06 21:25:47 +01:00
|
|
|
'Mitgliedsbeitrag für ::lastname::',
|
|
|
|
'Familie ::lastname::\\\\::street::\\\\::zip:: ::location::',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-12-14 00:23:03 +01:00
|
|
|
public function testItDisplaysSplitPayments(): void
|
|
|
|
{
|
|
|
|
$member = Member::factory()
|
|
|
|
->defaults()
|
|
|
|
->state([
|
|
|
|
'firstname' => '::firstname::',
|
|
|
|
'lastname' => '::lastname::',
|
|
|
|
])
|
|
|
|
->has(Payment::factory()->notPaid()->nr('1995')->subscription('::subName::', [
|
|
|
|
new Child('a', 1000),
|
|
|
|
new Child('b', 500),
|
|
|
|
], ['split' => true]))
|
|
|
|
->create();
|
|
|
|
|
|
|
|
$letter = app(DocumentFactory::class)->singleLetter(BillDocument::class, $this->query($member));
|
|
|
|
|
|
|
|
$letter->assertHasAllContent([
|
|
|
|
'Rechnung',
|
|
|
|
'10.00',
|
|
|
|
'5.00',
|
|
|
|
'::subName:: (a) 1995 für ::firstname:: ::lastname::',
|
|
|
|
'::subName:: (b) 1995 für ::firstname:: ::lastname::',
|
|
|
|
'Mitgliedsbeitrag für ::lastname::',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-12-06 21:25:47 +01:00
|
|
|
public function testBillSetsFilename(): void
|
|
|
|
{
|
|
|
|
$member = Member::factory()
|
|
|
|
->defaults()
|
|
|
|
->state(['lastname' => '::lastname::'])
|
2022-12-13 23:11:32 +01:00
|
|
|
->has(Payment::factory()->notPaid()->nr('1995'))
|
2022-12-06 21:25:47 +01:00
|
|
|
->create();
|
|
|
|
|
2022-12-07 00:40:53 +01:00
|
|
|
$letter = app(DocumentFactory::class)->singleLetter(BillDocument::class, $this->query($member));
|
2022-12-06 21:25:47 +01:00
|
|
|
|
|
|
|
$this->assertEquals('rechnung-fur-lastname.pdf', $letter->compiledFilename());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRememberSetsFilename(): void
|
|
|
|
{
|
|
|
|
$member = Member::factory()
|
|
|
|
->defaults()
|
|
|
|
->state(['lastname' => '::lastname::'])
|
|
|
|
->has(Payment::factory()->notPaid())
|
|
|
|
->create();
|
|
|
|
|
2022-12-07 00:40:53 +01:00
|
|
|
$letter = app(DocumentFactory::class)->singleLetter(RememberDocument::class, $this->query($member));
|
2022-12-06 21:25:47 +01:00
|
|
|
|
|
|
|
$this->assertEquals('zahlungserinnerung-fur-lastname.pdf', $letter->compiledFilename());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItCreatesOneFileForFamilyMembers(): void
|
|
|
|
{
|
|
|
|
$firstMember = Member::factory()
|
|
|
|
->defaults()
|
|
|
|
->state(['firstname' => 'Max1', 'lastname' => '::lastname::', 'address' => '::address::', 'zip' => '12345', 'location' => '::location::'])
|
|
|
|
->has(Payment::factory()->notPaid()->nr('nr1'))
|
|
|
|
->create();
|
|
|
|
Member::factory()
|
|
|
|
->defaults()
|
|
|
|
->state(['firstname' => 'Max2', 'lastname' => '::lastname::', 'address' => '::address::', 'zip' => '12345', 'location' => '::location::'])
|
|
|
|
->has(Payment::factory()->notPaid()->nr('nr2'))
|
|
|
|
->create();
|
|
|
|
|
2022-12-07 00:40:53 +01:00
|
|
|
$letter = app(DocumentFactory::class)->singleLetter(BillDocument::class, $this->query($firstMember));
|
2022-12-06 21:25:47 +01:00
|
|
|
|
|
|
|
$letter->assertHasAllContent(['Max1', 'Max2', 'nr1', 'nr2']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @testWith ["App\\Letter\\BillDocument"]
|
|
|
|
* ["App\\Letter\\RememberDocument"]
|
|
|
|
*/
|
|
|
|
public function testItDisplaysSettings(string $type): void
|
|
|
|
{
|
|
|
|
LetterSettings::fake([
|
|
|
|
'from_long' => 'langer Stammesname',
|
|
|
|
'from' => 'Stammeskurz',
|
|
|
|
'mobile' => '+49 176 55555',
|
|
|
|
'email' => 'max@muster.de',
|
|
|
|
'website' => 'https://example.com',
|
|
|
|
'address' => 'Musterstr 4',
|
|
|
|
'place' => 'Münster',
|
|
|
|
'zip' => '12345',
|
|
|
|
'iban' => 'DE444',
|
|
|
|
'bic' => 'SOLSSSSS',
|
|
|
|
]);
|
|
|
|
$member = Member::factory()
|
|
|
|
->defaults()
|
|
|
|
->has(Payment::factory()->notPaid()->nr('nr2'))
|
|
|
|
->create();
|
|
|
|
|
2022-12-07 00:40:53 +01:00
|
|
|
$letter = app(DocumentFactory::class)->singleLetter($type, $this->query($member));
|
2022-12-06 21:25:47 +01:00
|
|
|
|
|
|
|
$letter->assertHasAllContent([
|
|
|
|
'langer Stammesname',
|
|
|
|
'Stammeskurz',
|
|
|
|
'+49 176 55555',
|
|
|
|
'max@muster.de',
|
|
|
|
'https://example.com',
|
|
|
|
'Musterstr 4',
|
|
|
|
'Münster',
|
|
|
|
'12345',
|
|
|
|
'DE444',
|
|
|
|
'SOLSSSSS',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItGeneratesAPdf(): void
|
|
|
|
{
|
|
|
|
Tex::fake();
|
|
|
|
$member = Member::factory()
|
|
|
|
->defaults()
|
|
|
|
->has(Payment::factory()->notPaid())
|
|
|
|
->create(['lastname' => 'lastname']);
|
|
|
|
$this->withoutExceptionHandling();
|
|
|
|
$this->login()->init()->loginNami();
|
|
|
|
|
|
|
|
$response = $this->call('GET', "/member/{$member->id}/pdf", [
|
|
|
|
'type' => BillDocument::class,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals('application/pdf', $response->headers->get('content-type'));
|
|
|
|
$this->assertEquals('inline; filename="rechnung-fur-lastname.pdf"', $response->headers->get('content-disposition'));
|
|
|
|
}
|
2022-12-07 00:40:53 +01:00
|
|
|
|
|
|
|
private function query(Member $member): LetterMemberQuery
|
|
|
|
{
|
|
|
|
return new SingleMemberQuery($member);
|
|
|
|
}
|
2022-12-06 21:25:47 +01:00
|
|
|
}
|