You are here

protected function SubscriptionTest::setUp in Commerce Recurring Framework 8

Overrides CommerceBrowserTestBase::setUp

File

tests/src/Functional/SubscriptionTest.php, line 89

Class

SubscriptionTest
Tests the subscription UI.

Namespace

Drupal\Tests\commerce_recurring\Functional

Code

protected function setUp() : void {
  parent::setUp();
  $this->variation = $this
    ->createEntity('commerce_product_variation', [
    'type' => 'default',
    'sku' => strtolower($this
      ->randomMachineName()),
    'price' => [
      'number' => '39.99',
      'currency_code' => 'USD',
    ],
  ]);
  $this
    ->createEntity('commerce_product', [
    'type' => 'default',
    'title' => 'My product',
    'variations' => [
      $this->variation,
    ],
    'stores' => [
      $this->store,
    ],
  ]);

  /** @var \Drupal\commerce_recurring\Entity\BillingScheduleInterface $billing_schedule */
  $this->billingSchedule = $this
    ->createEntity('commerce_billing_schedule', [
    'id' => 'test_id',
    'label' => 'Hourly schedule',
    'displayLabel' => 'Hourly schedule',
    'billingType' => BillingSchedule::BILLING_TYPE_POSTPAID,
    'plugin' => 'fixed',
    'configuration' => [
      'interval' => [
        'number' => '1',
        'unit' => 'hour',
      ],
    ],
  ]);
  $profile = Profile::create([
    'type' => 'customer',
    'address' => [
      'country_code' => 'US',
    ],
  ]);
  $profile
    ->save();
  $this->billingProfile = $this
    ->reloadEntity($profile);

  /** @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',
    'card_number' => 1,
    'uid' => $this->adminUser
      ->id(),
    'billing_profile' => $this->billingProfile,
  ]);
  $payment_method
    ->save();
  $this->paymentMethod = $this
    ->reloadEntity($payment_method);
  $this->dateFormat = DateFormat::load('html_date')
    ->getPattern();
  $this->timeFormat = DateFormat::load('html_time')
    ->getPattern();
  $this->recurringOrderManager = $this->container
    ->get('commerce_recurring.order_manager');
}