You are here

protected function CheckoutAccessTest::createOrder in Commerce Core 8.2

Creates a sample order with one order item for provided user.

Parameters

\Drupal\user\UserInterface $user: The user.

Return value

\Drupal\commerce_order\Entity\OrderInterface The sample order.

4 calls to CheckoutAccessTest::createOrder()
CheckoutAccessTest::testAccessCheckoutPermission in modules/checkout/tests/src/Kernel/CheckoutAccessTest.php
Tests that users need the `access checkout` permission.
CheckoutAccessTest::testCanceledOrderCheckout in modules/checkout/tests/src/Kernel/CheckoutAccessTest.php
Tests that canceled orders cannot enter checkout.
CheckoutAccessTest::testOrderMustHaveItems in modules/checkout/tests/src/Kernel/CheckoutAccessTest.php
Tests that an order must have items to enter checkout.
CheckoutAccessTest::testOwnerCheckoutAccess in modules/checkout/tests/src/Kernel/CheckoutAccessTest.php
Tests that only the order's owner can view its checkout.

File

modules/checkout/tests/src/Kernel/CheckoutAccessTest.php, line 184

Class

CheckoutAccessTest
Tests the checkout access for orders.

Namespace

Drupal\Tests\commerce_checkout\Kernel

Code

protected function createOrder(UserInterface $user) {

  /** @var \Drupal\commerce_order\Entity\Order $order */
  $order = Order::create([
    'type' => 'default',
    'state' => 'draft',
    'mail' => $user
      ->getEmail(),
    'uid' => $user
      ->id(),
    'ip_address' => '127.0.0.1',
    'order_number' => '6',
    'store_id' => $this->store
      ->id(),
  ]);
  $order_item = $this->orderItemStorage
    ->createFromPurchasableEntity($this->variation);
  $order_item
    ->save();
  $order
    ->addItem($order_item);
  $order
    ->save();
  return $order;
}