public function CommerceDiscountShippingTest::testCommerceDiscountShippingAndFixedAmount in Commerce Discount 7
Test a free shipping discount combined with a fixed amount discount.
File
- tests/
commerce_discount_shipping.test, line 203 - Commerce Discounts shipping tests.
Class
- CommerceDiscountShippingTest
- Testing commerce shipping discounts functionality.
Code
public function testCommerceDiscountShippingAndFixedAmount() {
$shipping_service_name = 'commerce_discount_cheap_shipping';
$order = $this
->createDummyOrder($this->store_customer->uid, array(
$this->product->product_id => 1,
), 'completed', NULL);
module_load_include('inc', 'commerce_shipping', 'commerce_shipping.rules');
commerce_shipping_rate_apply($order, $shipping_service_name);
commerce_order_save($order);
unset($order->shipping_rates);
$free_shipping_discount = $this
->createDiscount('order_discount', 'free_shipping', $shipping_service_name, 'free_shipping', 'Free cheap shipping', 1);
$this
->createDiscount('order_discount', 'fixed_amount', 1500, 'of1');
// Recalculate discounts.
$order_wrapper = commerce_cart_order_refresh($order);
// Order total before discount is 1000, assert that applying both a shipping
// discount and a fixed amount discount isn't causing the order total to
// be negative (make sure order total is properly recalculated after the
// free shipping discount is applied).
$this
->assertTrue($order_wrapper->commerce_order_total->amount
->value() == 0, 'Order total is correct when the free shipping discount has a lower weight than the fixed amount.');
// Update the free shipping discount weight to make sure the order total
// is correct when the shipping discount is evaluated after the fixed amount
// discount.
$free_shipping_discount->sort_order = 20;
$free_shipping_discount
->save();
$order_wrapper = commerce_cart_order_refresh($order);
$this
->assertTrue($order_wrapper->commerce_order_total->amount
->value() == 0, 'Order total is correct when the free shipping discount has a higher weight than the fixed amount.');
}