You are here

public function OrderTest::testOrderEmail in Commerce Core 8.2

Tests that an order's email updates with the customer.

File

modules/order/tests/src/Kernel/Entity/OrderTest.php, line 374

Class

OrderTest
Tests the Order entity.

Namespace

Drupal\Tests\commerce_order\Kernel\Entity

Code

public function testOrderEmail() {
  $customer = $this
    ->createUser([
    'mail' => 'test@example.com',
  ]);
  $order_with_customer = Order::create([
    'type' => 'default',
    'state' => 'completed',
    'uid' => $customer,
  ]);
  $order_with_customer
    ->save();
  $this
    ->assertEquals($customer
    ->getEmail(), $order_with_customer
    ->getEmail());
  $order_without_customer = Order::create([
    'type' => 'default',
    'state' => 'completed',
  ]);
  $order_without_customer
    ->save();
  $this
    ->assertEquals('', $order_without_customer
    ->getEmail());
  $order_without_customer
    ->setCustomer($customer);
  $order_without_customer
    ->save();
  $this
    ->assertEquals($customer
    ->getEmail(), $order_without_customer
    ->getEmail());
}