adrema/tests/Feature/Invoice/BillRememberDocumentTest.php

175 lines
5.7 KiB
PHP
Raw Normal View History

2022-12-06 21:25:47 +01:00
<?php
2023-04-18 22:08:45 +02:00
namespace Tests\Feature\Invoice;
use App\Invoice\BillDocument;
2023-11-30 23:54:16 +01:00
use App\Invoice\BillKind;
2023-04-18 22:08:45 +02:00
use App\Invoice\DocumentFactory;
2023-11-30 23:54:16 +01:00
use App\Invoice\Invoice;
2023-04-18 22:08:45 +02:00
use App\Invoice\InvoiceSettings;
2023-11-30 23:54:16 +01:00
use App\Invoice\Queries\BillKindQuery;
2023-04-18 22:08:45 +02:00
use App\Invoice\Queries\InvoiceMemberQuery;
use App\Invoice\Queries\SingleMemberQuery;
use App\Invoice\RememberDocument;
2022-12-06 21:25:47 +01:00
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;
2023-11-30 23:54:16 +01:00
class BillRememberDocumentTest extends TestCase
2022-12-06 21:25:47 +01:00
{
use DatabaseTransactions;
public function testItDisplaysMemberInformation(): void
{
$member = Member::factory()
->defaults()
->state([
'firstname' => '::firstname::',
'lastname' => '::lastname::',
'address' => '::street::',
'zip' => '::zip::',
'location' => '::location::',
])
2023-11-30 23:54:16 +01:00
->postBillKind()
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();
2023-11-30 23:54:16 +01:00
$invoice = BillDocument::fromMembers($this->query(BillDocument::class)->getMembers()->first());
2022-12-06 21:25:47 +01:00
2023-04-18 22:08:45 +02:00
$invoice->assertHasAllContent([
2022-12-06 21:25:47 +01:00
'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()
2023-11-30 23:54:16 +01:00
->postBillKind()
2022-12-14 00:23:03 +01:00
->state([
'firstname' => '::firstname::',
'lastname' => '::lastname::',
])
->has(Payment::factory()->notPaid()->nr('1995')->subscription('::subName::', [
new Child('a', 1000),
new Child('b', 500),
], ['split' => true]))
->create();
2023-11-30 23:54:16 +01:00
$invoice = BillDocument::fromMembers($this->query(BillDocument::class)->getMembers()->first());
2022-12-14 00:23:03 +01:00
2023-04-18 22:08:45 +02:00
$invoice->assertHasAllContent([
2022-12-14 00:23:03 +01:00
'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
{
2023-11-30 23:54:16 +01:00
Member::factory()
2022-12-06 21:25:47 +01:00
->defaults()
2023-11-30 23:54:16 +01:00
->postBillKind()
2022-12-06 21:25:47 +01:00
->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();
2023-11-30 23:54:16 +01:00
$invoice = BillDocument::fromMembers($this->query(BillDocument::class)->getMembers()->first());
2022-12-06 21:25:47 +01:00
2023-04-18 22:08:45 +02:00
$this->assertEquals('rechnung-fur-lastname.pdf', $invoice->compiledFilename());
2022-12-06 21:25:47 +01:00
}
public function testRememberSetsFilename(): void
{
2023-11-30 23:54:16 +01:00
Member::factory()
->postBillKind()
2022-12-06 21:25:47 +01:00
->defaults()
->state(['lastname' => '::lastname::'])
2023-05-08 23:10:08 +02:00
->has(Payment::factory()->notPaid()->state(['last_remembered_at' => now()->subMonths(6)]))
2022-12-06 21:25:47 +01:00
->create();
2023-11-30 23:54:16 +01:00
$invoice = RememberDocument::fromMembers($this->query(RememberDocument::class)->getMembers()->first());
2022-12-06 21:25:47 +01:00
2023-04-18 22:08:45 +02:00
$this->assertEquals('zahlungserinnerung-fur-lastname.pdf', $invoice->compiledFilename());
2022-12-06 21:25:47 +01:00
}
public function testItCreatesOneFileForFamilyMembers(): void
{
2023-11-30 23:54:16 +01:00
Member::factory()
2022-12-06 21:25:47 +01:00
->defaults()
2023-11-30 23:54:16 +01:00
->postBillKind()
2022-12-06 21:25:47 +01:00
->state(['firstname' => 'Max1', 'lastname' => '::lastname::', 'address' => '::address::', 'zip' => '12345', 'location' => '::location::'])
->has(Payment::factory()->notPaid()->nr('nr1'))
->create();
Member::factory()
->defaults()
2023-11-30 23:54:16 +01:00
->postBillKind()
2022-12-06 21:25:47 +01:00
->state(['firstname' => 'Max2', 'lastname' => '::lastname::', 'address' => '::address::', 'zip' => '12345', 'location' => '::location::'])
->has(Payment::factory()->notPaid()->nr('nr2'))
->create();
2023-11-30 23:54:16 +01:00
$this->assertCount(2, $this->query(BillDocument::class)->getMembers()->first());
2022-12-06 21:25:47 +01:00
}
/**
2023-04-18 22:08:45 +02:00
* @testWith ["App\\Invoice\\BillDocument"]
* ["App\\Invoice\\RememberDocument"]
2022-12-06 21:25:47 +01:00
*/
public function testItDisplaysSettings(string $type): void
{
2023-04-18 22:08:45 +02:00
InvoiceSettings::fake([
2022-12-06 21:25:47 +01:00
'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',
]);
2023-11-30 23:54:16 +01:00
Member::factory()
2022-12-06 21:25:47 +01:00
->defaults()
2023-11-30 23:54:16 +01:00
->postBillKind()
->has(Payment::factory()->notPaid()->nr('nr2')->state(['last_remembered_at' => now()->subYear()]))
2022-12-06 21:25:47 +01:00
->create();
2023-11-30 23:54:16 +01:00
$invoice = BillDocument::fromMembers($this->query(BillDocument::class)->getMembers()->first());
2022-12-06 21:25:47 +01:00
2023-04-18 22:08:45 +02:00
$invoice->assertHasAllContent([
2022-12-06 21:25:47 +01:00
'langer Stammesname',
'Stammeskurz',
'+49 176 55555',
'max@muster.de',
'https://example.com',
'Musterstr 4',
'Münster',
'12345',
'DE444',
'SOLSSSSS',
]);
}
2023-11-30 23:54:16 +01:00
/**
* @param class-string<Invoice> $type
*/
private function query(string $type): InvoiceMemberQuery
2022-12-07 00:40:53 +01:00
{
2023-11-30 23:54:16 +01:00
return (new BillKindQuery(BillKind::POST))->type($type);
2022-12-07 00:40:53 +01:00
}
2022-12-06 21:25:47 +01:00
}