You are here

protected function DefaultPaymentAdminTest::setUp in Commerce Core 8.2

Overrides CommerceBrowserTestBase::setUp

File

modules/payment/tests/src/Functional/DefaultPaymentAdminTest.php, line 70

Class

DefaultPaymentAdminTest
Tests the admin UI for payments of type 'payment_default'.

Namespace

Drupal\Tests\commerce_payment\Functional

Code

protected function setUp() : void {
  parent::setUp();
  $profile = $this
    ->createEntity('profile', [
    'type' => 'customer',
    'address' => [
      'country_code' => 'US',
      'postal_code' => '53177',
      'locality' => 'Milwaukee',
      'address_line1' => 'Pabst Blue Ribbon Dr',
      'administrative_area' => 'WI',
      'given_name' => 'Frederick',
      'family_name' => 'Pabst',
    ],
    'uid' => $this->adminUser
      ->id(),
  ]);
  $this->paymentGateway = $this
    ->createEntity('commerce_payment_gateway', [
    'id' => 'example',
    'label' => 'Example',
    'plugin' => 'example_onsite',
  ]);
  $this->paymentMethod = $this
    ->createEntity('commerce_payment_method', [
    'uid' => $this->loggedInUser
      ->id(),
    'type' => 'credit_card',
    'payment_gateway' => 'example',
    'billing_profile' => $profile,
  ]);
  $details = [
    'type' => 'visa',
    'number' => '4111111111111111',
    'expiration' => [
      'month' => '01',
      'year' => date('Y') + 1,
    ],
  ];
  $this->paymentGateway
    ->getPlugin()
    ->createPaymentMethod($this->paymentMethod, $details);

  // An order item type that doesn't need a purchasable entity, for simplicity.
  OrderItemType::create([
    'id' => 'test',
    'label' => 'Test',
    'orderType' => 'default',
  ])
    ->save();
  $order_item = $this
    ->createEntity('commerce_order_item', [
    'type' => 'test',
    'quantity' => 1,
    'unit_price' => new Price('10', 'USD'),
  ]);
  $this->order = $this
    ->createEntity('commerce_order', [
    'uid' => $this->loggedInUser
      ->id(),
    'type' => 'default',
    'state' => 'draft',
    'order_items' => [
      $order_item,
    ],
    'store_id' => $this->store,
  ]);
  $this->paymentUri = Url::fromRoute('entity.commerce_payment.collection', [
    'commerce_order' => $this->order
      ->id(),
  ])
    ->toString();
}