2015-03-02 16:06:03 +00:00
|
|
|
<?php
|
2015-03-06 15:32:40 +00:00
|
|
|
|
|
|
|
namespace WooCommerce\Tests\Cart;
|
|
|
|
|
2015-03-02 16:06:03 +00:00
|
|
|
/**
|
2015-03-06 15:32:40 +00:00
|
|
|
* Class Functions
|
|
|
|
* @package WooCommerce\Tests\Cart
|
2015-03-02 16:06:03 +00:00
|
|
|
*/
|
2015-03-06 15:32:40 +00:00
|
|
|
class Functions extends \WC_Unit_Test_Case {
|
2015-03-02 16:06:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wc_empty_cart()
|
|
|
|
*
|
|
|
|
* @since 2.3.0
|
|
|
|
*/
|
|
|
|
public function test_wc_empty_cart() {
|
|
|
|
// Create dummy product
|
2015-03-06 15:32:40 +00:00
|
|
|
$product = \WC_Helper_Product::create_simple_product();
|
2015-03-02 16:06:03 +00:00
|
|
|
|
|
|
|
// Add the product to the cart
|
|
|
|
WC()->cart->add_to_cart( $product->id, 1 );
|
|
|
|
|
|
|
|
// Empty the cart
|
|
|
|
wc_empty_cart();
|
|
|
|
|
|
|
|
// Check if the cart is empty
|
|
|
|
$this->assertEquals( 0, WC()->cart->get_cart_contents_count() );
|
2015-03-02 16:11:42 +00:00
|
|
|
|
|
|
|
// Delete the previously created product
|
2015-03-06 15:32:40 +00:00
|
|
|
\WC_Helper_Product::delete_product( $product->id );
|
2015-03-02 16:06:03 +00:00
|
|
|
}
|
2015-04-14 14:37:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wc_format_list_of_items()
|
|
|
|
*
|
|
|
|
* @since 2.4
|
|
|
|
*/
|
|
|
|
public function test_wc_format_list_of_items() {
|
|
|
|
$items = array( 'Title 1', 'Title 2' );
|
|
|
|
|
2015-08-14 18:39:20 +00:00
|
|
|
$this->assertEquals( "“Title 1” and “Title 2”", wc_format_list_of_items( $items ) );
|
2015-04-14 14:37:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wc_cart_totals_subtotal_html()
|
|
|
|
*
|
|
|
|
* @todo test with taxes incl./excl.
|
|
|
|
* @since 2.4
|
|
|
|
*/
|
|
|
|
public function test_wc_cart_totals_subtotal_html() {
|
|
|
|
$product = \WC_Helper_Product::create_simple_product();
|
|
|
|
|
|
|
|
WC()->cart->add_to_cart( $product->id, 1 );
|
|
|
|
|
|
|
|
$this->expectOutputString( wc_price( $product->price ), wc_cart_totals_subtotal_html() );
|
|
|
|
|
|
|
|
\WC_Helper_Product::delete_product( $product->id );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wc_cart_totals_coupon_label()
|
|
|
|
*
|
|
|
|
* @since 2.4
|
|
|
|
*/
|
|
|
|
public function test_wc_cart_totals_coupon_label() {
|
|
|
|
$coupon = \WC_Helper_Coupon::create_coupon();
|
|
|
|
|
|
|
|
$this->expectOutputString( apply_filters( 'woocommerce_cart_totals_coupon_label', 'Coupon: ' . $coupon->code ), wc_cart_totals_coupon_label( $coupon ) );
|
|
|
|
|
|
|
|
\WC_Helper_Coupon::delete_coupon( $coupon->id );
|
|
|
|
}
|
2015-03-02 16:06:03 +00:00
|
|
|
}
|