public function OrderTotalSummaryTest::testWithOrderAdjustments in Commerce Core 8.2
Tests the order total summary with order adjustments.
File
- modules/
order/ tests/ src/ Kernel/ OrderTotalSummaryTest.php, line 104
Class
- OrderTotalSummaryTest
- Tests the order total summary.
Namespace
Drupal\Tests\commerce_order\KernelCode
public function testWithOrderAdjustments() {
/** @var \Drupal\commerce_order\Entity\OrderItemInterface $order_item */
$order_item = OrderItem::create([
'type' => 'default',
'quantity' => 1,
'unit_price' => new Price('12.00', 'USD'),
]);
$order_item
->save();
$order_item = $this
->reloadEntity($order_item);
$this->order
->addItem($order_item);
$this->order
->addAdjustment(new Adjustment([
'type' => 'promotion',
'label' => 'Back to school discount',
'amount' => new Price('-5.00', 'USD'),
'percentage' => '0.1',
'source_id' => '1',
]));
$this->order
->save();
$totals = $this->orderTotalSummary
->buildTotals($this->order);
$this
->assertEquals(new Price('12.00', 'USD'), $totals['subtotal']);
$this
->assertEquals(new Price('7.00', 'USD'), $totals['total']);
$this
->assertCount(1, $totals['adjustments']);
$first = array_shift($totals['adjustments']);
$this
->assertEquals('promotion', $first['type']);
$this
->assertEquals('Back to school discount', $first['label']);
$this
->assertEquals(new Price('-5', 'USD'), $first['amount']);
$this
->assertEquals('0.1', $first['percentage']);
}