You are here

public function ChainTaxCodeResolverTest::testProductVariationTaxCodeResolver in Drupal Commerce Connector for AvaTax 8

Tests the product variation tax code resolver.

File

tests/src/Kernel/ChainTaxCodeResolverTest.php, line 50

Class

ChainTaxCodeResolverTest
Tests the chain tax code resolver.

Namespace

Drupal\Tests\commerce_avatax\Kernel

Code

public function testProductVariationTaxCodeResolver() {
  $variation1 = ProductVariation::create([
    'type' => 'default',
    'sku' => 'TEST_' . strtolower($this
      ->randomMachineName()),
    'title' => $this
      ->randomString(),
    'status' => 1,
    'price' => new Price('12.00', 'USD'),
    'avatax_tax_code' => 'TESTCODE123',
  ]);
  $order_item = OrderItem::create([
    'type' => 'default',
    'quantity' => 1,
    'purchased_entity' => $variation1,
  ]);
  $resolved_code = $this->container
    ->get('commerce_avatax.chain_tax_code_resolver')
    ->resolve($order_item);
  $this
    ->assertEquals('TESTCODE123', $resolved_code);
  $variation2 = ProductVariation::create([
    'type' => 'default',
    'sku' => 'TEST_' . strtolower($this
      ->randomMachineName()),
    'title' => $this
      ->randomString(),
    'status' => 1,
    'price' => new Price('12.00', 'USD'),
  ]);
  $order_item = OrderItem::create([
    'type' => 'default',
    'quantity' => 1,
    'purchased_entity' => $variation2,
  ]);
  $resolved_code = $this->container
    ->get('commerce_avatax.chain_tax_code_resolver')
    ->resolve($order_item);
  $this
    ->assertEquals(NULL, $resolved_code);
}