You are here

public function CommerceDiscountDateTest::testDiscountDateProductDiscountInTime in Commerce Discount 7

Test product discount in timespan.

File

tests/commerce_discount_date.test, line 79
Commerce Discounts date tests.

Class

CommerceDiscountDateTest
Testing commerce discount date functionality.

Code

public function testDiscountDateProductDiscountInTime() {

  // Create a discount valid from yesterday until tomorrow.
  $start_time = time() - $this->dayInSeconds;
  $end_time = time() + $this->dayInSeconds;
  $this
    ->createDateDiscount('product_discount', 'fixed_amount', 300, $start_time, $end_time);

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

  // Invoke line item price re-calculation.
  $line_item = $order_wrapper->commerce_line_items
    ->get(0)
    ->value();
  rules_invoke_event('commerce_product_calculate_sell_price', $line_item);

  // Check if the discount was added as a component to the line item.
  $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
  $price_data = $line_item_wrapper->commerce_unit_price->data
    ->value();
  $this
    ->assertEqual($price_data['components'][1]['price']['amount'], -300, 'Product discount is applied when discount is in time frame.');
}