You are here

public function ConfigureGatewayTest::testCreateSquareGateway in Commerce Square Connect 8

Tests that a Square gateway can be configured.

File

tests/src/FunctionalJavascript/ConfigureGatewayTest.php, line 39

Class

ConfigureGatewayTest
Tests the creation and configuration of the gateway.

Namespace

Drupal\Tests\commerce_square\FunctionalJavascript

Code

public function testCreateSquareGateway() {
  $this
    ->drupalGet(Url::fromRoute('commerce_square.settings'));
  $this
    ->getSession()
    ->getPage()
    ->fillField('Application Secret', 'fluff');
  $this
    ->getSession()
    ->getPage()
    ->fillField('Application Name', 'Drupal Commerce 2 Demo');
  $this
    ->getSession()
    ->getPage()
    ->fillField('Application ID', 'sq0idp-nV_lBSwvmfIEF62s09z0-Q');
  $this
    ->getSession()
    ->getPage()
    ->fillField('Sandbox Application ID', 'sandbox-sq0idb-RMT75dFT1toXdUNnW8Ahmw');
  $this
    ->getSession()
    ->getPage()
    ->fillField('Sandbox Access Token', 'EAAAEA3D3KIn2sjtYE0GjRPMJZPl4aigTyCyAhwojBAfWlr99jx4Wfz9GuCbzwfM');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Save configuration');
  $is_squareup = strpos($this
    ->getSession()
    ->getCurrentUrl(), 'squareup.com');
  $this
    ->assertNotFalse($is_squareup);
  $this
    ->drupalGet('admin/commerce/config/payment-gateways/add');
  $radio_button = $this
    ->getSession()
    ->getPage()
    ->findField('Square');
  $radio_button
    ->click();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // Populate the label / machine name first.
  $this
    ->getSession()
    ->getPage()
    ->fillField('label', 'Square');
  $this
    ->assertJsCondition('jQuery(".machine-name-value:visible").length > 0');
  $this
    ->getSession()
    ->getPage()
    ->fillField('configuration[square][test][test_location_id]', 'C9HQN1PSN4NKA');
  $this
    ->assertSession()
    ->fieldDisabled('configuration[square][live][live_location_id]');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Save');
  $this
    ->assertSession()
    ->responseContains(new FormattableMarkup('Saved the %label payment gateway.', [
    '%label' => 'Square',
  ]));
  $this
    ->drupalGet('admin/commerce/config/payment-gateways/manage/square');
  $radio_button = $this
    ->getSession()
    ->getPage()
    ->findField('Production');
  $radio_button
    ->click();
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Save');
  $this
    ->assertSession()
    ->pageTextContains('You must select a location for the configured mode.');
}