You are here

public function CommerceCouponTest::testMultipleCouponsSameDiscount in Commerce Coupon 7.2

File

./commerce_coupon.test, line 284
Commerce Coupon tests.

Class

CommerceCouponTest
Testing commerce coupon UI and functionality.

Code

public function testMultipleCouponsSameDiscount() {

  // Login as administrator and add the field to the footer of the cart View.
  $this
    ->drupalLogin($this->store_admin);

  // Create a discount with 'multi' coupon strateg and add two coupons to it.
  $discount = $this
    ->createDiscount('order_discount', 'fixed_amount', 300, '', '', 10, 'multi');
  $coupon = commerce_coupon_create('discount_coupon');
  $coupon->code = 'HALF OFF';
  $coupon->commerce_discount_reference[LANGUAGE_NONE][0]['target_id'] = $discount->discount_id;
  commerce_coupon_save($coupon);

  // Add another coupon to the same discount.
  $coupon = commerce_coupon_create('discount_coupon');
  $coupon->code = 'HALF OFF 2';
  $coupon->commerce_discount_reference[LANGUAGE_NONE][0]['target_id'] = $discount->discount_id;
  commerce_coupon_save($coupon);
  _commerce_discount_rebuild_rules_config(array(
    $discount,
  ));

  // Create a cart order and ensure we can see the code form on the cart
  // management page.
  $this
    ->createDummyOrder($this->store_admin->uid, array(
    $this->product->product_id => 1,
  ), $status = 'cart');
  $this
    ->drupalGet('checkout');

  // Test coupon code validation.
  $values = array(
    'commerce_coupon[coupon_code]' => 'HALF OFF',
  );
  $this
    ->drupalPost(NULL, $values, t('Add coupon'));
  $this
    ->drupalGet('checkout');
  $this
    ->assertText(t('$7.00'), 'Order total decreased with coupon value.');
  $values = array(
    'commerce_coupon[coupon_code]' => 'HALF OFF 2',
  );
  $this
    ->drupalPost(NULL, $values, t('Add coupon'));
  $this
    ->drupalGet('checkout');
  $this
    ->assertText(t('$4.00'), 'Order total decreased with second coupon value.');
}