From f4c557a9be6a462acfa6eba96baee821844083a8 Mon Sep 17 00:00:00 2001 From: Paul Dechov Date: Wed, 13 Dec 2017 09:35:43 -0500 Subject: [PATCH] Add test verifying that the correct list of payment gateways is returned per country --- .../admin/class-wc-admin-setup-wizard.php | 2 +- tests/unit-tests/setup/functions.php | 69 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tests/unit-tests/setup/functions.php diff --git a/includes/admin/class-wc-admin-setup-wizard.php b/includes/admin/class-wc-admin-setup-wizard.php index 12dd83436a9..665c3a77b91 100644 --- a/includes/admin/class-wc-admin-setup-wizard.php +++ b/includes/admin/class-wc-admin-setup-wizard.php @@ -1199,7 +1199,7 @@ class WC_Admin_Setup_Wizard { * * @return array */ - protected function get_wizard_in_cart_payment_gateways() { + public function get_wizard_in_cart_payment_gateways() { $gateways = $this->get_wizard_available_in_cart_payment_gateways(); if ( ! current_user_can( 'install_plugins' ) ) { diff --git a/tests/unit-tests/setup/functions.php b/tests/unit-tests/setup/functions.php new file mode 100644 index 00000000000..9612ab8cced --- /dev/null +++ b/tests/unit-tests/setup/functions.php @@ -0,0 +1,69 @@ +get_wizard_in_cart_payment_gateways() ); + } + + // non-admin user + $this->user_id = $this->factory->user->create( array( 'role' => 'shop_manager' ) ); + wp_set_current_user( $this->user_id ); + $this->assertEquals( gateways( $setup_wizard ), array( + 'paypal' => false, + ) ); + + // set admin user + $this->user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); + wp_set_current_user( $this->user_id ); + + update_option( 'woocommerce_default_country', 'US' ); + $this->assertEquals( gateways( $setup_wizard ), array( + 'stripe' => true, + 'ppec_paypal' => true, + ) ); + + update_option( 'woocommerce_default_country', 'CN' ); + $this->assertEquals( gateways( $setup_wizard ), array( + 'ppec_paypal' => true, + ) ); + + update_option( 'woocommerce_default_country', 'SE' ); + $this->assertEquals( gateways( $setup_wizard ), array( + 'klarna_checkout' => true, + 'ppec_paypal' => true, + 'stripe' => false, + ) ); + + update_option( 'woocommerce_default_country', 'DE' ); + $this->assertEquals( gateways( $setup_wizard ), array( + 'klarna_payments' => true, + 'ppec_paypal' => true, + 'stripe' => false, + ) ); + + update_option( 'woocommerce_default_country', 'GB' ); + update_option( 'woocommerce_sell_in_person', 'yes' ); + $this->assertEquals( gateways( $setup_wizard ), array( + 'square' => true, + 'ppec_paypal' => true, + 'stripe' => false, + ) ); + } +}