You are here

public function CommerceDiscountUsageTest::testCommerceDiscountUsageFixedProductDiscount in Commerce Discount 7

Test fixed product discounts.

File

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

Class

CommerceDiscountUsageTest
Testing commerce discount usage module functionality.

Code

public function testCommerceDiscountUsageFixedProductDiscount() {
  $this
    ->createUsageDiscount('product_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 added as a component to the line item.
  $price = commerce_price_wrapper_value($order_wrapper->commerce_line_items
    ->get(0), 'commerce_unit_price');
  $this
    ->assertTrue($price['data']['components'][1]['price']['amount'] == -300, 'Fixed product discount is added as a price component to the line item.');
  commerce_order_save($order);

  // 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 added as a component to the line item.
  $price = commerce_price_wrapper_value($order_wrapper->commerce_line_items
    ->get(0), 'commerce_unit_price');
  $this
    ->assertTrue(count($price['data']['components']) === 1, 'Fixed product discount is ignored after maximal usage.');
}