You are here

public function TaxTypePluginTest::testApply in Drupal Commerce Connector for AvaTax 8

Tests applying.

File

tests/src/Kernel/TaxTypePluginTest.php, line 184

Class

TaxTypePluginTest
Tests the tax type plugin.

Namespace

Drupal\Tests\commerce_avatax\Kernel

Code

public function testApply() {
  list($order_item) = $this->order
    ->getItems();
  $this
    ->mockResponse([
    new Response(200, [], Json::encode([
      'lines' => [
        [
          'lineNumber' => $order_item
            ->uuid(),
          'tax' => 5.25,
          'details' => [
            [
              'taxName' => 'CA STATE TAX',
            ],
          ],
        ],
      ],
    ])),
  ]);
  $plugin = $this->taxType
    ->getPlugin();
  $this
    ->assertTrue($plugin
    ->applies($this->order));
  $plugin
    ->apply($this->order);
  $adjustments = $this->order
    ->collectAdjustments();
  $this
    ->assertCount(1, $adjustments);
  $adjustment = reset($adjustments);
  $this
    ->assertEquals('tax', $adjustment
    ->getType());
  $this
    ->assertEquals('CA STATE TAX', $adjustment
    ->getLabel());
  $this
    ->assertEquals('avatax|avatax', $adjustment
    ->getSourceId());
  $this
    ->assertEquals(new Price('5.25', 'USD'), $adjustment
    ->getAmount());

  // Disable the tax calculation and ensure the tax type plugin no longer
  // applies.
  $this
    ->config(self::CONFIG_NAME)
    ->set('disable_tax_calculation', TRUE)
    ->save();
  $this
    ->assertFalse($plugin
    ->applies($this->order));
}