woocommerce/tests/legacy/unit-tests/setup/functions.php

106 lines
2.6 KiB
PHP
Raw Normal View History

<?php
/**
2019-05-14 21:34:21 +00:00
* Class WC_Tests_Setup_Functions.
* @package WooCommerce\Tests\Setup
*/
2019-05-14 21:34:21 +00:00
/**
* Class WC_Tests_Setup_Functions.
*/
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
// non-admin user.
$this->user_id = $this->login_as_role( 'shop_manager' );
$this->assertEquals(
array(
'paypal' => false,
),
$this->get_gateways_statuses( $setup_wizard )
);
2019-05-14 21:34:21 +00:00
// set admin user.
$this->user_id = $this->login_as_administrator();
update_option( 'woocommerce_default_country', 'US' );
$this->assertEquals(
array(
'stripe' => true,
2019-05-16 14:26:34 +00:00
'ppec_paypal' => false,
),
$this->get_gateways_statuses( $setup_wizard )
);
update_option( 'woocommerce_default_country', 'CN' );
$this->assertEquals(
array(
'ppec_paypal' => true,
),
$this->get_gateways_statuses( $setup_wizard )
);
update_option( 'woocommerce_default_country', 'SE' );
$this->assertEquals(
array(
'klarna_checkout' => true,
2019-05-16 14:26:34 +00:00
'ppec_paypal' => false,
'stripe' => true,
),
$this->get_gateways_statuses( $setup_wizard )
);
update_option( 'woocommerce_default_country', 'DE' );
$this->assertEquals(
array(
'klarna_payments' => true,
2019-05-16 14:26:34 +00:00
'ppec_paypal' => false,
'stripe' => true,
),
$this->get_gateways_statuses( $setup_wizard )
);
update_option( 'woocommerce_default_country', 'GB' );
update_option( 'woocommerce_sell_in_person', 'yes' );
$this->assertEquals(
array(
'square' => false,
2019-05-16 14:26:34 +00:00
'ppec_paypal' => false,
'stripe' => true,
),
$this->get_gateways_statuses( $setup_wizard )
);
}
/**
* Helper method 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
*/
protected function get_gateways_statuses( $setup_wizard ) {
return array_map( array( $this, 'get_enabled' ), $setup_wizard->get_wizard_in_cart_payment_gateways() );
}
/**
* Return wheter a given gateway is enable or not.
*
* @param array $gateway Gateway information.
* @return bool
*/
protected function get_enabled( $gateway ) {
return isset( $gateway['enabled'] ) && $gateway['enabled'];
}
}