mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Add unit tests
This commit is contained in:
parent
43f4d15cea
commit
0e6f6bfc97
2 changed files with 96 additions and 1 deletions
|
@ -53,7 +53,7 @@ class DisabledFundingSources {
|
||||||
* @return array|int[]|mixed|string[]
|
* @return array|int[]|mixed|string[]
|
||||||
* @throws NotFoundException When the setting is not found.
|
* @throws NotFoundException When the setting is not found.
|
||||||
*/
|
*/
|
||||||
public function sources( $context ) {
|
public function sources( string $context ) {
|
||||||
$disable_funding = $this->settings->has( 'disable_funding' )
|
$disable_funding = $this->settings->has( 'disable_funding' )
|
||||||
? $this->settings->get( 'disable_funding' )
|
? $this->settings->get( 'disable_funding' )
|
||||||
: array();
|
: array();
|
||||||
|
|
95
tests/PHPUnit/Button/Helper/DisabledFundingSourcesTest.php
Normal file
95
tests/PHPUnit/Button/Helper/DisabledFundingSourcesTest.php
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\Button\Helper;
|
||||||
|
|
||||||
|
use Mockery;
|
||||||
|
use WC_Payment_Gateways;
|
||||||
|
use WooCommerce;
|
||||||
|
use WooCommerce\PayPalCommerce\TestCase;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||||
|
use function Brain\Monkey\Functions\when;
|
||||||
|
|
||||||
|
class DisabledFundingSourcesTest extends TestCase
|
||||||
|
{
|
||||||
|
private $settings;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->settings = Mockery::mock(Settings::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_is_checkout_true_does_not_add_card()
|
||||||
|
{
|
||||||
|
$sut = new DisabledFundingSources($this->settings, []);
|
||||||
|
|
||||||
|
$this->setExpectations();
|
||||||
|
$this->setWcPaymentGateways();
|
||||||
|
|
||||||
|
when('is_checkout')->justReturn(true);
|
||||||
|
|
||||||
|
$this->assertEquals([], $sut->sources(''));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_is_checkout_false_adds_card()
|
||||||
|
{
|
||||||
|
$sut = new DisabledFundingSources($this->settings, []);
|
||||||
|
|
||||||
|
$this->setExpectations();
|
||||||
|
$this->setWcPaymentGateways();
|
||||||
|
|
||||||
|
when('is_checkout')->justReturn(false);
|
||||||
|
|
||||||
|
$this->assertEquals(['card'], $sut->sources('checkout-block'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_checkout_block_context_adds_source()
|
||||||
|
{
|
||||||
|
$sut = new DisabledFundingSources($this->settings, [
|
||||||
|
'card' => 'Credit or debit cards',
|
||||||
|
'paypal' => 'PayPal',
|
||||||
|
'foo' => 'Bar',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->setExpectations();
|
||||||
|
$this->setWcPaymentGateways();
|
||||||
|
|
||||||
|
when('is_checkout')->justReturn(true);
|
||||||
|
|
||||||
|
$this->assertEquals(['foo'], $sut->sources('checkout-block'));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setExpectations(
|
||||||
|
array $disabledFundings = [],
|
||||||
|
bool $dccEnambled = true
|
||||||
|
): void
|
||||||
|
{
|
||||||
|
$this->settings->shouldReceive('has')
|
||||||
|
->with('disable_funding')
|
||||||
|
->andReturn(true);
|
||||||
|
|
||||||
|
$this->settings->shouldReceive('get')
|
||||||
|
->with('disable_funding')
|
||||||
|
->andReturn($disabledFundings);
|
||||||
|
|
||||||
|
$this->settings->shouldReceive('has')
|
||||||
|
->with('dcc_enabled')
|
||||||
|
->andReturn(true);
|
||||||
|
|
||||||
|
$this->settings->shouldReceive('get')
|
||||||
|
->with('dcc_enabled')
|
||||||
|
->andReturn($dccEnambled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setWcPaymentGateways(array $paymentGateways = []): void
|
||||||
|
{
|
||||||
|
$woocommerce = Mockery::mock(WooCommerce::class);
|
||||||
|
$payment_gateways = Mockery::mock(WC_Payment_Gateways::class);
|
||||||
|
when('WC')->justReturn($woocommerce);
|
||||||
|
$woocommerce->payment_gateways = $payment_gateways;
|
||||||
|
$payment_gateways->shouldReceive('get_available_payment_gateways')
|
||||||
|
->andReturn($paymentGateways);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue