You are here

public function StoreTaxTest::testDefaultRates in Commerce Core 8.2

@covers ::getDefaultRates

File

modules/tax/tests/src/Kernel/StoreTaxTest.php, line 142

Class

StoreTaxTest
@coversDefaultClass \Drupal\commerce_tax\StoreTax @group commerce

Namespace

Drupal\Tests\commerce_tax\Kernel

Code

public function testDefaultRates() {
  $order_item = OrderItem::create([
    'type' => 'test',
    'quantity' => '1',
    'unit_price' => new Price('12.00', 'USD'),
  ]);
  $order_item
    ->save();
  $this->order
    ->addItem($order_item);
  $this->order
    ->save();
  $rates = $this->storeTax
    ->getDefaultRates($this->store, $order_item);
  $this
    ->assertCount(1, $rates);
  $this
    ->assertArrayHasKey('fr', $rates);
  $rate = reset($rates);
  $this
    ->assertEquals('standard', $rate
    ->getId());

  // Confirm that the commerce_tax_test TaxRateResolver is called.
  $order_item
    ->setQuantity('30');
  $order_item
    ->save();
  $rates = $this->storeTax
    ->getDefaultRates($this->store, $order_item);
  $this
    ->assertCount(1, $rates);
  $this
    ->assertArrayHasKey('fr', $rates);
  $rate = reset($rates);
  $this
    ->assertEquals('reduced', $rate
    ->getId());

  // Confirm that no rates are returned when no tax types apply.
  $second_store = $this
    ->createStore('Second store', 'admin2@example.com', 'online', FALSE, 'US');
  $rates = $this->storeTax
    ->getDefaultRates($second_store, $order_item);
  $this
    ->assertCount(0, $rates);
}