public function ShippingTest::testApplyDefault in Commerce Shipping 8.2
@covers ::applyDefault
File
- tests/
src/ Kernel/ Plugin/ Commerce/ TaxType/ ShippingTest.php, line 237
Class
- ShippingTest
- Tests the shipping tax type.
Namespace
Drupal\Tests\commerce_shipping\Kernel\Plugin\Commerce\TaxTypeCode
public function testApplyDefault() {
$plugin = $this->taxType
->getPlugin();
/** @var \Drupal\commerce_shipping\Entity\ShipmentInterface[] $shipments */
$shipments = $this->order
->get('shipments')
->referencedEntities();
$shipment = reset($shipments);
$plugin
->apply($this->order);
$tax_adjustments = $shipment
->getAdjustments([
'tax',
]);
$this
->assertCount(1, $tax_adjustments);
$tax_adjustment = reset($tax_adjustments);
$this
->assertEquals('eu_vat|fr|standard', $tax_adjustment
->getSourceId());
$this
->assertEquals('VAT', $tax_adjustment
->getLabel());
$this
->assertEquals(new Price('1.67', 'USD'), $tax_adjustment
->getAmount());
$this
->assertEquals('0.2', $tax_adjustment
->getPercentage());
$this
->assertTrue($tax_adjustment
->isIncluded());
// Leave only the order item which uses the "intermediate" rate.
$order_items = $this->order
->getItems();
$second_order_item = reset($order_items);
$this->order
->setItems([
$second_order_item,
]);
/** @var \Drupal\commerce_shipping\Entity\ShipmentInterface $shipment */
$shipment = $this
->reloadEntity($shipment);
$plugin
->apply($this->order);
$tax_adjustments = $shipment
->getAdjustments([
'tax',
]);
$this
->assertCount(1, $tax_adjustments);
$tax_adjustment = reset($tax_adjustments);
// Confirm that the default rate is still used.
$this
->assertEquals('eu_vat|fr|standard', $tax_adjustment
->getSourceId());
}