You are here

protected function OrderIntegrationTest::setUp in Commerce Core 8.2

Same name in this branch
  1. 8.2 modules/tax/tests/src/Kernel/OrderIntegrationTest.php \Drupal\Tests\commerce_tax\Kernel\OrderIntegrationTest::setUp()
  2. 8.2 modules/log/tests/src/Kernel/OrderIntegrationTest.php \Drupal\Tests\commerce_log\Kernel\OrderIntegrationTest::setUp()

Overrides OrderKernelTestBase::setUp

File

modules/log/tests/src/Kernel/OrderIntegrationTest.php, line 60

Class

OrderIntegrationTest
Tests integration with order events.

Namespace

Drupal\Tests\commerce_log\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installEntitySchema('commerce_log');
  $user = $this
    ->createUser([
    'mail' => $this
      ->randomString() . '@example.com',
  ]);
  $this->logStorage = $this->container
    ->get('entity_type.manager')
    ->getStorage('commerce_log');
  $this->logViewBuilder = $this->container
    ->get('entity_type.manager')
    ->getViewBuilder('commerce_log');

  // Change the workflow of the default order type.
  $order_type = OrderType::load('default');
  $order_type
    ->setWorkflowId('order_fulfillment_validation');
  $order_type
    ->save();

  // 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' => 1,
    'price' => new Price('12.00', 'USD'),
  ]);
  $variation1
    ->save();
  $product
    ->addVariation($variation1)
    ->save();
  $profile = Profile::create([
    'type' => 'customer',
  ]);
  $profile
    ->save();
  $profile = $this
    ->reloadEntity($profile);

  /** @var \Drupal\commerce_order\OrderItemStorageInterface $order_item_storage */
  $order_item_storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('commerce_order_item');
  $order_item1 = $order_item_storage
    ->createFromPurchasableEntity($variation1);
  $order_item1
    ->save();
  $order = Order::create([
    'type' => 'default',
    'store_id' => $this->store
      ->id(),
    'state' => 'draft',
    'mail' => $user
      ->getEmail(),
    'uid' => $user
      ->id(),
    'ip_address' => '127.0.0.1',
    'order_number' => '6',
    'billing_profile' => $profile,
    'order_items' => [
      $order_item1,
    ],
  ]);
  $order
    ->save();
  $this->order = $this
    ->reloadEntity($order);
}