You are here

protected function RecurringKernelTestBase::createInitialOrder in Commerce Recurring Framework 8

Creates an order with an order item that will start a subscription.

Parameters

bool $trial: Whether to enable a trial interval for the billing schedule. Defaults to FALSE.

Return value

\Drupal\commerce_order\Entity\OrderInterface A commerce order.

4 calls to RecurringKernelTestBase::createInitialOrder()
SubscriptionLifecycleTest::testLifecycle in tests/src/Kernel/SubscriptionLifecycleTest.php
Tests the subscription lifecycle, without a free trial.
SubscriptionLifecycleTest::testLifecycleWithTrial in tests/src/Kernel/SubscriptionLifecycleTest.php
Tests the subscription lifecycle, with a free trial.
SubscriptionLifecycleTest::testSubscriptionDelete in tests/src/Kernel/SubscriptionLifecycleTest.php
Tests the subscription deletion.
SubscriptionLifecycleTest::testSubscriptionUpdates in tests/src/Kernel/SubscriptionLifecycleTest.php
Tests that updating an active subscription also updates the current order.

File

tests/src/Kernel/RecurringKernelTestBase.php, line 158

Class

RecurringKernelTestBase
Provides a base class for Recurring kernel tests.

Namespace

Drupal\Tests\commerce_recurring\Kernel

Code

protected function createInitialOrder($trial = FALSE) {
  if (!$trial) {
    $configuration = $this->billingSchedule
      ->getPluginConfiguration();
    unset($configuration['trial_interval']);
    $this->billingSchedule
      ->setPluginConfiguration($configuration);
    $this->billingSchedule
      ->save();
  }
  $first_order_item = OrderItem::create([
    'type' => 'test',
    'title' => 'I promise not to start a subscription',
    'unit_price' => [
      'number' => '10.00',
      'currency_code' => 'USD',
    ],
    'quantity' => 1,
  ]);
  $first_order_item
    ->save();
  $second_order_item = OrderItem::create([
    'type' => 'default',
    'purchased_entity' => $this->variation,
    'unit_price' => [
      'number' => '2.00',
      'currency_code' => 'USD',
    ],
    'quantity' => '3',
  ]);
  $second_order_item
    ->save();
  $initial_order = Order::create([
    'type' => 'default',
    'store_id' => $this->store,
    'uid' => $this->user,
    'order_items' => [
      $first_order_item,
      $second_order_item,
    ],
    'state' => 'draft',
  ]);
  $initial_order
    ->save();
  return $initial_order;
}