You are here

AvataxLibTest.php in Drupal Commerce Connector for AvaTax 8

File

tests/modules/commerce_avatax_test/src/AvataxLibTest.php
View source
<?php

namespace Drupal\commerce_avatax_test;

use Drupal\commerce_avatax\AvataxLib;
use Drupal\Component\Serialization\Json;

/**
 * Decorates `commerce_avatax.avatax_lib` for testing.
 */
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;
  }

}

Classes

Namesort descending Description
AvataxLibTest Decorates `commerce_avatax.avatax_lib` for testing.