You are here

public function CommerceDiscountTest::testCommerceDiscountFixedOrderDiscount in Commerce Discount 7

Test fixed order discounts.

File

tests/commerce_discount.test, line 90
Commerce Discounts tests.

Class

CommerceDiscountTest
Testing commerce discounts functionality.

Code

public function testCommerceDiscountFixedOrderDiscount() {

  // Testing fixed discount.
  // Create a fixed order discount of $3.
  $discount = $this
    ->createDiscount('order_discount', 'fixed_amount', 300);

  // Create an order.
  $order = $this
    ->createDummyOrder($this->store_customer->uid, array(
    $this->product->product_id => 1,
  ), 'completed');

  // Recalculate discounts.
  $order_wrapper = commerce_cart_order_refresh($order);

  // Check if the discount was applied on the order total price.
  $this
    ->assertTrue($order_wrapper->commerce_order_total->amount
    ->value() == 700, 'Fixed order discount is deducted correctly.');

  // Recalculate discounts.
  $order_wrapper = commerce_cart_order_refresh($order);

  // Check if the discount was applied on the order total price.
  $this
    ->assertTrue($order_wrapper->commerce_order_total->amount
    ->value() == 700, 'Fixed order discount is deducted correctly even after order refresh.');

  // Disable the discount.
  $discount->status = FALSE;
  entity_save('commerce_discount', $discount);

  // Re-save the order.
  // Check if the discount was applied on the order total price.
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  $order_wrapper
    ->save();

  // Recalculate discounts.
  $order_wrapper = commerce_cart_order_refresh($order);
  $this
    ->assertTrue($order_wrapper->commerce_order_total->amount
    ->value() == 1000, "Fixed order discount is removed when it's not applicable.");
}