🧪 Fix the DisabledFundingSourcesTest test

This commit is contained in:
Daniel Dudzic 2025-05-23 19:11:20 +02:00
parent 602efee944
commit 0de1d21a76
No known key found for this signature in database
GPG key ID: 31B40D33E3465483

View file

@ -32,7 +32,7 @@ class DisabledFundingSourcesTest extends TestCase
{
$this->dcc_configuration->shouldReceive('is_enabled')->andReturn(true);
$this->dcc_configuration->shouldReceive('use_acdc')->andReturn(true);
$sut = new DisabledFundingSources($this->settings, [], $this->dcc_configuration);
$sut = new DisabledFundingSources($this->settings, [], $this->dcc_configuration, 'US');
$this->setExpectations();
$this->setWcPaymentGateways();
@ -50,7 +50,7 @@ class DisabledFundingSourcesTest extends TestCase
{
$this->dcc_configuration->shouldReceive('is_enabled')->andReturn(true);
$this->dcc_configuration->shouldReceive('use_acdc')->andReturn(true);
$sut = new DisabledFundingSources($this->settings, [], $this->dcc_configuration);
$sut = new DisabledFundingSources($this->settings, [], $this->dcc_configuration, 'US');
$this->setExpectations();
$this->setWcPaymentGateways();
@ -71,7 +71,8 @@ class DisabledFundingSourcesTest extends TestCase
'paypal' => 'PayPal',
'foo' => 'Bar',
],
$this->dcc_configuration
$this->dcc_configuration,
'US'
);
$this->setExpectations();
@ -82,6 +83,66 @@ class DisabledFundingSourcesTest extends TestCase
$this->assertEquals(['card', 'foo'], $sut->sources('checkout-block'));
}
/**
* Test Mexico-specific logic: BCDC enabled should not disable card funding
*/
public function test_mexico_bcdc_enabled_does_not_disable_card_funding()
{
$this->dcc_configuration->shouldReceive('is_enabled')->andReturn(true);
$this->dcc_configuration->shouldReceive('use_acdc')->andReturn(true);
$this->dcc_configuration->shouldReceive('is_bcdc_enabled')->andReturn(true);
$sut = new DisabledFundingSources($this->settings, [], $this->dcc_configuration, 'MX');
$this->setExpectations();
$this->setWcPaymentGateways();
when('is_checkout')->justReturn(true);
// For Mexico with BCDC enabled, card should not be in disabled funding sources
$this->assertEquals([], $sut->sources('checkout-block'));
}
/**
* Test Mexico-specific logic: BCDC disabled should disable card funding
*/
public function test_mexico_bcdc_disabled_disables_card_funding()
{
$this->dcc_configuration->shouldReceive('is_enabled')->andReturn(true);
$this->dcc_configuration->shouldReceive('use_acdc')->andReturn(true);
$this->dcc_configuration->shouldReceive('is_bcdc_enabled')->andReturn(false);
$sut = new DisabledFundingSources($this->settings, [], $this->dcc_configuration, 'MX');
$this->setExpectations();
$this->setWcPaymentGateways();
when('is_checkout')->justReturn(true);
// For Mexico with BCDC disabled, card should be in disabled funding sources
$this->assertEquals(['card'], $sut->sources('checkout-block'));
}
/**
* Test non-Mexico country behavior remains unchanged
*/
public function test_non_mexico_country_behavior_unchanged()
{
$this->dcc_configuration->shouldReceive('is_enabled')->andReturn(true);
$this->dcc_configuration->shouldReceive('use_acdc')->andReturn(true);
// BCDC method should not be called for non-Mexico countries
$sut = new DisabledFundingSources($this->settings, [], $this->dcc_configuration, 'CA');
$this->setExpectations();
$this->setWcPaymentGateways();
when('is_checkout')->justReturn(true);
// For non-Mexico countries, existing logic applies
$this->assertEquals(['card'], $sut->sources('checkout-block'));
}
private function setExpectations(
array $disabledFundings = [],
bool $dccEnambled = true