You are here

protected function CheckoutTest::setUp in Commerce Authorize.Net 8

Overrides CommerceWebDriverTestBase::setUp

File

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

Class

CheckoutTest
Tests the Authorize.net payment configuration form.

Namespace

Drupal\Tests\commerce_authnet\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,
    ],
  ]);

  /** @var \Drupal\commerce_payment\Entity\PaymentGateway $gateway */
  $gateway = PaymentGateway::create([
    'id' => 'authorize_net_us',
    'label' => 'Authorize.net US',
    'plugin' => 'authorizenet_acceptjs',
  ]);
  $gateway
    ->getPlugin()
    ->setConfiguration([
    'api_login' => '5KP3u95bQpv',
    'transaction_key' => '346HZ32z3fP4hTG2',
    'mode' => 'test',
    'payment_method_types' => [
      'credit_card',
    ],
    'client_key' => 'test-client-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();
}