public function AdjustmentTransformerTest::testCombining in Commerce Core 8.2
Tests adjustment combining.
@covers ::combineAdjustments
File
- modules/
order/ tests/ src/ Kernel/ AdjustmentTransformerTest.php, line 38
Class
- AdjustmentTransformerTest
- Tests the adjustment transformer.
Namespace
Drupal\Tests\commerce_order\KernelCode
public function testCombining() {
$adjustments = [];
// Adjustments 0 and 2 are supposed to be combined.
$adjustments[0] = new Adjustment([
'type' => 'tax',
'label' => 'VAT',
'amount' => new Price('10', 'USD'),
'source_id' => 'us_vat|default|standard',
'percentage' => '0.1',
]);
$adjustments[1] = new Adjustment([
'type' => 'promotion',
'label' => '20% off',
'amount' => new Price('20', 'USD'),
'percentage' => '0.2',
]);
$adjustments[2] = new Adjustment([
'type' => 'tax',
'label' => 'VAT',
'amount' => new Price('3', 'USD'),
'source_id' => 'us_vat|default|standard',
'percentage' => '0.1',
]);
$adjustments[3] = new Adjustment([
'type' => 'tax',
'label' => 'VAT',
'amount' => new Price('4', 'USD'),
'source_id' => 'us_vat|default|reduced',
'percentage' => '0.1',
]);
$combined_adjustments = [];
$combined_adjustments[0] = new Adjustment([
'type' => 'tax',
'label' => 'VAT',
'amount' => new Price('13', 'USD'),
'source_id' => 'us_vat|default|standard',
'percentage' => '0.1',
]);
$combined_adjustments[1] = new Adjustment([
'type' => 'promotion',
'label' => '20% off',
'amount' => new Price('20', 'USD'),
'percentage' => '0.2',
]);
$combined_adjustments[2] = new Adjustment([
'type' => 'tax',
'label' => 'VAT',
'amount' => new Price('4', 'USD'),
'source_id' => 'us_vat|default|reduced',
'percentage' => '0.1',
]);
$result = $this->adjustmentTransformer
->combineAdjustments($adjustments);
$this
->assertCount(3, $result);
$this
->assertEquals($combined_adjustments, $result);
}