public function ShippingTest::testApplyProportional in Commerce Shipping 8.2
@covers ::applyProportional
File
- tests/
src/ Kernel/ Plugin/ Commerce/ TaxType/ ShippingTest.php, line 316
Class
- ShippingTest
- Tests the shipping tax type.
Namespace
Drupal\Tests\commerce_shipping\Kernel\Plugin\Commerce\TaxTypeCode
public function testApplyProportional() {
$plugin = $this->taxType
->getPlugin();
$plugin
->setConfiguration([
'strategy' => 'proportional',
]);
/** @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(2, $tax_adjustments);
// The second and third order item represent 30% of the subtotal.
// That's (10 * 0.2 / 1.2) * 0.3 = 1.67.
$first_tax_adjustment = reset($tax_adjustments);
$this
->assertEquals('eu_vat|fr|standard', $first_tax_adjustment
->getSourceId());
$this
->assertEquals('VAT', $first_tax_adjustment
->getLabel());
$this
->assertEquals(new Price('0.5', 'USD'), $first_tax_adjustment
->getAmount());
$this
->assertEquals('0.2', $first_tax_adjustment
->getPercentage());
$this
->assertTrue($first_tax_adjustment
->isIncluded());
// The first order item represents 70% of the subtotal.
// That's (10 * 0.1 / 1.1) * 0.7 = 0.64.
$second_tax_adjustment = end($tax_adjustments);
$this
->assertEquals('eu_vat|fr|intermediate', $second_tax_adjustment
->getSourceId());
$this
->assertEquals('VAT', $second_tax_adjustment
->getLabel());
$this
->assertEquals(new Price('0.64', 'USD'), $second_tax_adjustment
->getAmount());
$this
->assertEquals('0.1', $second_tax_adjustment
->getPercentage());
$this
->assertTrue($second_tax_adjustment
->isIncluded());
}