Moved bank transfer logic to special module
This commit is contained in:
@@ -5,6 +5,7 @@ namespace Tests\Unit;
|
||||
use App\EventPaymentModules\EventPaymentModuleRegistry;
|
||||
use App\EventPaymentModules\Modules\AccountTransferPaymentModule;
|
||||
use App\EventPaymentModules\Modules\UndefinedPaymentModule;
|
||||
use App\EventPaymentModules\ProvidesGiroCode;
|
||||
use App\Models\PaymentMethod;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -49,6 +50,12 @@ class EventPaymentModuleRegistryTest extends TestCase
|
||||
$this->assertTrue($module->isConfigurationComplete(['iban' => 'DE123', 'account_owner' => 'Kasse']));
|
||||
}
|
||||
|
||||
public function test_only_account_transfer_provides_giro_code(): void
|
||||
{
|
||||
$this->assertInstanceOf(ProvidesGiroCode::class, new AccountTransferPaymentModule());
|
||||
$this->assertNotInstanceOf(ProvidesGiroCode::class, new UndefinedPaymentModule());
|
||||
}
|
||||
|
||||
public function test_defaults_are_built_from_modules(): void
|
||||
{
|
||||
$defaults = PaymentMethod::defaults();
|
||||
|
||||
@@ -52,8 +52,9 @@ class PaymentMethodOptionsTest extends TestCase
|
||||
$this->assertTrue(PaymentMethod::isConfigurationComplete($slug, ['iban' => 'DE123', 'account_owner' => 'Kasse']));
|
||||
}
|
||||
|
||||
public function test_slug_without_options_is_always_complete(): void
|
||||
public function test_unknown_slug_is_always_complete(): void
|
||||
{
|
||||
$this->assertTrue(PaymentMethod::isConfigurationComplete(PaymentMethod::PAYMENT_NOT_DEFINED, []));
|
||||
// Kein Modul -> keine Pflichtfelder -> stets vollständig.
|
||||
$this->assertTrue(PaymentMethod::isConfigurationComplete('NO_MODULE', []));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\EventPaymentModules\DTO\RegistrationSummaryRequest;
|
||||
use App\EventPaymentModules\Modules\AccountTransferPaymentModule;
|
||||
use App\EventPaymentModules\Modules\UndefinedPaymentModule;
|
||||
use App\Models\EventParticipant;
|
||||
use App\ValueObjects\Amount;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class RegistrationSummaryTest extends TestCase
|
||||
{
|
||||
private function participant(float $amount, float $amountPaid, string $purpose = 'Zweck'): EventParticipant
|
||||
{
|
||||
$participant = new EventParticipant();
|
||||
$participant->setRawAttributes([
|
||||
'payment_purpose' => $purpose,
|
||||
], true);
|
||||
// Amount-Casts umgehen und die Value-Objects direkt setzen.
|
||||
$participant->amount = new Amount($amount, ' Euro');
|
||||
$participant->amount_paid = new Amount($amountPaid, ' Euro');
|
||||
|
||||
return $participant;
|
||||
}
|
||||
|
||||
public function test_account_transfer_summary_builds_lines_from_config(): void
|
||||
{
|
||||
$module = new AccountTransferPaymentModule();
|
||||
$request = new RegistrationSummaryRequest(
|
||||
$this->participant(50.0, 0.0, 'Camp - Beitrag'),
|
||||
['account_owner' => 'Kasse', 'iban' => 'DE123', 'bic' => 'XY'],
|
||||
);
|
||||
|
||||
$summary = $module->registrationSummary($request);
|
||||
|
||||
$this->assertTrue($summary->hasPaymentInformation);
|
||||
$this->assertTrue($summary->showGiroCode);
|
||||
$this->assertNull($summary->html);
|
||||
|
||||
$byLabel = [];
|
||||
foreach ($summary->lines as $line) {
|
||||
$byLabel[$line['label']] = $line['value'];
|
||||
}
|
||||
$this->assertSame('Kasse', $byLabel['Kontoinhaber']);
|
||||
$this->assertSame('DE123', $byLabel['IBAN']);
|
||||
$this->assertSame('Camp - Beitrag', $byLabel['Verwendungszweck']);
|
||||
$this->assertArrayHasKey('Betrag', $byLabel);
|
||||
}
|
||||
|
||||
public function test_account_transfer_without_open_amount_has_no_payment_information(): void
|
||||
{
|
||||
$module = new AccountTransferPaymentModule();
|
||||
$summary = $module->registrationSummary(new RegistrationSummaryRequest(
|
||||
$this->participant(50.0, 50.0),
|
||||
['account_owner' => 'Kasse', 'iban' => 'DE123'],
|
||||
));
|
||||
|
||||
$this->assertFalse($summary->hasPaymentInformation);
|
||||
$this->assertFalse($summary->showGiroCode);
|
||||
}
|
||||
|
||||
public function test_cash_summary_returns_configured_html(): void
|
||||
{
|
||||
$module = new UndefinedPaymentModule();
|
||||
$summary = $module->registrationSummary(new RegistrationSummaryRequest(
|
||||
$this->participant(50.0, 0.0),
|
||||
['payment_information' => '<p>Bitte bar vor Ort zahlen.</p>'],
|
||||
));
|
||||
|
||||
$this->assertTrue($summary->hasPaymentInformation);
|
||||
$this->assertFalse($summary->showGiroCode);
|
||||
$this->assertSame('<p>Bitte bar vor Ort zahlen.</p>', $summary->html);
|
||||
$this->assertSame([], $summary->lines);
|
||||
}
|
||||
|
||||
public function test_cash_summary_empty_when_no_text_configured(): void
|
||||
{
|
||||
$module = new UndefinedPaymentModule();
|
||||
$summary = $module->registrationSummary(new RegistrationSummaryRequest(
|
||||
$this->participant(50.0, 0.0),
|
||||
[],
|
||||
));
|
||||
|
||||
$this->assertFalse($summary->hasPaymentInformation);
|
||||
}
|
||||
|
||||
public function test_cash_module_requires_payment_information_option(): void
|
||||
{
|
||||
$module = new UndefinedPaymentModule();
|
||||
|
||||
$this->assertSame(['payment_information'], $module->requiredOptionKeys());
|
||||
$this->assertFalse($module->isConfigurationComplete([]));
|
||||
$this->assertTrue($module->isConfigurationComplete(['payment_information' => '<p>Text</p>']));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user