You are here

protected function CheckoutAddressbookTest::setUp in Drupal Commerce Connector for AvaTax 8

Overrides CommerceWebDriverTestBase::setUp

File

tests/src/FunctionalJavascript/CheckoutAddressbookTest.php, line 67

Class

CheckoutAddressbookTest
Tests the address.

Namespace

Drupal\Tests\commerce_avatax\FunctionalJavascript

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->placeBlock('commerce_cart');
  $this
    ->placeBlock('commerce_checkout_progress');
  $variation = $this
    ->createEntity('commerce_product_variation', [
    'type' => 'default',
    'sku' => strtolower($this
      ->randomMachineName()),
    'price' => [
      'number' => 9.99,
      'currency_code' => 'USD',
    ],
  ]);

  /** @var \Drupal\commerce_product\Entity\ProductInterface $product */
  $this->product = $this
    ->createEntity('commerce_product', [
    'type' => 'default',
    'title' => 'My product',
    'variations' => [
      $variation,
    ],
    'stores' => [
      $this->store,
    ],
  ]);
  $this
    ->config('commerce_avatax.settings')
    ->setData([
    'api_mode' => 'development',
    'account_id' => 'test',
    'company_code' => 'DEFAULT',
    'customer_code_field' => 'mail',
    'disable_commit' => FALSE,
    'disable_tax_calculation' => FALSE,
    'license_key' => 'test',
    'logging' => FALSE,
    'shipping_tax_code' => 'FR020100',
    'address_validation' => [
      'enable' => TRUE,
      'countries' => [
        'US' => 'US',
        'CA' => 'CA',
      ],
      'postal_code_match' => TRUE,
    ],
  ])
    ->save();

  /** @var \Drupal\commerce_payment\Entity\PaymentGateway $gateway */
  $gateway = PaymentGateway::create([
    'id' => 'manual',
    'label' => 'Manual',
    'plugin' => 'manual',
  ]);
  $gateway
    ->save();
  $order_type = OrderType::load('default');
  $order_type
    ->setThirdPartySetting('commerce_checkout', 'checkout_flow', 'shipping');
  $order_type
    ->setThirdPartySetting('commerce_shipping', 'shipment_type', 'default');
  $order_type
    ->save();

  // Create the order field.
  $field_definition = commerce_shipping_build_shipment_field_definition($order_type
    ->id());
  $this->container
    ->get('commerce.configurable_field_manager')
    ->createField($field_definition);

  // Install the variation trait.
  $trait_manager = $this->container
    ->get('plugin.manager.commerce_entity_trait');
  $trait = $trait_manager
    ->createInstance('purchasable_entity_shippable');
  $trait_manager
    ->installTrait($trait, 'commerce_product_variation', 'default');

  /** @var \Drupal\commerce_shipping\Entity\PackageType $package_type */
  $package_type = $this
    ->createEntity('commerce_package_type', [
    'id' => 'package_type_a',
    'label' => 'Package Type A',
    'dimensions' => [
      'length' => 20,
      'width' => 20,
      'height' => 20,
      'unit' => 'mm',
    ],
    'weight' => [
      'number' => 20,
      'unit' => 'g',
    ],
  ]);
  $this->container
    ->get('plugin.manager.commerce_package_type')
    ->clearCachedDefinitions();
  $this
    ->createEntity('commerce_shipping_method', [
    'name' => 'Standard shipping',
    'stores' => [
      $this->store
        ->id(),
    ],
    'plugin' => [
      'target_plugin_id' => 'flat_rate',
      'target_plugin_configuration' => [
        'rate_label' => 'Standard shipping',
        'rate_amount' => [
          'number' => '9.99',
          'currency_code' => 'USD',
        ],
      ],
    ],
  ]);
}