You are here

protected function RecurringKernelTestBase::setUp in Commerce Recurring Framework 8

Overrides OrderKernelTestBase::setUp

12 calls to RecurringKernelTestBase::setUp()
BillingScheduleAccessTest::setUp in tests/src/Kernel/BillingScheduleAccessTest.php
CronTest::setUp in tests/src/Kernel/CronTest.php
OrderRefreshTest::setUp in tests/src/Kernel/OrderRefreshTest.php
PaymentDeclinedMailTest::setUp in tests/src/Kernel/Mail/PaymentDeclinedMailTest.php
ProportionalTest::setUp in tests/src/Kernel/Plugin/Commerce/Prorater/ProportionalTest.php

... See full list

12 methods override RecurringKernelTestBase::setUp()
BillingScheduleAccessTest::setUp in tests/src/Kernel/BillingScheduleAccessTest.php
CronTest::setUp in tests/src/Kernel/CronTest.php
OrderRefreshTest::setUp in tests/src/Kernel/OrderRefreshTest.php
PaymentDeclinedMailTest::setUp in tests/src/Kernel/Mail/PaymentDeclinedMailTest.php
ProportionalTest::setUp in tests/src/Kernel/Plugin/Commerce/Prorater/ProportionalTest.php

... See full list

File

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

Class

RecurringKernelTestBase
Provides a base class for Recurring kernel tests.

Namespace

Drupal\Tests\commerce_recurring\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installEntitySchema('commerce_payment');
  $this
    ->installEntitySchema('commerce_payment_method');
  $this
    ->installEntitySchema('commerce_subscription');
  $this
    ->installEntitySchema('user');
  $this
    ->installSchema('advancedqueue', 'advancedqueue');
  $this
    ->installConfig('entity');
  $this
    ->installConfig('commerce_recurring');
  $user = $this
    ->createUser();
  $this->user = $this
    ->reloadEntity($user);

  /** @var \Drupal\commerce_recurring\Entity\BillingScheduleInterface $billing_schedule */
  $billing_schedule = BillingSchedule::create([
    'id' => 'test_id',
    'label' => 'Monthly schedule',
    'displayLabel' => 'Monthly schedule',
    'billingType' => BillingSchedule::BILLING_TYPE_POSTPAID,
    'plugin' => 'fixed',
    'configuration' => [
      'trial_interval' => [
        'number' => '10',
        'unit' => 'day',
      ],
      'interval' => [
        'number' => '1',
        'unit' => 'month',
      ],
    ],
  ]);
  $billing_schedule
    ->save();
  $this->billingSchedule = $this
    ->reloadEntity($billing_schedule);

  /** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $payment_gateway */
  $payment_gateway = PaymentGateway::create([
    'id' => 'example',
    'label' => 'Example',
    'plugin' => 'example_onsite',
  ]);
  $payment_gateway
    ->save();
  $this->paymentGateway = $this
    ->reloadEntity($payment_gateway);

  /** @var \Drupal\commerce_payment\Entity\PaymentMethodInterface $payment_method */
  $payment_method = PaymentMethod::create([
    'type' => 'credit_card',
    'payment_gateway' => $this->paymentGateway,
    'card_type' => 'visa',
    'uid' => $this->user
      ->id(),
  ]);
  $payment_method
    ->save();
  $this->paymentMethod = $this
    ->reloadEntity($payment_method);

  /** @var \Drupal\commerce_product\Entity\ProductVariationTypeInterface $product_variation_type */
  $product_variation_type = ProductVariationType::load('default');
  $product_variation_type
    ->setGenerateTitle(FALSE);
  $product_variation_type
    ->save();

  // Install the variation trait.
  $trait_manager = \Drupal::service('plugin.manager.commerce_entity_trait');
  $trait = $trait_manager
    ->createInstance('purchasable_entity_subscription');
  $trait_manager
    ->installTrait($trait, 'commerce_product_variation', 'default');
  $variation = ProductVariation::create([
    'type' => 'default',
    'title' => $this
      ->randomMachineName(),
    'sku' => strtolower($this
      ->randomMachineName()),
    'price' => [
      'number' => '10.00',
      'currency_code' => 'USD',
    ],
    'billing_schedule' => $this->billingSchedule,
    'subscription_type' => [
      'target_plugin_id' => 'product_variation',
    ],
  ]);
  $variation
    ->save();
  $this->variation = $this
    ->reloadEntity($variation);
}