You are here

protected function OrderRefreshTest::setUp in Commerce Core 8.2

Overrides OrderKernelTestBase::setUp

File

modules/order/tests/src/Kernel/OrderRefreshTest.php, line 72

Class

OrderRefreshTest
Tests the order refresh process.

Namespace

Drupal\Tests\commerce_order\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $user = $this
    ->createUser();
  $this->user = $this
    ->reloadEntity($user);
  $this->orderItemStorage = $this->container
    ->get('entity_type.manager')
    ->getStorage('commerce_order_item');

  // Turn off title generation to allow explicit values to be used.
  $variation_type = ProductVariationType::load('default');
  $variation_type
    ->setGenerateTitle(FALSE);
  $variation_type
    ->save();
  $product = Product::create([
    'type' => 'default',
    'title' => 'Default testing product',
  ]);
  $product
    ->save();
  $variation1 = ProductVariation::create([
    'type' => 'default',
    'sku' => 'TEST_' . strtolower($this
      ->randomMachineName()),
    'title' => $this
      ->randomString(),
    'status' => 0,
    'price' => new Price('2.00', 'USD'),
  ]);
  $variation1
    ->save();
  $product
    ->addVariation($variation1)
    ->save();
  $this->variation1 = $this
    ->reloadEntity($variation1);
  $variation2 = ProductVariation::create([
    'type' => 'default',
    'sku' => strtolower($this
      ->randomMachineName()),
    'title' => $this
      ->randomString(),
    'status' => 1,
    'price' => new Price('3.00', 'USD'),
  ]);
  $variation2
    ->save();
  $product
    ->addVariation($variation2)
    ->save();
  $this->variation2 = $this
    ->reloadEntity($variation2);
  $profile = Profile::create([
    'type' => 'customer',
  ]);
  $profile
    ->save();
  $profile = $this
    ->reloadEntity($profile);

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