From f3694cf17b17d0d8e8df16ca6e05d005fd59a7ca Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 28 Oct 2015 16:09:53 -0200 Subject: [PATCH] Fixed tests for the new cart and coupons functions --- tests/unit-tests/cart/cart.php | 98 +-------------------------- tests/unit-tests/cart/functions.php | 83 +++++++++++++++++++++++ tests/unit-tests/coupon/functions.php | 9 +++ 3 files changed, 93 insertions(+), 97 deletions(-) diff --git a/tests/unit-tests/cart/cart.php b/tests/unit-tests/cart/cart.php index 939beaab59f..5f1ec4aa512 100644 --- a/tests/unit-tests/cart/cart.php +++ b/tests/unit-tests/cart/cart.php @@ -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; } diff --git a/tests/unit-tests/cart/functions.php b/tests/unit-tests/cart/functions.php index 45cd85a422c..960ca0b306e 100644 --- a/tests/unit-tests/cart/functions.php +++ b/tests/unit-tests/cart/functions.php @@ -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() ); + } } diff --git a/tests/unit-tests/coupon/functions.php b/tests/unit-tests/coupon/functions.php index 1be553343e4..4764769df99 100644 --- a/tests/unit-tests/coupon/functions.php +++ b/tests/unit-tests/coupon/functions.php @@ -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() ); + } + }