user_id = $this->factory->user->create( array( 'role' => 'shop_manager' ) ); wp_set_current_user( $this->user_id ); $this->assertEquals( array( 'paypal' => false, ), $this->get_gateways_statuses( $setup_wizard ) ); // 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( array( 'stripe' => true, 'ppec_paypal' => true, ), $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, 'ppec_paypal' => true, 'stripe' => true, ), $this->get_gateways_statuses( $setup_wizard ) ); update_option( 'woocommerce_default_country', 'DE' ); $this->assertEquals( array( 'klarna_payments' => true, 'ppec_paypal' => true, '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, 'ppec_paypal' => true, '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']; } }