public function OrderLockingTest::testOrderConstraintValidation in Commerce Core 8.2
Tests order constraints are validated.
File
- modules/
order/ tests/ src/ Kernel/ OrderLockingTest.php, line 52
Class
- OrderLockingTest
- Tests order locking.
Namespace
Drupal\Tests\commerce_order\KernelCode
public function testOrderConstraintValidation() {
/** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$order = Order::create([
'type' => 'default',
'mail' => $this->user
->getEmail(),
'uid' => $this->user
->id(),
'store_id' => $this->store
->id(),
]);
$contraint_violations = $order
->validate()
->getEntityViolations();
$this
->assertEquals(0, $contraint_violations
->count());
$order
->save();
$this
->assertEquals(1, $order
->getVersion());
(function ($order_id) {
$order = Order::load($order_id);
assert($order instanceof OrderInterface);
$order
->addItem(OrderItem::create([
'type' => 'test',
'quantity' => 1,
'unit_price' => new Price('12.00', 'USD'),
]));
$order
->save();
$this
->assertEquals(2, $order
->getVersion());
})($order
->id());
$contraint_violations = $order
->validate()
->getEntityViolations();
$this
->assertEquals(1, $contraint_violations
->count());
$entity_constraint_violation = $contraint_violations
->get(0);
$this
->assertEquals('The order has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.', $entity_constraint_violation
->getMessage());
}