You are here

public function CommerceDiscountTest::testCommerceDiscountPercentageOrderDiscount in Commerce Discount 7

Test percentage order discounts.

File

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

Class

CommerceDiscountTest
Testing commerce discounts functionality.

Code

public function testCommerceDiscountPercentageOrderDiscount() {

  // Testing percentage discount.
  // Create a percentage order discount of 5%.
  $discount = $this
    ->createDiscount('order_discount', 'percentage', 5);

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

  // Recalculate discounts.
  $order_wrapper = commerce_cart_order_refresh($order);

  // Check if the discount was applied on the order total price.
  $this
    ->assertTrue($order_wrapper->commerce_order_total->amount
    ->value() == 950, 'Percentage order discount is deducted correctly.');

  // Recalculate discounts.
  $order_wrapper = commerce_cart_order_refresh($order);

  // Check if the discount was applied on the order total price.
  $this
    ->assertTrue($order_wrapper->commerce_order_total->amount
    ->value() == 950, 'Percentage order discount is deducted correctly even after refresh.');

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

  // Recalculate discounts.
  $order_wrapper = commerce_cart_order_refresh($order);
  $this
    ->assertTrue($order_wrapper->commerce_order_total->amount
    ->value() == 1000, "Percentage order discount is removed when it's not applicable.");
}