public function CommerceCouponTest::testCommerceCouponUIAddCoupon in Commerce Coupon 7.2        
                          
                  
                        
File
 
   - ./commerce_coupon.test, line 189
- Commerce Coupon tests.
Class
  
  - CommerceCouponTest 
- Testing commerce coupon UI and functionality.
Code
public function testCommerceCouponUIAddCoupon() {
  
  $this
    ->drupalLogin($this->store_customer);
  
  $this
    ->drupalGet('admin/commerce/coupons/add');
  $this
    ->assertResponse(403, 'Normal user is not able to add a coupon using the admin interface');
  
  $this
    ->drupalLogin($this->store_admin);
  
  $this
    ->drupalGet('admin/commerce/coupons/add');
  $this
    ->assertResponse(200, 'Store admin user is allowed to add a discount using the admin interface');
  
  $this
    ->assertFieldByName('code', NULL, 'Coupon code field is present');
  $this
    ->assertFieldByName('generate', NULL, 'Coupon code generate field is present');
  $this
    ->assertFieldByName('commerce_discount_reference[und][0][target_id]', NULL, 'Discount reference field is present');
  $this
    ->assertFieldByName('status', 1, 'Coupon status field is present and enabled');
  $this
    ->assertFieldById('edit-submit', t('Save coupon'), 'Save coupon button is present');
  
  $this
    ->drupalPost(NULL, array(), t('Save coupon'));
  $this
    ->assertText(t('You must enter a code.'), 'Validation message for missing code.');
  $this
    ->assertText(t('field is required.'), 'Validation message for discount reference.');
  
  $discount = $this
    ->createDiscount('order_discount', 'fixed_amount', 300);
  
  $this
    ->drupalGet('admin/commerce/coupons/add');
  $values = array(
    
    'code' => 'TEST_COUPON ',
    'commerce_discount_reference[und][0][target_id]' => $discount->label . ' (' . $discount
      ->internalIdentifier() . ')',
  );
  $this
    ->drupalPost(NULL, $values, t('Save coupon'));
  
  $coupon = entity_load_single('commerce_coupon', 1);
  $this
    ->assertEqual($coupon->code, 'TEST_COUPON', 'Coupon code is correct');
  
  $this
    ->assertUrl('admin/commerce/coupons', array(), 'Landing page after save is the coupons list.');
  $this
    ->assertText($values['code'], 'Label of the coupon is present.');
}