You are here

public function CommerceDiscountUsageUITest::testCommerceDiscountUsageUIAddDiscount in Commerce Discount 7

Test usage specific elements in the add discount UI.

File

tests/commerce_discount_usage_ui.test, line 34
Commerce Discounts usage UI tests.

Class

CommerceDiscountUsageUITest
Testing commerce discount usage module UI.

Code

public function testCommerceDiscountUsageUIAddDiscount() {

  // Login with store admin.
  $this
    ->drupalLogin($this->store_admin);

  // Access to the admin discount creation page.
  $this
    ->drupalGet('admin/commerce/discounts/add');

  // Check the integrity of the add form.
  $this
    ->assertFieldByName('commerce_discount_fields[discount_usage_per_person][und][0][value]', NULL, 'Maximum usage per customer field is present');
  $this
    ->assertFieldByName('commerce_discount_fields[discount_usage_limit][und][0][value]', NULL, 'Maximum overall usage field is present');

  // Create a discount.
  $values = array(
    'label' => 'Order discount - fixed',
    'name' => 'order_discount_fixed',
    'component_title' => 'Order discount',
    'commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]' => 12.77,
    'commerce_discount_fields[discount_usage_limit][und][0][value]' => 5,
  );
  $this
    ->drupalPost(NULL, $values, t('Save discount'));

  // Load the discount and wrap it.
  $discount = entity_load_single('commerce_discount', 1);
  $discount_wrapper = entity_metadata_wrapper('commerce_discount', $discount);

  // Check the usage fields of the stored discount.
  $this
    ->assertTrue($discount_wrapper->discount_usage_per_person
    ->value() == 0, 'Discount uses field is empty.');
  $this
    ->assertTrue($discount_wrapper->discount_usage_limit
    ->value() == 5, 'Discount max uses stored correctly.');

  // Check the discounts listing.
  $this
    ->assertText(t('@amount available', array(
    '@amount' => 5,
  )), 'Analytics - Max usage is shown.');
  $this
    ->assertText(t('Used @amount times', array(
    '@amount' => 0,
  )), 'Analytics - Usage is shown.');
}