public function AdjustmentItemTest::testAdjustmentItem in Commerce Core 8.2
Tests the adjustment item field defined by an array.
File
- modules/
order/ tests/ src/ Kernel/ AdjustmentItemTest.php, line 56
Class
- AdjustmentItemTest
- Tests the adjustment field.
Namespace
Drupal\Tests\commerce_order\KernelCode
public function testAdjustmentItem() {
/** @var \Drupal\Core\Field\FieldItemListInterface $adjustment_item_list */
$adjustment_item_list = $this->testEntity->test_adjustments;
$adjustment_item_list
->appendItem(new Adjustment([
'type' => 'custom',
'label' => '10% off',
'amount' => new Price('-1.00', 'USD'),
'percentage' => '0.1',
'source_id' => '1',
]));
/** @var \Drupal\commerce_order\Adjustment $adjustment */
$adjustment = $adjustment_item_list
->first()->value;
$this
->assertEquals('custom', $adjustment
->getType());
$this
->assertEquals('10% off', $adjustment
->getLabel());
$this
->assertEquals('-1.00', $adjustment
->getAmount()
->getNumber());
$this
->assertEquals('USD', $adjustment
->getAmount()
->getCurrencyCode());
$this
->assertEquals('1', $adjustment
->getSourceId());
}