mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 09:08:09 +08:00
update tests
This commit is contained in:
parent
90a0e28f63
commit
55c3de4f24
2 changed files with 103 additions and 13 deletions
|
@ -6,8 +6,11 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Processor;
|
|||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint;
|
||||
use Woocommerce\PayPalCommerce\ApiClient\Entity\Capture;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payments;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Repository\CartRepository;
|
||||
use WooCommerce\PayPalCommerce\Button\Helper\ThreeDSecure;
|
||||
|
@ -15,14 +18,32 @@ use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
|||
use WooCommerce\PayPalCommerce\TestCase;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\WooCommerce\Logging\WooCommerceLoggingModule;
|
||||
use Mockery;
|
||||
|
||||
class OrderProcessorTest extends TestCase
|
||||
{
|
||||
|
||||
public function testAuthorize() {
|
||||
$transactionId = 'ABC123';
|
||||
|
||||
$capture = Mockery::mock(Capture::class);
|
||||
$capture->expects('id')
|
||||
->andReturn($transactionId);
|
||||
|
||||
$payments = Mockery::mock(Payments::class);
|
||||
$payments->expects('captures')
|
||||
->andReturn([$capture]);
|
||||
|
||||
$purchaseUnit = Mockery::mock(PurchaseUnit::class);
|
||||
$purchaseUnit->expects('payments')
|
||||
->andReturn($payments);
|
||||
|
||||
$wcOrder = Mockery::mock(\WC_Order::class);
|
||||
$wcOrder->expects('update_meta_data')
|
||||
->with(PayPalGateway::ORDER_PAYMENT_MODE_META_KEY, 'live');
|
||||
$wcOrder->expects('set_transaction_id')
|
||||
->with($transactionId);
|
||||
|
||||
$orderStatus = Mockery::mock(OrderStatus::class);
|
||||
$orderStatus
|
||||
->expects('is')
|
||||
|
@ -32,8 +53,10 @@ class OrderProcessorTest extends TestCase
|
|||
->expects('is')
|
||||
->with(OrderStatus::COMPLETED)
|
||||
->andReturn(true);
|
||||
|
||||
$orderId = 'abc';
|
||||
$orderIntent = 'AUTHORIZE';
|
||||
|
||||
$currentOrder = Mockery::mock(Order::class);
|
||||
$currentOrder
|
||||
->expects('id')
|
||||
|
@ -44,13 +67,18 @@ class OrderProcessorTest extends TestCase
|
|||
$currentOrder
|
||||
->shouldReceive('status')
|
||||
->andReturn($orderStatus);
|
||||
$currentOrder->expects('purchase_units')
|
||||
->andReturn([$purchaseUnit]);
|
||||
|
||||
$sessionHandler = Mockery::mock(SessionHandler::class);
|
||||
$sessionHandler
|
||||
->expects('order')
|
||||
->andReturn($currentOrder);
|
||||
$sessionHandler
|
||||
->expects('destroy_session_data');
|
||||
|
||||
$cartRepository = Mockery::mock(CartRepository::class);
|
||||
|
||||
$orderEndpoint = Mockery::mock(OrderEndpoint::class);
|
||||
$orderEndpoint
|
||||
->expects('patch_order_with')
|
||||
|
@ -60,14 +88,19 @@ class OrderProcessorTest extends TestCase
|
|||
->expects('authorize')
|
||||
->with($currentOrder)
|
||||
->andReturn($currentOrder);
|
||||
|
||||
$paymentsEndpoint = Mockery::mock(PaymentsEndpoint::class);
|
||||
|
||||
$orderFactory = Mockery::mock(OrderFactory::class);
|
||||
$orderFactory
|
||||
->expects('from_wc_order')
|
||||
->with($wcOrder, $currentOrder)
|
||||
->andReturn($currentOrder);
|
||||
|
||||
$threeDSecure = Mockery::mock(ThreeDSecure::class);
|
||||
|
||||
$authorizedPaymentProcessor = Mockery::mock(AuthorizedPaymentsProcessor::class);
|
||||
|
||||
$settings = Mockery::mock(Settings::class);
|
||||
$settings
|
||||
->shouldReceive('has')
|
||||
|
@ -81,7 +114,8 @@ class OrderProcessorTest extends TestCase
|
|||
$orderFactory,
|
||||
$threeDSecure,
|
||||
$authorizedPaymentProcessor,
|
||||
$settings
|
||||
$settings,
|
||||
false
|
||||
);
|
||||
|
||||
$cart = Mockery::mock(\WC_Cart::class);
|
||||
|
@ -115,6 +149,20 @@ class OrderProcessorTest extends TestCase
|
|||
}
|
||||
|
||||
public function testCapture() {
|
||||
$transactionId = 'ABC123';
|
||||
|
||||
$capture = Mockery::mock(Capture::class);
|
||||
$capture->expects('id')
|
||||
->andReturn($transactionId);
|
||||
|
||||
$payments = Mockery::mock(Payments::class);
|
||||
$payments->expects('captures')
|
||||
->andReturn([$capture]);
|
||||
|
||||
$purchaseUnit = Mockery::mock(PurchaseUnit::class);
|
||||
$purchaseUnit->expects('payments')
|
||||
->andReturn($payments);
|
||||
|
||||
$wcOrder = Mockery::mock(\WC_Order::class);
|
||||
$orderStatus = Mockery::mock(OrderStatus::class);
|
||||
$orderStatus
|
||||
|
@ -137,6 +185,9 @@ class OrderProcessorTest extends TestCase
|
|||
$currentOrder
|
||||
->shouldReceive('status')
|
||||
->andReturn($orderStatus);
|
||||
$currentOrder
|
||||
->expects('purchase_units')
|
||||
->andReturn([$purchaseUnit]);
|
||||
$sessionHandler = Mockery::mock(SessionHandler::class);
|
||||
$sessionHandler
|
||||
->expects('order')
|
||||
|
@ -174,7 +225,8 @@ class OrderProcessorTest extends TestCase
|
|||
$orderFactory,
|
||||
$threeDSecure,
|
||||
$authorizedPaymentProcessor,
|
||||
$settings
|
||||
$settings,
|
||||
false
|
||||
);
|
||||
|
||||
$cart = Mockery::mock(\WC_Cart::class);
|
||||
|
@ -198,6 +250,10 @@ class OrderProcessorTest extends TestCase
|
|||
$wcOrder
|
||||
->expects('update_status')
|
||||
->with('on-hold', 'Awaiting payment.');
|
||||
$wcOrder->expects('update_meta_data')
|
||||
->with(PayPalGateway::ORDER_PAYMENT_MODE_META_KEY, 'live');
|
||||
$wcOrder->expects('set_transaction_id')
|
||||
->with($transactionId);
|
||||
$wcOrder
|
||||
->expects('update_status')
|
||||
->with('processing', 'Payment received.');
|
||||
|
@ -205,7 +261,26 @@ class OrderProcessorTest extends TestCase
|
|||
}
|
||||
|
||||
public function testError() {
|
||||
$transactionId = 'ABC123';
|
||||
|
||||
$capture = Mockery::mock(Capture::class);
|
||||
$capture->shouldReceive('id')
|
||||
->andReturn($transactionId);
|
||||
|
||||
$payments = Mockery::mock(Payments::class);
|
||||
$payments->shouldReceive('captures')
|
||||
->andReturn([$capture]);
|
||||
|
||||
$purchaseUnit = Mockery::mock(PurchaseUnit::class);
|
||||
$purchaseUnit->shouldReceive('payments')
|
||||
->andReturn($payments);
|
||||
|
||||
$wcOrder = Mockery::mock(\WC_Order::class);
|
||||
$wcOrder->expects('update_meta_data')
|
||||
->with(PayPalGateway::ORDER_PAYMENT_MODE_META_KEY, 'live');
|
||||
$wcOrder->shouldReceive('set_transaction_id')
|
||||
->with($transactionId);
|
||||
|
||||
$orderStatus = Mockery::mock(OrderStatus::class);
|
||||
$orderStatus
|
||||
->expects('is')
|
||||
|
@ -226,6 +301,9 @@ class OrderProcessorTest extends TestCase
|
|||
$currentOrder
|
||||
->shouldReceive('payment_source')
|
||||
->andReturnNull();
|
||||
$currentOrder
|
||||
->shouldReceive('purchase_units')
|
||||
->andReturn([$purchaseUnit]);
|
||||
$sessionHandler = Mockery::mock(SessionHandler::class);
|
||||
$sessionHandler
|
||||
->expects('order')
|
||||
|
@ -246,7 +324,8 @@ class OrderProcessorTest extends TestCase
|
|||
$orderFactory,
|
||||
$threeDSecure,
|
||||
$authorizedPaymentProcessor,
|
||||
$settings
|
||||
$settings,
|
||||
false
|
||||
);
|
||||
|
||||
$cart = Mockery::mock(\WC_Cart::class);
|
||||
|
@ -270,4 +349,4 @@ class OrderProcessorTest extends TestCase
|
|||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue