You are here

protected function CheckoutTest::setUp in Commerce Stripe 8

Overrides CommerceWebDriverTestBase::setUp

File

tests/src/FunctionalJavascript/CheckoutTest.php, line 46

Class

CheckoutTest
Tests checkout with Stripe.

Namespace

Drupal\Tests\commerce_stripe\FunctionalJavascript

Code

protected function setUp() : void {
  parent::setUp();
  $variation = $this
    ->createEntity('commerce_product_variation', [
    'type' => 'default',
    'sku' => strtolower($this
      ->randomMachineName()),
    'price' => [
      'number' => '9.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
        ->id(),
    ],
  ]);
  $gateway = PaymentGateway::create([
    'id' => 'stripe_testing',
    'label' => 'Stripe',
    'plugin' => 'stripe',
    'configuration' => [
      'payment_method_types' => [
        'credit_card',
      ],
      'publishable_key' => StripeIntegrationTestBase::TEST_PUBLISHABLE_KEY,
      'secret_key' => StripeIntegrationTestBase::TEST_SECRET_KEY,
    ],
  ]);
  $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();
  $this
    ->drupalLogout();
}