You are here

protected function MolliePaymentOffsiteFormTest::setUp in Commerce Mollie 8

Overrides CommerceBrowserTestBase::setUp

File

tests/src/Functional/MolliePaymentOffsiteFormTest.php, line 58

Class

MolliePaymentOffsiteFormTest
Tests the checkout form that initializes a payment.

Namespace

Drupal\Tests\commerce_mollie\Functional

Code

protected function setUp() {
  parent::setUp();
  $this->orderStorage = \Drupal::entityTypeManager()
    ->getStorage('commerce_order');
  $this->paymentStorage = \Drupal::entityTypeManager()
    ->getStorage('commerce_payment');
  $variation = $this
    ->createEntity('commerce_product_variation', [
    'type' => 'default',
    'sku' => strtolower($this
      ->randomMachineName()),
    'price' => [
      'number' => '29.99',
      'currency_code' => 'USD',
    ],
  ]);

  /** @var \Drupal\commerce_product\Entity\ProductInterface $product */
  $this->product = $this
    ->createEntity('commerce_product', [
    'type' => 'default',
    'title' => 'My product',
    'variations' => [
      $variation,
    ],
    'stores' => [
      $this->store,
    ],
  ]);

  /** @var \Drupal\commerce_order\Entity\OrderType $order_type */
  $order_type = OrderType::load('default');
  $order_type
    ->setWorkflowId('order_default_validation');
  $order_type
    ->save();

  /** @var \Drupal\commerce_payment\Entity\PaymentGateway $gateway */
  $gateway = PaymentGateway::create([
    'id' => 'mollie_test_gateway',
    'label' => 'Mollie',
    'plugin' => 'mollie',
  ]);
  $gateway
    ->getPlugin()
    ->setConfiguration([
    'mode' => 'test',
    'api_key_test' => 'test_Dfm3kc8CNcFb34xHnxwNNEyAJTteez',
    'api_key_live' => 'live_key',
    'callback_domain' => 'https://molliedevelopment.localtunnel.me',
  ]);
  $gateway
    ->save();

  // Cheat so we don't need JS to interact w/ Address field widget.

  /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $customer_form_display */
  $customer_form_display = EntityFormDisplay::load('profile.customer.default');
  $address_component = $customer_form_display
    ->getComponent('address');
  $address_component['settings']['default_country'] = 'US';
  $customer_form_display
    ->setComponent('address', $address_component);
  $customer_form_display
    ->save();
}