You are here

public function CommerceDiscountTest::testCommerceDiscountMultipleFixedOrderDiscounts in Commerce Discount 7

Test multiple fixed order discounts.

File

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

Class

CommerceDiscountTest
Testing commerce discounts functionality.

Code

public function testCommerceDiscountMultipleFixedOrderDiscounts() {

  // Create two discounts.
  $this
    ->createDiscount('order_discount', 'fixed_amount', 300, 'of1');
  $this
    ->createDiscount('order_discount', 'fixed_amount', 200, 'of2');

  // 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);
  $this
    ->assertTrue($order_wrapper->commerce_discounts
    ->count() == 2, '2 discounts are listed as applied on the order.');
  $this
    ->assertTrue($order_wrapper->commerce_order_total->amount
    ->value() == 500, 'Two fixed order discounts are applied on the total price.');
  $this
    ->assertTrue($order_wrapper->commerce_line_items
    ->count() == 3, 'An order with one product and two fixed order discounts has three line items.');
  $order_wrapper
    ->save();
  $this
    ->assertTrue($order_wrapper->commerce_line_items
    ->count() == 3, 'After updating the order it still has three line items.');
}