You are here

protected function UbercartJavascriptTestBase::populateCheckoutForm in Ubercart 8.4

Helper function to fill-in required fields on the checkout page.

Parameters

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

Return value

array The values array ready to pass to the checkout page.

1 call to UbercartJavascriptTestBase::populateCheckoutForm()
UbercartJavascriptTestBase::checkout in uc_store/tests/src/FunctionalJavascript/UbercartJavascriptTestBase.php
Executes the checkout process.

File

uc_store/tests/src/FunctionalJavascript/UbercartJavascriptTestBase.php, line 133

Class

UbercartJavascriptTestBase
Base class for Ubercart PHPUnit browser tests.

Namespace

Drupal\Tests\uc_store\FunctionalJavascript

Code

protected function populateCheckoutForm(array $edit = []) {
  foreach ([
    'billing',
    'delivery',
  ] as $pane) {
    $prefix = 'panes[' . $pane . ']';
    $key = $prefix . '[country]';
    $country_id = isset($edit[$key]) ? $edit[$key] : \Drupal::config('uc_store.settings')
      ->get('address.country');
    $country = \Drupal::service('country_manager')
      ->getCountry($country_id);
    $edit += [
      $prefix . '[first_name]' => $this
        ->randomMachineName(10),
      $prefix . '[last_name]' => $this
        ->randomMachineName(10),
      $prefix . '[street1]' => $this
        ->randomMachineName(10),
      $prefix . '[city]' => $this
        ->randomMachineName(10),
      $prefix . '[postal_code]' => (string) mt_rand(10000, 99999),
      $prefix . '[country]' => $country_id,
    ];

    // Don't try to set the zone unless the store country has zones!
    if (!empty($country
      ->getZones())) {
      $edit += [
        $prefix . '[zone]' => array_rand($country
          ->getZones()),
      ];
    }
  }

  // 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
      ->randomMachineName(8) . '@example.com';
  }
  return $edit;
}