Add test verifying that the correct list of payment gateways is returned per country

This commit is contained in:
Paul Dechov 2017-12-13 09:35:43 -05:00
parent b1b604b401
commit f4c557a9be
2 changed files with 70 additions and 1 deletions

View File

@ -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' ) ) {

View File

@ -0,0 +1,69 @@
<?php
/**
* Class Functions.
* @package WooCommerce\Tests\Setup
*/
class WC_Tests_Setup_Functions extends WC_Unit_Test_Case {
/**
* Test get_wizard_in_cart_payment_gateways.
* Verifies contents, order, and default enabled state of offered gateways.
*
* @since 3.3
*/
public function test_wizard_in_cart_payment_gateways() {
$setup_wizard = new WC_Admin_Setup_Wizard();
function get_enabled( $gateway ) {
return isset( $gateway['enabled'] ) && $gateway['enabled'];
}
function gateways( $setup_wizard ) {
return array_map( 'get_enabled', $setup_wizard->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,
) );
}
}