You are here

public function CommerceDiscountUsageTest::testCommerceDiscountUsageFixedOrderDiscount in Commerce Discount 7

Test fixed order discounts.

File

tests/commerce_discount_usage.test, line 37
Commerce Discounts usage tests.

Class

CommerceDiscountUsageTest
Testing commerce discount usage module functionality.

Code

public function testCommerceDiscountUsageFixedOrderDiscount() {

  // Testing fixed discount.
  // Create a fixed order discount of $3 limited to one use.
  $this
    ->createUsageDiscount('order_discount', 'fixed_amount', 300, 1);

  // 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 on the first use.');

  // Create another order to make sure the discount isn't applied again.
  $order = $this
    ->createDummyOrder($this->store_customer2->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() == 1000, 'Fixed order discount is ignored after maximal usage.');
}