You are here

function UCXFTestCase::populateCheckoutForm in Extra Fields Checkout Pane 7

Same name and namespace in other branches
  1. 6.2 uc_extra_fields_pane.test \UCXFTestCase::populateCheckoutForm()

Override of UbercartTestHelper::populateCheckoutForm().

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][address][delivery_first_name]". This is done to fix issues with the zone field.

Parameters

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

Overrides UbercartTestHelper::populateCheckoutForm

2 calls to UCXFTestCase::populateCheckoutForm()
UCXFCheckoutTestCase::testSanitizing in ./uc_extra_fields_pane.test
Test if field values are properly sanitized.
UCXFTestCase::UbercartCheckout in ./uc_extra_fields_pane.test
Similar to UbercartTestHelper::checkout().

File

./uc_extra_fields_pane.test, line 459
Automated tests for Extra Fields Pane

Class

UCXFTestCase
Base class for all Extra Fields Pane test cases.

Code

function populateCheckoutForm($edit = array()) {
  foreach (array(
    'billing',
    'delivery',
  ) as $pane) {
    $prefix = 'panes[' . $pane . '][address][' . $pane;
    $key = $prefix . '_country]';
    $country = empty($edit[$key]) ? variable_get('uc_store_country', 840) : $edit[$key];
    $zone_id = db_query_range('SELECT zone_id FROM {uc_zones} WHERE zone_country_id = :country ORDER BY rand()', 0, 1, array(
      'country' => $country,
    ))
      ->fetchField();
    $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;
}