You are here

public function CommerceDiscountDateTest::testDiscountSameDay in Commerce Discount 7

Test product discount on the same day.

File

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

Class

CommerceDiscountDateTest
Testing commerce discount date functionality.

Code

public function testDiscountSameDay() {

  // Create a discount valid for today only.
  $start_date = new DateTime();
  $start_date
    ->setTime(0, 0, 0);
  $start_time = $start_date
    ->getTimestamp();
  $end_time = $start_time;
  $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.');
}