You are here

public function CommerceDiscountTest::testCommerceDiscountFixedProductDiscount in Commerce Discount 7

Test fixed product discounts.

File

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

Class

CommerceDiscountTest
Testing commerce discounts functionality.

Code

public function testCommerceDiscountFixedProductDiscount() {
  $discount = $this
    ->createDiscount('product_discount', 'fixed_amount', 300);

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

  // Check if the discount was added as a component to the line item.
  $price = $order_wrapper->commerce_line_items
    ->get(0)->commerce_unit_price
    ->value();
  $this
    ->assertTrue($price['data']['components'][1]['price']['amount'] == -300, 'Fixed product discount is added as a price component to the line item.');
  $this
    ->assertEqual($price['amount'], 700, 'Line item price with fixed product discount is correct.');
  $order_wrapper = commerce_cart_order_refresh($order);

  // Check if the discount was added as a component to the line item.
  $price = $order_wrapper->commerce_line_items
    ->get(0)->commerce_unit_price
    ->value();
  $this
    ->assertTrue($price['data']['components'][1]['price']['amount'] == -300, 'Fixed product discount is added as a price component to the line item even after refresh.');
  $this
    ->assertEqual($price['amount'], 700, 'Line item price with fixed product discount is correct even after refresh.');

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

  // Check if the discount is not applied.
  $price = $order_wrapper->commerce_line_items
    ->get(0)->commerce_unit_price
    ->value();
  $this
    ->assertEqual($price['amount'], 1000, 'Disabled fixed product discount is does not appear in the price.');
}