You are here

function UcCouponTestCase::createCoupon in Ubercart Discount Coupons 7.3

2 calls to UcCouponTestCase::createCoupon()
UcCouponTestCase::testCoupon in tests/uc_coupon.test
UcCouponTestCase::testGiftCertificate in tests/uc_coupon.test

File

tests/uc_coupon.test, line 31
Ubercart Discount Coupon Tests.

Class

UcCouponTestCase
SimpleTests for Ubercart Discount Coupons

Code

function createCoupon($edit = array()) {
  $edit += array(
    'code' => $this
      ->randomName(8),
    'name' => $this
      ->randomName(20),
    'discount' => mt_rand(1, 50) . '%',
    'status' => 1,
  );
  $form_state = array(
    'values' => $edit,
  );
  drupal_form_submit('uc_coupon_add_form', $form_state);
  $cid = db_query('SELECT cid FROM {uc_coupons} WHERE code = :code', array(
    ':code' => trim(strtoupper($edit['code'])),
  ))
    ->fetchField();
  $this
    ->assertTrue($cid, 'Coupon was created successfully');
  if (!$cid) {
    debug(form_get_errors(), 'Form errors:');
  }
  $coupon = uc_coupon_load($cid);
  return $coupon;
}