From 4d9bbb6f62a5568c766344d9283d7365bb5db8a5 Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Tue, 2 Jan 2024 16:41:41 +0100 Subject: [PATCH] merge split UPE tests into main gateway - II --- .../test-class-upe-payment-gateway.php | 49 -------------- .../test-class-upe-split-payment-gateway.php | 36 ----------- .../test-class-wc-payment-gateway-wcpay.php | 64 +++++++++++++++---- 3 files changed, 50 insertions(+), 99 deletions(-) diff --git a/tests/unit/payment-methods/test-class-upe-payment-gateway.php b/tests/unit/payment-methods/test-class-upe-payment-gateway.php index 7c013e2b858..5a4d879e5c3 100644 --- a/tests/unit/payment-methods/test-class-upe-payment-gateway.php +++ b/tests/unit/payment-methods/test-class-upe-payment-gateway.php @@ -354,55 +354,6 @@ public function tear_down() { wcpay_get_test_container()->reset_all_replacements(); } - public function test_process_payment_returns_correct_redirect_when_using_saved_payment() { - $order = WC_Helper_Order::create_order(); - $_POST = $this->setup_saved_payment_method(); - $intent = WC_Helper_Intention::create_intention(); - - $this->mock_gateway->expects( $this->once() ) - ->method( 'manage_customer_details_for_order' ) - ->will( - $this->returnValue( [ wp_get_current_user(), 'cus_123' ] ) - ); - $this->mock_wcpay_request( Create_And_Confirm_Intention::class, 1, $intent->get_id() ) - ->expects( $this->once() ) - ->method( 'format_response' ) - ->willReturn( $intent ); - - $this->set_cart_contains_subscription_items( false ); - - $result = $this->mock_gateway->process_payment( $order->get_id() ); - - $this->assertEquals( 'success', $result['result'] ); - $this->assertEquals( $this->return_url, $result['redirect'] ); - } - - public function test_process_payment_returns_correct_redirect_when_using_payment_request() { - $order = WC_Helper_Order::create_order(); - $intent = WC_Helper_Intention::create_intention(); - $_POST['payment_request_type'] = 'google_pay'; - - $this->mock_gateway->expects( $this->once() ) - ->method( 'manage_customer_details_for_order' ) - ->will( - $this->returnValue( [ wp_get_current_user(), 'cus_123' ] ) - ); - $this->mock_wcpay_request( Create_And_Confirm_Intention::class, 1, $intent->get_id() ) - ->expects( $this->once() ) - ->method( 'format_response' ) - ->willReturn( $intent ); - $this->set_cart_contains_subscription_items( false ); - - $result = $this->mock_gateway->process_payment( $order->get_id() ); - - $this->assertEquals( 'success', $result['result'] ); - $this->assertEquals( $this->return_url, $result['redirect'] ); - } - - public function is_proper_intent_used_with_order_returns_false() { - $this->assertFalse( $this->mock_gateway->is_proper_intent_used_with_order( WC_Helper_Order::create_order(), 'wrong_intent_id' ) ); - } - public function test_process_redirect_payment_intent_processing() { $order = WC_Helper_Order::create_order(); $order_id = $order->get_id(); diff --git a/tests/unit/payment-methods/test-class-upe-split-payment-gateway.php b/tests/unit/payment-methods/test-class-upe-split-payment-gateway.php index bb8bc7b5ef0..547f6b6e291 100644 --- a/tests/unit/payment-methods/test-class-upe-split-payment-gateway.php +++ b/tests/unit/payment-methods/test-class-upe-split-payment-gateway.php @@ -353,38 +353,6 @@ public function tear_down() { wcpay_get_test_container()->reset_all_replacements(); } - public function test_process_payment_returns_correct_redirect_when_using_saved_payment() { - $mock_card_payment_gateway = $this->mock_payment_gateways[ Payment_Method::CARD ]; - $user = wp_get_current_user(); - $customer_id = 'cus_mock'; - - $order = WC_Helper_Order::create_order(); - $_POST = $this->setup_saved_payment_method(); - $mock_card_payment_gateway->expects( $this->once() ) - ->method( 'manage_customer_details_for_order' ) - ->will( - $this->returnValue( [ $user, $customer_id ] ) - ); - $mock_card_payment_gateway->expects( $this->any() ) - ->method( 'get_upe_enabled_payment_method_ids' ) - ->will( - $this->returnValue( [ Payment_Method::CARD ] ) - ); - $this->mock_wcpay_request( Create_And_Confirm_Intention::class, 1 ) - ->expects( $this->once() ) - ->method( 'format_response' ) - ->willReturn( - WC_Helper_Intention::create_intention( [ 'status' => Intent_Status::PROCESSING ] ) - ); - - $this->set_cart_contains_subscription_items( false ); - - $result = $mock_card_payment_gateway->process_payment( $order->get_id() ); - - $this->assertEquals( 'success', $result['result'] ); - $this->assertEquals( $this->return_url, $result['redirect'] ); - } - public function test_upe_process_payment_check_session_order_redirect_to_previous_order() { $_POST['wc_payment_intent_id'] = 'pi_mock'; $mock_upe_gateway = $this->mock_payment_gateways[ Payment_Method::SEPA ]; @@ -531,10 +499,6 @@ public function test_process_redirect_payment_intent_succeded() { $this->assertEquals( Order_Status::PROCESSING, $result_order->get_status() ); } - public function is_proper_intent_used_with_order_returns_false() { - $this->assertFalse( $this->mock_upe_gateway->is_proper_intent_used_with_order( WC_Helper_Order::create_order(), 'wrong_intent_id' ) ); - } - public function test_process_redirect_setup_intent_succeded() { $order = WC_Helper_Order::create_order(); diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay.php b/tests/unit/test-class-wc-payment-gateway-wcpay.php index c527fe62cd3..a22f05aa1ae 100644 --- a/tests/unit/test-class-wc-payment-gateway-wcpay.php +++ b/tests/unit/test-class-wc-payment-gateway-wcpay.php @@ -49,7 +49,7 @@ /** * WC_Payment_Gateway_WCPay unit tests. */ -class Timur_Test extends WCPAY_UnitTestCase { +class WC_Payment_Gateway_WCPay_Test extends WCPAY_UnitTestCase { const NO_REQUIREMENTS = false; const PENDING_REQUIREMENTS = true; @@ -2377,6 +2377,55 @@ public function test_new_process_payment() { ); } + public function test_process_payment_returns_correct_redirect() { + $order = WC_Helper_Order::create_order(); + $_POST = [ 'wcpay-payment-method' => 'pm_mock' ]; + + $this->mock_wcpay_request( Create_And_Confirm_Intention::class, 1 ) + ->expects( $this->once() ) + ->method( 'format_response' ) + ->willReturn( + WC_Helper_Intention::create_intention( [ 'status' => Intent_Status::PROCESSING ] ) + ); + + $this->mock_token_service + ->expects( $this->once() ) + ->method( 'add_payment_method_to_user' ) + ->willReturn( new WC_Payment_Token_CC() ); + + $result = $this->card_gateway->process_payment( $order->get_id() ); + + $this->assertEquals( 'success', $result['result'] ); + $this->assertEquals( $order->get_checkout_order_received_url(), $result['redirect'] ); + } + + public function test_process_payment_returns_correct_redirect_when_using_payment_request() { + $order = WC_Helper_Order::create_order(); + $_POST['payment_request_type'] = 'google_pay'; + $_POST = [ 'wcpay-payment-method' => 'pm_mock' ]; + + $this->mock_wcpay_request( Create_And_Confirm_Intention::class, 1 ) + ->expects( $this->once() ) + ->method( 'format_response' ) + ->willReturn( + WC_Helper_Intention::create_intention( [ 'status' => Intent_Status::PROCESSING ] ) + ); + + $this->mock_token_service + ->expects( $this->once() ) + ->method( 'add_payment_method_to_user' ) + ->willReturn( new WC_Payment_Token_CC() ); + + $result = $this->card_gateway->process_payment( $order->get_id() ); + + $this->assertEquals( 'success', $result['result'] ); + $this->assertEquals( $order->get_checkout_order_received_url(), $result['redirect'] ); + } + + public function is_proper_intent_used_with_order_returns_false() { + $this->assertFalse( $this->card_gateway->is_proper_intent_used_with_order( WC_Helper_Order::create_order(), 'wrong_intent_id' ) ); + } + /** * Sets up the expectation for a certain factor for the new payment * process to be either set or unset. @@ -2496,17 +2545,4 @@ function( $gateway ) use ( $payment_method_id ) { ) ) )[0] ?? null; } - - /** - * Helper function to mock subscriptions for internal UPE payment methods. - */ - private function set_cart_contains_subscription_items( $cart_contains_subscriptions ) { - foreach ( $this->mock_payment_methods as $mock_payment_method ) { - $mock_payment_method->expects( $this->any() ) - ->method( 'is_subscription_item_in_cart' ) - ->will( - $this->returnValue( $cart_contains_subscriptions ) - ); - } - } }