You are here

protected function UbercartTestBase::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.

2 calls to UbercartTestBase::populateCheckoutForm()
QuoteTest::testQuote in shipping/uc_quote/src/Tests/QuoteTest.php
Tests basic flatrate shipping quote functionality.
UbercartTestBase::checkout in uc_store/src/Tests/UbercartTestBase.php
Executes the checkout process.

File

uc_store/src/Tests/UbercartTestBase.php, line 254

Class

UbercartTestBase
Base class for Ubercart Simpletest tests.

Namespace

Drupal\uc_store\Tests

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]' => mt_rand(10000, 99999),
    ];

    // 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;
}