Skip to content

Commit 4d9bbb6

Browse files
author
Timur Karimov
committed
merge split UPE tests into main gateway - II
1 parent 374b219 commit 4d9bbb6

File tree

3 files changed

+50
-99
lines changed

3 files changed

+50
-99
lines changed

tests/unit/payment-methods/test-class-upe-payment-gateway.php

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -354,55 +354,6 @@ public function tear_down() {
354354
wcpay_get_test_container()->reset_all_replacements();
355355
}
356356

357-
public function test_process_payment_returns_correct_redirect_when_using_saved_payment() {
358-
$order = WC_Helper_Order::create_order();
359-
$_POST = $this->setup_saved_payment_method();
360-
$intent = WC_Helper_Intention::create_intention();
361-
362-
$this->mock_gateway->expects( $this->once() )
363-
->method( 'manage_customer_details_for_order' )
364-
->will(
365-
$this->returnValue( [ wp_get_current_user(), 'cus_123' ] )
366-
);
367-
$this->mock_wcpay_request( Create_And_Confirm_Intention::class, 1, $intent->get_id() )
368-
->expects( $this->once() )
369-
->method( 'format_response' )
370-
->willReturn( $intent );
371-
372-
$this->set_cart_contains_subscription_items( false );
373-
374-
$result = $this->mock_gateway->process_payment( $order->get_id() );
375-
376-
$this->assertEquals( 'success', $result['result'] );
377-
$this->assertEquals( $this->return_url, $result['redirect'] );
378-
}
379-
380-
public function test_process_payment_returns_correct_redirect_when_using_payment_request() {
381-
$order = WC_Helper_Order::create_order();
382-
$intent = WC_Helper_Intention::create_intention();
383-
$_POST['payment_request_type'] = 'google_pay';
384-
385-
$this->mock_gateway->expects( $this->once() )
386-
->method( 'manage_customer_details_for_order' )
387-
->will(
388-
$this->returnValue( [ wp_get_current_user(), 'cus_123' ] )
389-
);
390-
$this->mock_wcpay_request( Create_And_Confirm_Intention::class, 1, $intent->get_id() )
391-
->expects( $this->once() )
392-
->method( 'format_response' )
393-
->willReturn( $intent );
394-
$this->set_cart_contains_subscription_items( false );
395-
396-
$result = $this->mock_gateway->process_payment( $order->get_id() );
397-
398-
$this->assertEquals( 'success', $result['result'] );
399-
$this->assertEquals( $this->return_url, $result['redirect'] );
400-
}
401-
402-
public function is_proper_intent_used_with_order_returns_false() {
403-
$this->assertFalse( $this->mock_gateway->is_proper_intent_used_with_order( WC_Helper_Order::create_order(), 'wrong_intent_id' ) );
404-
}
405-
406357
public function test_process_redirect_payment_intent_processing() {
407358
$order = WC_Helper_Order::create_order();
408359
$order_id = $order->get_id();

tests/unit/payment-methods/test-class-upe-split-payment-gateway.php

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -353,38 +353,6 @@ public function tear_down() {
353353
wcpay_get_test_container()->reset_all_replacements();
354354
}
355355

356-
public function test_process_payment_returns_correct_redirect_when_using_saved_payment() {
357-
$mock_card_payment_gateway = $this->mock_payment_gateways[ Payment_Method::CARD ];
358-
$user = wp_get_current_user();
359-
$customer_id = 'cus_mock';
360-
361-
$order = WC_Helper_Order::create_order();
362-
$_POST = $this->setup_saved_payment_method();
363-
$mock_card_payment_gateway->expects( $this->once() )
364-
->method( 'manage_customer_details_for_order' )
365-
->will(
366-
$this->returnValue( [ $user, $customer_id ] )
367-
);
368-
$mock_card_payment_gateway->expects( $this->any() )
369-
->method( 'get_upe_enabled_payment_method_ids' )
370-
->will(
371-
$this->returnValue( [ Payment_Method::CARD ] )
372-
);
373-
$this->mock_wcpay_request( Create_And_Confirm_Intention::class, 1 )
374-
->expects( $this->once() )
375-
->method( 'format_response' )
376-
->willReturn(
377-
WC_Helper_Intention::create_intention( [ 'status' => Intent_Status::PROCESSING ] )
378-
);
379-
380-
$this->set_cart_contains_subscription_items( false );
381-
382-
$result = $mock_card_payment_gateway->process_payment( $order->get_id() );
383-
384-
$this->assertEquals( 'success', $result['result'] );
385-
$this->assertEquals( $this->return_url, $result['redirect'] );
386-
}
387-
388356
public function test_upe_process_payment_check_session_order_redirect_to_previous_order() {
389357
$_POST['wc_payment_intent_id'] = 'pi_mock';
390358
$mock_upe_gateway = $this->mock_payment_gateways[ Payment_Method::SEPA ];
@@ -531,10 +499,6 @@ public function test_process_redirect_payment_intent_succeded() {
531499
$this->assertEquals( Order_Status::PROCESSING, $result_order->get_status() );
532500
}
533501

534-
public function is_proper_intent_used_with_order_returns_false() {
535-
$this->assertFalse( $this->mock_upe_gateway->is_proper_intent_used_with_order( WC_Helper_Order::create_order(), 'wrong_intent_id' ) );
536-
}
537-
538502
public function test_process_redirect_setup_intent_succeded() {
539503

540504
$order = WC_Helper_Order::create_order();

tests/unit/test-class-wc-payment-gateway-wcpay.php

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
/**
5050
* WC_Payment_Gateway_WCPay unit tests.
5151
*/
52-
class Timur_Test extends WCPAY_UnitTestCase {
52+
class WC_Payment_Gateway_WCPay_Test extends WCPAY_UnitTestCase {
5353

5454
const NO_REQUIREMENTS = false;
5555
const PENDING_REQUIREMENTS = true;
@@ -2377,6 +2377,55 @@ public function test_new_process_payment() {
23772377
);
23782378
}
23792379

2380+
public function test_process_payment_returns_correct_redirect() {
2381+
$order = WC_Helper_Order::create_order();
2382+
$_POST = [ 'wcpay-payment-method' => 'pm_mock' ];
2383+
2384+
$this->mock_wcpay_request( Create_And_Confirm_Intention::class, 1 )
2385+
->expects( $this->once() )
2386+
->method( 'format_response' )
2387+
->willReturn(
2388+
WC_Helper_Intention::create_intention( [ 'status' => Intent_Status::PROCESSING ] )
2389+
);
2390+
2391+
$this->mock_token_service
2392+
->expects( $this->once() )
2393+
->method( 'add_payment_method_to_user' )
2394+
->willReturn( new WC_Payment_Token_CC() );
2395+
2396+
$result = $this->card_gateway->process_payment( $order->get_id() );
2397+
2398+
$this->assertEquals( 'success', $result['result'] );
2399+
$this->assertEquals( $order->get_checkout_order_received_url(), $result['redirect'] );
2400+
}
2401+
2402+
public function test_process_payment_returns_correct_redirect_when_using_payment_request() {
2403+
$order = WC_Helper_Order::create_order();
2404+
$_POST['payment_request_type'] = 'google_pay';
2405+
$_POST = [ 'wcpay-payment-method' => 'pm_mock' ];
2406+
2407+
$this->mock_wcpay_request( Create_And_Confirm_Intention::class, 1 )
2408+
->expects( $this->once() )
2409+
->method( 'format_response' )
2410+
->willReturn(
2411+
WC_Helper_Intention::create_intention( [ 'status' => Intent_Status::PROCESSING ] )
2412+
);
2413+
2414+
$this->mock_token_service
2415+
->expects( $this->once() )
2416+
->method( 'add_payment_method_to_user' )
2417+
->willReturn( new WC_Payment_Token_CC() );
2418+
2419+
$result = $this->card_gateway->process_payment( $order->get_id() );
2420+
2421+
$this->assertEquals( 'success', $result['result'] );
2422+
$this->assertEquals( $order->get_checkout_order_received_url(), $result['redirect'] );
2423+
}
2424+
2425+
public function is_proper_intent_used_with_order_returns_false() {
2426+
$this->assertFalse( $this->card_gateway->is_proper_intent_used_with_order( WC_Helper_Order::create_order(), 'wrong_intent_id' ) );
2427+
}
2428+
23802429
/**
23812430
* Sets up the expectation for a certain factor for the new payment
23822431
* process to be either set or unset.
@@ -2496,17 +2545,4 @@ function( $gateway ) use ( $payment_method_id ) {
24962545
)
24972546
) )[0] ?? null;
24982547
}
2499-
2500-
/**
2501-
* Helper function to mock subscriptions for internal UPE payment methods.
2502-
*/
2503-
private function set_cart_contains_subscription_items( $cart_contains_subscriptions ) {
2504-
foreach ( $this->mock_payment_methods as $mock_payment_method ) {
2505-
$mock_payment_method->expects( $this->any() )
2506-
->method( 'is_subscription_item_in_cart' )
2507-
->will(
2508-
$this->returnValue( $cart_contains_subscriptions )
2509-
);
2510-
}
2511-
}
25122548
}

0 commit comments

Comments
 (0)