Skip to content

Commit 2122fd9

Browse files
author
Timur Karimov
committed
cleanup settings controller tests
1 parent 3fa1a93 commit 2122fd9

File tree

1 file changed

+11
-159
lines changed

1 file changed

+11
-159
lines changed

tests/unit/admin/test-class-wc-rest-payments-settings-controller.php

Lines changed: 11 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use WCPay\Database_Cache;
1313
use WCPay\Duplicate_Payment_Prevention_Service;
1414
use WCPay\Payment_Methods\Eps_Payment_Method;
15-
use WCPay\Payment_Methods\UPE_Payment_Gateway;
1615
use WCPay\Payment_Methods\CC_Payment_Method;
1716
use WCPay\Payment_Methods\Bancontact_Payment_Method;
1817
use WCPay\Payment_Methods\Becs_Payment_Method;
@@ -65,34 +64,6 @@ class WC_REST_Payments_Settings_Controller_Test extends WCPAY_UnitTestCase {
6564
*/
6665
private $mock_db_cache;
6766

68-
/**
69-
* An array of mocked split UPE payment gateways mapped to payment method ID.
70-
*
71-
* @var UPE_Payment_Gateway
72-
*/
73-
private $mock_upe_payment_gateway;
74-
75-
/**
76-
* An array of mocked split UPE payment gateways mapped to payment method ID.
77-
*
78-
* @var UPE_Payment_Gateway
79-
*/
80-
private $mock_split_upe_payment_gateway;
81-
82-
/**
83-
* UPE system under test.
84-
*
85-
* @var WC_REST_Payments_Settings_Controller
86-
*/
87-
private $upe_controller;
88-
89-
/**
90-
* UPE system under test.
91-
*
92-
* @var WC_REST_Payments_Settings_Controller
93-
*/
94-
private $upe_split_controller;
95-
9667
/**
9768
* WC_Payments_Localization_Service instance.
9869
*
@@ -186,40 +157,6 @@ public function set_up() {
186157
);
187158
$this->controller = new WC_REST_Payments_Settings_Controller( $this->mock_api_client, $this->gateway, $this->mock_wcpay_account );
188159

189-
$this->mock_upe_payment_gateway = new WC_Payment_Gateway_WCPay(
190-
$this->mock_api_client,
191-
$this->mock_wcpay_account,
192-
$customer_service,
193-
$token_service,
194-
$action_scheduler_service,
195-
$mock_payment_method,
196-
$mock_payment_methods,
197-
$mock_rate_limiter,
198-
$order_service,
199-
$mock_dpps,
200-
$this->mock_localization_service,
201-
$this->mock_fraud_service
202-
);
203-
204-
$this->upe_controller = new WC_REST_Payments_Settings_Controller( $this->mock_api_client, $this->mock_upe_payment_gateway, $this->mock_wcpay_account );
205-
206-
$this->mock_split_upe_payment_gateway = new WC_Payment_Gateway_WCPay(
207-
$this->mock_api_client,
208-
$this->mock_wcpay_account,
209-
$customer_service,
210-
$token_service,
211-
$action_scheduler_service,
212-
$mock_payment_methods['card'],
213-
$mock_payment_methods,
214-
$mock_rate_limiter,
215-
$order_service,
216-
$mock_dpps,
217-
$this->mock_localization_service,
218-
$this->mock_fraud_service
219-
);
220-
221-
$this->upe_split_controller = new WC_REST_Payments_Settings_Controller( $this->mock_api_client, $this->mock_split_upe_payment_gateway, $this->mock_wcpay_account );
222-
223160
$this->mock_api_client
224161
->method( 'is_server_connected' )
225162
->willReturn( true );
@@ -269,7 +206,7 @@ public function test_get_settings_returns_enabled_payment_method_ids() {
269206
);
270207
}
271208

272-
public function test_upe_get_settings_returns_available_payment_method_ids() {
209+
public function test_get_settings_returns_available_payment_method_ids() {
273210
$this->mock_localization_service->method( 'get_country_locale_data' )->willReturn(
274211
[
275212
'currency_code' => 'usd',
@@ -295,32 +232,6 @@ public function test_upe_get_settings_returns_available_payment_method_ids() {
295232
);
296233
}
297234

298-
public function test_split_upe_get_settings_returns_available_payment_method_ids() {
299-
$this->mock_localization_service->method( 'get_country_locale_data' )->willReturn(
300-
[
301-
'currency_code' => 'usd',
302-
]
303-
);
304-
$response = $this->upe_split_controller->get_settings();
305-
$enabled_method_ids = $response->get_data()['available_payment_method_ids'];
306-
307-
$this->assertEquals(
308-
[
309-
Payment_Method::CARD,
310-
Payment_Method::BECS,
311-
Payment_Method::BANCONTACT,
312-
Payment_Method::EPS,
313-
Payment_Method::GIROPAY,
314-
Payment_Method::IDEAL,
315-
Payment_Method::SOFORT,
316-
Payment_Method::SEPA,
317-
Payment_Method::P24,
318-
Payment_Method::LINK,
319-
],
320-
$enabled_method_ids
321-
);
322-
}
323-
324235
public function test_get_settings_request_returns_test_mode_flag() {
325236
$this->mock_localization_service->method( 'get_country_locale_data' )->willReturn(
326237
[
@@ -438,26 +349,15 @@ public function test_update_settings_returns_error_on_non_bool_is_wcpay_enabled_
438349
$this->assertEquals( 400, $response->get_status() );
439350
}
440351

441-
public function test_upe_update_settings_saves_enabled_payment_methods() {
442-
$this->mock_upe_payment_gateway->update_option( 'upe_enabled_payment_method_ids', [ Payment_Method::CARD ] );
352+
public function test_update_settings_saves_enabled_payment_methods() {
353+
$this->gateway->update_option( 'upe_enabled_payment_method_ids', [ Payment_Method::CARD ] );
443354

444355
$request = new WP_REST_Request();
445356
$request->set_param( 'enabled_payment_method_ids', [ Payment_Method::CARD, Payment_Method::GIROPAY ] );
446357

447-
$this->upe_controller->update_settings( $request );
448-
449-
$this->assertEquals( [ Payment_Method::CARD, Payment_Method::GIROPAY ], $this->mock_upe_payment_gateway->get_option( 'upe_enabled_payment_method_ids' ) );
450-
}
451-
452-
public function test_upe_split_update_settings_saves_enabled_payment_methods() {
453-
$this->mock_split_upe_payment_gateway->update_option( 'upe_enabled_payment_method_ids', [ Payment_Method::CARD ] );
454-
455-
$request = new WP_REST_Request();
456-
$request->set_param( 'enabled_payment_method_ids', [ Payment_Method::CARD, Payment_Method::GIROPAY ] );
457-
458-
$this->upe_split_controller->update_settings( $request );
358+
$this->controller->update_settings( $request );
459359

460-
$this->assertEquals( [ Payment_Method::CARD, Payment_Method::GIROPAY ], $this->mock_split_upe_payment_gateway->get_option( 'upe_enabled_payment_method_ids' ) );
360+
$this->assertEquals( [ Payment_Method::CARD, Payment_Method::GIROPAY ], $this->gateway->get_option( 'upe_enabled_payment_method_ids' ) );
461361
}
462362

463363
public function test_update_settings_fails_if_user_cannot_manage_woocommerce() {
@@ -771,7 +671,7 @@ public function deregister_wc_blocks_rest_api() {
771671
}
772672
}
773673

774-
public function test_upe_get_settings_card_eligible_flag(): void {
674+
public function test_get_settings_card_eligible_flag(): void {
775675
// Enable Cash on Delivery gateway for the purpose of this test.
776676
$cod_gateway = WC()->payment_gateways()->payment_gateways()['cod'];
777677
$cod_gateway->enabled = 'yes';
@@ -782,26 +682,7 @@ public function test_upe_get_settings_card_eligible_flag(): void {
782682
]
783683
);
784684

785-
$response = $this->upe_controller->get_settings();
786-
787-
$this->assertArrayHasKey( 'is_card_present_eligible', $response->get_data() );
788-
$this->assertTrue( $response->get_data()['is_card_present_eligible'] );
789-
790-
// Disable Cash on Delivery gateway.
791-
$cod_gateway->enabled = 'no';
792-
}
793-
794-
public function test_upe_split_get_settings_card_eligible_flag(): void {
795-
// Enable Cash on Delivery gateway for the purpose of this test.
796-
$cod_gateway = WC()->payment_gateways()->payment_gateways()['cod'];
797-
$cod_gateway->enabled = 'yes';
798-
799-
$this->mock_localization_service->method( 'get_country_locale_data' )->willReturn(
800-
[
801-
'currency_code' => 'usd',
802-
]
803-
);
804-
$response = $this->upe_split_controller->get_settings();
685+
$response = $this->controller->get_settings();
805686

806687
$this->assertArrayHasKey( 'is_card_present_eligible', $response->get_data() );
807688
$this->assertTrue( $response->get_data()['is_card_present_eligible'] );
@@ -810,7 +691,7 @@ public function test_upe_split_get_settings_card_eligible_flag(): void {
810691
$cod_gateway->enabled = 'no';
811692
}
812693

813-
public function test_upe_get_settings_domestic_currency(): void {
694+
public function test_get_settings_domestic_currency(): void {
814695
$mock_domestic_currency = 'usd';
815696
$this->mock_localization_service->method( 'get_country_locale_data' )->willReturn(
816697
[
@@ -821,49 +702,20 @@ public function test_upe_get_settings_domestic_currency(): void {
821702
->expects( $this->never() )
822703
->method( 'get_account_default_currency' );
823704

824-
$response = $this->upe_controller->get_settings();
825-
826-
$this->assertArrayHasKey( 'account_domestic_currency', $response->get_data() );
827-
$this->assertSame( $mock_domestic_currency, $response->get_data()['account_domestic_currency'] );
828-
}
829-
830-
public function test_upe_get_settings_domestic_currency_fallbacks_to_default_currency(): void {
831-
$mock_domestic_currency = 'usd';
832-
$this->mock_localization_service->method( 'get_country_locale_data' )->willReturn( [] );
833-
$this->mock_wcpay_account
834-
->expects( $this->once() )
835-
->method( 'get_account_default_currency' )
836-
->willReturn( $mock_domestic_currency );
837-
$response = $this->upe_controller->get_settings();
838-
839-
$this->assertArrayHasKey( 'account_domestic_currency', $response->get_data() );
840-
$this->assertSame( $mock_domestic_currency, $response->get_data()['account_domestic_currency'] );
841-
}
842-
843-
public function test_upe_split_get_settings_domestic_currency(): void {
844-
$mock_domestic_currency = 'usd';
845-
$this->mock_localization_service->method( 'get_country_locale_data' )->willReturn(
846-
[
847-
'currency_code' => $mock_domestic_currency,
848-
]
849-
);
850-
$this->mock_wcpay_account
851-
->expects( $this->never() )
852-
->method( 'get_account_default_currency' );
853-
$response = $this->upe_split_controller->get_settings();
705+
$response = $this->controller->get_settings();
854706

855707
$this->assertArrayHasKey( 'account_domestic_currency', $response->get_data() );
856708
$this->assertSame( $mock_domestic_currency, $response->get_data()['account_domestic_currency'] );
857709
}
858710

859-
public function test_upe_split_get_settings_domestic_currency_fallbacks_to_default_currency(): void {
711+
public function test_get_settings_domestic_currency_fallbacks_to_default_currency(): void {
860712
$mock_domestic_currency = 'usd';
861713
$this->mock_localization_service->method( 'get_country_locale_data' )->willReturn( [] );
862714
$this->mock_wcpay_account
863715
->expects( $this->once() )
864716
->method( 'get_account_default_currency' )
865717
->willReturn( $mock_domestic_currency );
866-
$response = $this->upe_split_controller->get_settings();
718+
$response = $this->controller->get_settings();
867719

868720
$this->assertArrayHasKey( 'account_domestic_currency', $response->get_data() );
869721
$this->assertSame( $mock_domestic_currency, $response->get_data()['account_domestic_currency'] );

0 commit comments

Comments
 (0)