public function CommerceCouponTest::testCommerceCouponUICartForm in Commerce Coupon 7.2
File
- ./commerce_coupon.test, line 242
- Commerce Coupon tests.
Class
- CommerceCouponTest
- Testing commerce coupon UI and functionality.
Code
public function testCommerceCouponUICartForm() {
$this
->drupalLogin($this->store_admin);
$view = views_get_view('commerce_cart_form');
$view
->add_item('default', 'footer', 'commerce_order', 'coupon_cart_form');
$view
->save();
$this
->createDummyOrder($this->store_admin->uid, array(
$this->product->product_id => 1,
), $status = 'cart');
$this
->drupalGet('cart');
$this
->assertFieldByName('coupon_code', NULL, 'Coupon code field is present on cart management page.');
$this
->assertFieldByName('coupon_add', NULL, 'Coupon add submit button is present on cart management page.');
$this
->drupalPost(NULL, array(), t('Add coupon'));
$this
->assertText(t('Please enter a coupon code.'), 'Validation message for missing code.');
$this
->drupalGet('cart');
$values = array(
'coupon_code' => 'BLAH',
);
$this
->drupalPost(NULL, $values, t('Add coupon'));
$this
->assertText(t('Please enter a valid coupon code.'), 'Validation message for code that doesn\'t exist.');
$discount = $this
->createDiscount('order_discount', 'fixed_amount', 300);
$coupon = commerce_coupon_create('discount_coupon');
$coupon->code = 'HALF OFF';
$coupon->commerce_discount_reference['und'][0]['target_id'] = $discount->discount_id;
commerce_coupon_save($coupon);
$this
->drupalGet('cart');
$values = array(
'coupon_code' => 'HALF OFF',
);
$this
->drupalPost(NULL, $values, t('Add coupon'));
$this
->assertText(t('Coupon code applied.'), 'Coupon applied message for valid code.');
$this
->drupalGet('cart');
$values = array(
'coupon_code' => 'HALF OFF ',
);
$this
->drupalPost(NULL, $values, t('Add coupon'));
$this
->assertText(t('The coupon you have entered has already been applied to your order'), 'Coupon applied message for valid code.');
}