60 lines
2.2 KiB
PHP
60 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use App\EventPaymentModules\EventPaymentModuleRegistry;
|
|
use App\EventPaymentModules\Modules\AccountTransferPaymentModule;
|
|
use App\EventPaymentModules\Modules\UndefinedPaymentModule;
|
|
use App\Models\PaymentMethod;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class EventPaymentModuleRegistryTest extends TestCase
|
|
{
|
|
public function test_for_slug_resolves_known_modules(): void
|
|
{
|
|
$this->assertInstanceOf(
|
|
AccountTransferPaymentModule::class,
|
|
EventPaymentModuleRegistry::forSlug(PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION)
|
|
);
|
|
$this->assertInstanceOf(
|
|
UndefinedPaymentModule::class,
|
|
EventPaymentModuleRegistry::forSlug(PaymentMethod::PAYMENT_NOT_DEFINED)
|
|
);
|
|
}
|
|
|
|
public function test_for_slug_returns_null_for_unknown(): void
|
|
{
|
|
$this->assertNull(EventPaymentModuleRegistry::forSlug('DOES_NOT_EXIST'));
|
|
}
|
|
|
|
public function test_slugs_lists_all_registered_modules(): void
|
|
{
|
|
$slugs = EventPaymentModuleRegistry::slugs();
|
|
|
|
$this->assertContains(PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION, $slugs);
|
|
$this->assertContains(PaymentMethod::PAYMENT_NOT_DEFINED, $slugs);
|
|
}
|
|
|
|
public function test_module_option_helpers(): void
|
|
{
|
|
$module = new AccountTransferPaymentModule();
|
|
|
|
$this->assertSame(['account_owner', 'iban'], $module->requiredOptionKeys());
|
|
// Rückgabe folgt der Schema-Reihenfolge, unbekannte Keys werden verworfen.
|
|
$this->assertSame(
|
|
['account_owner' => 'Kasse', 'iban' => 'DE123'],
|
|
$module->sanitizeConfiguration(['iban' => 'DE123', 'account_owner' => 'Kasse', 'evil' => 'x'])
|
|
);
|
|
$this->assertFalse($module->isConfigurationComplete(['iban' => 'DE123']));
|
|
$this->assertTrue($module->isConfigurationComplete(['iban' => 'DE123', 'account_owner' => 'Kasse']));
|
|
}
|
|
|
|
public function test_defaults_are_built_from_modules(): void
|
|
{
|
|
$defaults = PaymentMethod::defaults();
|
|
|
|
$this->assertSame('Überweisung auf Veranstaltungskonto', $defaults[PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION]['name']);
|
|
$this->assertArrayHasKey(PaymentMethod::PAYMENT_NOT_DEFINED, $defaults);
|
|
}
|
|
}
|