Configurations for payment modules
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\PaymentMethod;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class PaymentMethodOptionsTest extends TestCase
|
||||
{
|
||||
public function test_options_for_returns_schema_for_known_slug(): void
|
||||
{
|
||||
$options = PaymentMethod::optionsFor(PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION);
|
||||
|
||||
$this->assertNotEmpty($options);
|
||||
$this->assertSame('account_owner', $options[0]['name']);
|
||||
}
|
||||
|
||||
public function test_options_for_returns_empty_for_unknown_slug(): void
|
||||
{
|
||||
$this->assertSame([], PaymentMethod::optionsFor('DOES_NOT_EXIST'));
|
||||
}
|
||||
|
||||
public function test_required_option_keys_only_returns_required(): void
|
||||
{
|
||||
$keys = PaymentMethod::requiredOptionKeys(PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION);
|
||||
|
||||
$this->assertContains('account_owner', $keys);
|
||||
$this->assertContains('iban', $keys);
|
||||
$this->assertNotContains('bic', $keys); // bic ist optional
|
||||
}
|
||||
|
||||
public function test_sanitize_configuration_drops_unknown_keys(): void
|
||||
{
|
||||
$sanitized = PaymentMethod::sanitizeConfiguration(PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION, [
|
||||
'iban' => 'DE123',
|
||||
'account_owner' => 'Kasse',
|
||||
'evil' => 'x',
|
||||
]);
|
||||
|
||||
$this->assertArrayHasKey('iban', $sanitized);
|
||||
$this->assertArrayHasKey('account_owner', $sanitized);
|
||||
$this->assertArrayNotHasKey('evil', $sanitized);
|
||||
}
|
||||
|
||||
public function test_is_configuration_complete_requires_all_required_options(): void
|
||||
{
|
||||
$slug = PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION;
|
||||
|
||||
$this->assertFalse(PaymentMethod::isConfigurationComplete($slug, []));
|
||||
$this->assertFalse(PaymentMethod::isConfigurationComplete($slug, ['iban' => 'DE123']));
|
||||
$this->assertFalse(PaymentMethod::isConfigurationComplete($slug, ['iban' => 'DE123', 'account_owner' => '']));
|
||||
$this->assertTrue(PaymentMethod::isConfigurationComplete($slug, ['iban' => 'DE123', 'account_owner' => 'Kasse']));
|
||||
}
|
||||
|
||||
public function test_slug_without_options_is_always_complete(): void
|
||||
{
|
||||
$this->assertTrue(PaymentMethod::isConfigurationComplete(PaymentMethod::PAYMENT_NOT_DEFINED, []));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user