You are here

public function AvataxLibTest::resolveAddress in Drupal Commerce Connector for AvaTax 8

Retrieve geolocation information for a specified address.

Parameters

array $address: The address item.

Return value

array Return AvaTax formatted response.

Overrides AvataxLib::resolveAddress

File

tests/modules/commerce_avatax_test/src/AvataxLibTest.php, line 16

Class

AvataxLibTest
Decorates `commerce_avatax.avatax_lib` for testing.

Namespace

Drupal\commerce_avatax_test

Code

public function resolveAddress(array $address) {

  // Irvine.
  if ($address['locality'] === 'Irvine') {
    $file = drupal_get_path('module', 'commerce_avatax') . '/tests/fixtures/irvine.json';
    if ($address['administrative_area'] === 'C0' || $address['address_line1'] === '2000 Main Stree') {
      $file = drupal_get_path('module', 'commerce_avatax') . '/tests/fixtures/irvine_suggestion.json';
    }
    if ($address['address_line1'] === '20000 Main Street') {
      $file = drupal_get_path('module', 'commerce_avatax') . '/tests/fixtures/irvine_error.json';
    }
  }
  else {
    $file = drupal_get_path('module', 'commerce_avatax') . '/tests/fixtures/durham.json';
    if ($address['address_line1'] === '512 S Mangu' || $address['postal_code'] === '27001') {
      $file = drupal_get_path('module', 'commerce_avatax') . '/tests/fixtures/durham_suggestion.json';
    }
  }
  $response_body = Json::decode(file_get_contents($file));

  // In fixtures we have address which are fixed. We need to replace
  // address array which represents what we are sending, so that
  // mockup response could be valid.
  $response_body['address'] = [
    'line1' => $address['address_line1'],
    'line2' => $address['address_line2'],
    'city' => $address['locality'],
    'region' => $address['administrative_area'],
    'country' => $address['country_code'],
    'postalCode' => $address['postal_code'],
  ];
  return $response_body;
}