You are here

public function CommerceDiscountTest::testCommerceDiscountCompatibilityStrategiesRefresh in Commerce Discount 7

Test discount compatibility regression https://www.drupal.org/node/2621526.

Discount "toggles" when cart page is refreshed.

File

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

Class

CommerceDiscountTest
Testing commerce discounts functionality.

Code

public function testCommerceDiscountCompatibilityStrategiesRefresh() {

  // Create two discounts set to execute one after the other.
  $discount_one = $this
    ->createDiscount('product_discount', 'percentage', 10, 'of1');
  $discount_one_wrapper = entity_metadata_wrapper('commerce_discount', $discount_one);
  $discount_two = $this
    ->createDiscount('product_discount', 'percentage', 20, 'of2', 2);
  $discount_two_wrapper = entity_metadata_wrapper('commerce_discount', $discount_two);

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

  // Test compatibility with discount one compatible only with discount two
  // And discount two compatible with any discount. Both should be applied.
  $discount_one_wrapper->commerce_compatibility_strategy = 'only';
  $discount_one_wrapper->commerce_compatibility_selection = array(
    $discount_two->discount_id,
  );
  $discount_one_wrapper
    ->save();
  $discount_two_wrapper->commerce_compatibility_strategy = 'any';
  $discount_two_wrapper
    ->save();
  commerce_cart_order_refresh($order);
  $properly_applied = $this
    ->discountAppliedToOrder('of1', $order) && $this
    ->discountAppliedToOrder('of2', $order);
  $this
    ->assertTrue($properly_applied, t('Both discounts applied when discount one is compatible with any discount and discount two is compatible only with discount one.'));

  // Regression test for discount compatibility with itself.
  commerce_cart_order_refresh($order);
  $properly_applied = $this
    ->discountAppliedToOrder('of1', $order) && $this
    ->discountAppliedToOrder('of2', $order);
  $this
    ->assertTrue($properly_applied, t('Both discounts applied when discount one is compatible with any discount, discount two is compatible only with discount one and the order refreshed one more time.'));
}