Fixed tests for the new cart and coupons functions
This commit is contained in:
parent
f64ea948f1
commit
f3694cf17b
|
@ -8,88 +8,6 @@ namespace WooCommerce\Tests\Cart;
|
|||
*/
|
||||
class Cart extends \WC_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* Helper method to get the checkout URL
|
||||
*
|
||||
* @since 2.3
|
||||
* @return string
|
||||
*/
|
||||
private function get_checkout_url() {
|
||||
|
||||
// Get the checkout URL
|
||||
$checkout_page_id = wc_get_page_id( 'checkout' );
|
||||
|
||||
$checkout_url = '';
|
||||
|
||||
// Check if there is a checkout page
|
||||
if ( $checkout_page_id ) {
|
||||
|
||||
// Get the permalink
|
||||
$checkout_url = get_permalink( $checkout_page_id );
|
||||
|
||||
// Force SSL if needed
|
||||
if ( is_ssl() || 'yes' === get_option( 'woocommerce_force_ssl_checkout' ) ) {
|
||||
$checkout_url = str_replace( 'http:', 'https:', $checkout_url );
|
||||
}
|
||||
|
||||
// Allow filtering of checkout URL
|
||||
$checkout_url = apply_filters( 'woocommerce_get_checkout_url', $checkout_url );
|
||||
}
|
||||
|
||||
return $checkout_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_checkout_url over HTTP
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
public function test_get_checkout_url_regular() {
|
||||
|
||||
// Get the original setting
|
||||
$o_setting = get_option( 'woocommerce_force_ssl_checkout' );
|
||||
|
||||
// Force SSL checkout
|
||||
update_option( 'woocommerce_force_ssl_checkout', 'no' );
|
||||
|
||||
$this->assertEquals( $this->get_checkout_url(), WC()->cart->get_checkout_url() );
|
||||
|
||||
// Restore option
|
||||
update_option( 'woocommerce_force_ssl_checkout', $o_setting );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_checkout_url over HTTP
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
public function test_get_checkout_url_ssl() {
|
||||
|
||||
// Get the original setting
|
||||
$o_setting = get_option( 'woocommerce_force_ssl_checkout' );
|
||||
|
||||
// Force SSL checkout
|
||||
update_option( 'woocommerce_force_ssl_checkout', 'yes' );
|
||||
|
||||
$this->assertEquals( $this->get_checkout_url(), WC()->cart->get_checkout_url() );
|
||||
|
||||
// Restore option
|
||||
update_option( 'woocommerce_force_ssl_checkout', $o_setting );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_cart_url method
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
public function test_get_cart_url() {
|
||||
$cart_page_url = wc_get_page_permalink( 'cart' );
|
||||
|
||||
$this->assertEquals( apply_filters( 'woocommerce_get_cart_url', $cart_page_url ? $cart_page_url : '' ), WC()->cart->get_cart_url() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_remove_url
|
||||
*
|
||||
|
@ -409,27 +327,13 @@ class Cart extends \WC_Unit_Test_Case {
|
|||
update_option( 'woocommerce_calc_taxes', 'no' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test coupons_enabled method
|
||||
*/
|
||||
public function test_coupons_enabled() {
|
||||
$this->assertEquals( apply_filters( 'woocommerce_coupons_enabled', get_option( 'woocommerce_enable_coupons' ) == 'yes' ), WC()->cart->coupons_enabled() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ship_to_billing_address_only method
|
||||
*/
|
||||
public function test_ship_to_billing_address_only() {
|
||||
$this->assertEquals( wc_ship_to_billing_address_only(), WC()->cart->ship_to_billing_address_only() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test needs_shipping_address method
|
||||
*/
|
||||
public function test_needs_shipping_address() {
|
||||
$needs_shipping_address = false;
|
||||
|
||||
if ( WC()->cart->needs_shipping() === true && ! WC()->cart->ship_to_billing_address_only() ) {
|
||||
if ( WC()->cart->needs_shipping() === true && ! wc_ship_to_billing_address_only() ) {
|
||||
$needs_shipping_address = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,78 @@ namespace WooCommerce\Tests\Cart;
|
|||
*/
|
||||
class Functions extends \WC_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* Helper method to get the checkout URL
|
||||
*
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_checkout_url() {
|
||||
|
||||
// Get the checkout URL
|
||||
$checkout_page_id = wc_get_page_id( 'checkout' );
|
||||
|
||||
$checkout_url = '';
|
||||
|
||||
// Check if there is a checkout page
|
||||
if ( $checkout_page_id ) {
|
||||
|
||||
// Get the permalink
|
||||
$checkout_url = get_permalink( $checkout_page_id );
|
||||
|
||||
// Force SSL if needed
|
||||
if ( is_ssl() || 'yes' === get_option( 'woocommerce_force_ssl_checkout' ) ) {
|
||||
$checkout_url = str_replace( 'http:', 'https:', $checkout_url );
|
||||
}
|
||||
|
||||
// Allow filtering of checkout URL
|
||||
$checkout_url = apply_filters( 'woocommerce_get_checkout_url', $checkout_url );
|
||||
}
|
||||
|
||||
return $checkout_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_checkout_url over HTTP
|
||||
*
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public function test_get_checkout_url_regular() {
|
||||
|
||||
// Get the original setting
|
||||
$o_setting = get_option( 'woocommerce_force_ssl_checkout' );
|
||||
|
||||
// Force SSL checkout
|
||||
update_option( 'woocommerce_force_ssl_checkout', 'no' );
|
||||
|
||||
$this->assertEquals( $this->get_checkout_url(), wc_get_checkout_url() );
|
||||
|
||||
// Restore option
|
||||
update_option( 'woocommerce_force_ssl_checkout', $o_setting );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_checkout_url over HTTP
|
||||
*
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public function test_get_checkout_url_ssl() {
|
||||
|
||||
// Get the original setting
|
||||
$o_setting = get_option( 'woocommerce_force_ssl_checkout' );
|
||||
|
||||
// Force SSL checkout
|
||||
update_option( 'woocommerce_force_ssl_checkout', 'yes' );
|
||||
|
||||
$this->assertEquals( $this->get_checkout_url(), wc_get_checkout_url() );
|
||||
|
||||
// Restore option
|
||||
update_option( 'woocommerce_force_ssl_checkout', $o_setting );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test wc_empty_cart()
|
||||
*
|
||||
|
@ -69,4 +141,15 @@ class Functions extends \WC_Unit_Test_Case {
|
|||
|
||||
\WC_Helper_Coupon::delete_coupon( $coupon->id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_cart_url method
|
||||
*
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public function test_wc_get_cart_url() {
|
||||
$cart_page_url = wc_get_page_permalink( 'cart' );
|
||||
|
||||
$this->assertEquals( apply_filters( 'woocommerce_get_cart_url', $cart_page_url ? $cart_page_url : '' ), wc_get_cart_url() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,4 +37,13 @@ class Functions extends \WC_Unit_Test_Case {
|
|||
$this->assertEmpty( wc_get_coupon_type( 'bogus_type' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test coupons_enabled method
|
||||
*
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public function test_wc_is_coupons_enabled() {
|
||||
$this->assertEquals( apply_filters( 'woocommerce_coupons_enabled', get_option( 'woocommerce_enable_coupons' ) == 'yes' ), wc_is_coupons_enabled() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue