You are here

class AvataxLibTest in Drupal Commerce Connector for AvaTax 8

Decorates `commerce_avatax.avatax_lib` for testing.

Hierarchy

Expanded class hierarchy of AvataxLibTest

1 string reference to 'AvataxLibTest'
commerce_avatax_test.services.yml in tests/modules/commerce_avatax_test/commerce_avatax_test.services.yml
tests/modules/commerce_avatax_test/commerce_avatax_test.services.yml
1 service uses AvataxLibTest
commerce_avatax_test.avatax_lib in tests/modules/commerce_avatax_test/commerce_avatax_test.services.yml
Drupal\commerce_avatax_test\AvataxLibTest

File

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

Namespace

Drupal\commerce_avatax_test
View source
class AvataxLibTest extends AvataxLib {

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AvataxLib::$adjustmentTypeManager protected property The adjustment type manager.
AvataxLib::$cache protected property The cache backend.
AvataxLib::$chainTaxCodeResolver protected property The chain tax code resolver.
AvataxLib::$client protected property The client.
AvataxLib::$config protected property The AvaTax configuration.
AvataxLib::$eventDispatcher protected property The event dispatcher.
AvataxLib::$logger protected property The logger.
AvataxLib::$moduleHandler protected property The module handler.
AvataxLib::doRequest protected function Performs an HTTP request to AvaTax.
AvataxLib::formatAddress protected static function Formats an address for use in the order request.
AvataxLib::formatDrupalAddress public static function Format an address with AvaTax array data.
AvataxLib::prepareTransactionsCreate public function Prepares the transaction request body. (This method should not be public but that makes the tests easier). Overrides AvataxLibInterface::prepareTransactionsCreate
AvataxLib::resolveCustomerProfile protected function Resolves the customer profile for the given order item. Stolen from TaxTypeBase::resolveCustomerProfile().
AvataxLib::setClient public function Sets the http client.
AvataxLib::transactionsCreate public function Creates a new transaction (/api/v2/transactions/create). Overrides AvataxLibInterface::transactionsCreate
AvataxLib::transactionsVoid public function Voids a transaction for the given order. Overrides AvataxLibInterface::transactionsVoid
AvataxLib::validateAddress public function Validate the give address from Drupal upon AvaTax resolved address. Overrides AvataxLibInterface::validateAddress
AvataxLib::__construct public function Constructs a new AvataxLib object.
AvataxLibTest::resolveAddress public function Retrieve geolocation information for a specified address. Overrides AvataxLib::resolveAddress