You are here

function UcAddressesCartCheckoutTestCase::populateCheckoutForm in Ubercart Addresses 6.2

Same name and namespace in other branches
  1. 7 tests/uc_addresses.checkout.test \UcAddressesCartCheckoutTestCase::populateCheckoutForm()

Populates the checkout form.

With Ubercart Addresses, address fields on checkout have a bit different name. Example: Instead of "panes[delivery][delivery_first_name]", Ubercart Addresses uses "panes[delivery][delivery][delivery_first_name]". This is done to fix issues with the zone field.

Parameters

array $edit: The form-values array to which to add required fields.

array $address_panes: (optional) The address panes to populate. Defaults to both billing and delivery pane.

2 calls to UcAddressesCartCheckoutTestCase::populateCheckoutForm()
UcAddressesCartCheckoutTestCase::checkout in tests/uc_addresses.checkout.test
Override of UbercartTestHelper::checkout().
UcAddressesCartCheckoutTestCase::testAnonymousCheckoutWithoutMailAddress in tests/uc_addresses.checkout.test
Tests if a customer can checkout when not providing a mail address.

File

tests/uc_addresses.checkout.test, line 98
Test cases for checkout.

Class

UcAddressesCartCheckoutTestCase
Test cases for checkout.

Code

function populateCheckoutForm($edit = array(), $address_panes = array(
  'billing',
  'delivery',
)) {
  foreach ($address_panes as $pane) {
    $prefix = 'panes[' . $pane . '][' . $pane . '][' . $pane;
    $key = $prefix . '_country]';
    $country = empty($edit[$key]) ? variable_get('uc_store_country', 840) : $edit[$key];
    $zone_id = db_result(db_query('SELECT zone_id FROM {uc_zones} WHERE zone_country_id = %d ORDER BY rand()', variable_get('uc_store_country', $country)));
    $edit += array(
      $prefix . '_first_name]' => $this
        ->randomName(10),
      $prefix . '_last_name]' => $this
        ->randomName(10),
      $prefix . '_street1]' => $this
        ->randomName(10),
      $prefix . '_city]' => $this
        ->randomName(10),
      $prefix . '_zone]' => $zone_id,
      $prefix . '_postal_code]' => mt_rand(10000, 99999),
    );
  }

  // If the email address has not been set, and the user has not logged in,
  // add a primary email address.
  if (!isset($edit['panes[customer][primary_email]']) && !$this->loggedInUser) {
    $edit['panes[customer][primary_email]'] = $this
      ->randomName(8) . '@example.com';
  }
  return $edit;
}