2017-12-13 14:35:43 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2019-05-14 21:34:21 +00:00
|
|
|
* Class WC_Tests_Setup_Functions.
|
2017-12-13 14:35:43 +00:00
|
|
|
* @package WooCommerce\Tests\Setup
|
|
|
|
*/
|
2019-05-14 21:34:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class WC_Tests_Setup_Functions.
|
|
|
|
*/
|
2017-12-13 14:35:43 +00:00
|
|
|
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();
|
|
|
|
|
2019-05-14 21:34:21 +00:00
|
|
|
/**
|
|
|
|
* Return wheter a given gateway is enable or not.
|
|
|
|
*
|
|
|
|
* @param array $gateway Gateway information.
|
|
|
|
* @return bool
|
|
|
|
*/
|
2017-12-13 14:35:43 +00:00
|
|
|
function get_enabled( $gateway ) {
|
|
|
|
return isset( $gateway['enabled'] ) && $gateway['enabled'];
|
|
|
|
}
|
2019-05-14 21:34:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to call the tested method and return a simplified version
|
|
|
|
* of the returned values. It returns only if the gateways are enable or not
|
|
|
|
* which is what we are currently checking in the tests.
|
|
|
|
*
|
|
|
|
* @param WC_Admin_Setup_Wizard $setup_wizard Setup wizard object.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2017-12-13 14:35:43 +00:00
|
|
|
function gateways( $setup_wizard ) {
|
|
|
|
return array_map( 'get_enabled', $setup_wizard->get_wizard_in_cart_payment_gateways() );
|
|
|
|
}
|
|
|
|
|
2019-05-14 21:34:21 +00:00
|
|
|
// non-admin user.
|
2017-12-13 14:35:43 +00:00
|
|
|
$this->user_id = $this->factory->user->create( array( 'role' => 'shop_manager' ) );
|
|
|
|
wp_set_current_user( $this->user_id );
|
2019-05-01 22:05:00 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
gateways( $setup_wizard ),
|
|
|
|
array(
|
|
|
|
'paypal' => false,
|
|
|
|
)
|
|
|
|
);
|
2017-12-13 14:35:43 +00:00
|
|
|
|
2019-05-14 21:34:21 +00:00
|
|
|
// set admin user.
|
2017-12-13 14:35:43 +00:00
|
|
|
$this->user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
|
|
|
|
wp_set_current_user( $this->user_id );
|
|
|
|
|
|
|
|
update_option( 'woocommerce_default_country', 'US' );
|
2019-05-01 22:05:00 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
gateways( $setup_wizard ),
|
|
|
|
array(
|
|
|
|
'stripe' => true,
|
|
|
|
'ppec_paypal' => true,
|
|
|
|
)
|
|
|
|
);
|
2017-12-13 14:35:43 +00:00
|
|
|
|
|
|
|
update_option( 'woocommerce_default_country', 'CN' );
|
2019-05-01 22:05:00 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
gateways( $setup_wizard ),
|
|
|
|
array(
|
|
|
|
'ppec_paypal' => true,
|
|
|
|
)
|
|
|
|
);
|
2017-12-13 14:35:43 +00:00
|
|
|
|
|
|
|
update_option( 'woocommerce_default_country', 'SE' );
|
2019-05-01 22:05:00 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
gateways( $setup_wizard ),
|
|
|
|
array(
|
|
|
|
'klarna_checkout' => true,
|
|
|
|
'ppec_paypal' => true,
|
|
|
|
'stripe' => false,
|
|
|
|
)
|
|
|
|
);
|
2017-12-13 14:35:43 +00:00
|
|
|
|
|
|
|
update_option( 'woocommerce_default_country', 'DE' );
|
2019-05-01 22:05:00 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
gateways( $setup_wizard ),
|
|
|
|
array(
|
|
|
|
'klarna_payments' => true,
|
|
|
|
'ppec_paypal' => true,
|
|
|
|
'stripe' => false,
|
|
|
|
)
|
|
|
|
);
|
2017-12-13 14:35:43 +00:00
|
|
|
|
|
|
|
update_option( 'woocommerce_default_country', 'GB' );
|
|
|
|
update_option( 'woocommerce_sell_in_person', 'yes' );
|
2019-05-01 22:05:00 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
gateways( $setup_wizard ),
|
|
|
|
array(
|
|
|
|
'square' => true,
|
|
|
|
'ppec_paypal' => true,
|
|
|
|
'stripe' => false,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2017-12-13 14:35:43 +00:00
|
|
|
}
|