public function CommerceDiscountDateTest::testDiscountDateProductDiscountOutOfTime in Commerce Discount 7
Test product discount out of timespan.
File
- tests/
commerce_discount_date.test, line 101 - Commerce Discounts date tests.
Class
- CommerceDiscountDateTest
- Testing commerce discount date functionality.
Code
public function testDiscountDateProductDiscountOutOfTime() {
// Create a discount valid from tomorrow.
$start_time = time() + $this->dayInSeconds;
$end_time = time() + 2 * $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
->assertTrue(count($price_data['components']) == 1, 'Product discount is ignored when discount is out of time frame.');
}