You are here

public function InitialOrderProcessorTest::testPrepaidProcess in Commerce Recurring Framework 8

@covers ::process

File

tests/src/Kernel/InitialOrderProcessorTest.php, line 58

Class

InitialOrderProcessorTest
@coversDefaultClass \Drupal\commerce_recurring\InitialOrderProcessor @group commerce_recurring

Namespace

Drupal\Tests\commerce_recurring\Kernel

Code

public function testPrepaidProcess() {
  $configuration = $this->billingSchedule
    ->getPluginConfiguration();
  unset($configuration['trial_interval']);
  $this->billingSchedule
    ->setPluginConfiguration($configuration);
  $this->billingSchedule
    ->setBillingType(BillingSchedule::BILLING_TYPE_PREPAID);
  $this->billingSchedule
    ->save();
  $order_item = OrderItem::create([
    'type' => 'default',
    'title' => $this->variation
      ->getOrderItemTitle(),
    'purchased_entity' => $this->variation
      ->id(),
    'unit_price' => $this->variation
      ->getPrice(),
  ]);
  $order_item
    ->save();
  $order = Order::create([
    'type' => 'default',
    'store_id' => $this->store
      ->id(),
    'uid' => $this->user
      ->id(),
    'order_items' => [
      $order_item,
    ],
    'state' => 'draft',
  ]);
  $order
    ->save();

  /** @var \Drupal\commerce_order\Entity\OrderInterface $order */
  $order = $this
    ->reloadEntity($order);

  /** @var \Drupal\commerce_order\Entity\OrderItemInterface $order_item */
  $order_item = $this
    ->reloadEntity($order_item);
  $this
    ->assertEquals($this->variation
    ->getPrice(), $order_item
    ->getUnitPrice());
  $this
    ->assertNotEquals($order_item
    ->getUnitPrice(), $order_item
    ->getAdjustedUnitPrice());
  $adjustments = $order_item
    ->getAdjustments();
  $adjustment = reset($adjustments);
  $this
    ->assertEquals('subscription', $adjustment
    ->getType());
  $this
    ->assertEquals(t('Proration'), $adjustment
    ->getLabel());
}