You are here

public function SalesforceOAuthTest::testOAuth in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 5.0.x modules/salesforce_oauth/tests/src/FunctionalJavascript/SalesforceOAuthTest.php \Drupal\Tests\salesforce_oauth\FunctionalJavascript\SalesforceOAuthTest::testOAuth()

Test adding an oauth provider plugin.

File

modules/salesforce_oauth/tests/src/FunctionalJavascript/SalesforceOAuthTest.php, line 54

Class

SalesforceOAuthTest
Test OAuth.

Namespace

Drupal\Tests\salesforce_oauth\FunctionalJavascript

Code

public function testOAuth() {
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->drupalGet('admin/config/salesforce/authorize/add');
  $labelField = $page
    ->findField('label');
  $label = $this
    ->randomString();
  $labelField
    ->setValue($label);
  $page
    ->findField('provider')
    ->setValue('oauth');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $edit = [
    'provider_settings[consumer_key]' => 'foo',
    'provider_settings[consumer_secret]' => 'bar',
    'provider_settings[login_url]' => 'https://login.salesforce.com',
  ];
  foreach ($edit as $key => $value) {
    $assert_session
      ->fieldExists($key);
    $page
      ->fillField($key, $value);
  }
  $this
    ->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/sfoauth-1.png');
  $page
    ->pressButton('Save');

  // Weird behavior from testbot: machine name field doesn't seem to work
  // as expected. Machine name field doesn't appear until after clicking
  // "save", so we fill it and have to click save again. IDKWTF.
  if ($page
    ->findField('id')) {
    $page
      ->fillField('id', strtolower($this
      ->randomMachineName()));
    $this
      ->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/sfoauth-2.png');
    $page
      ->pressButton('Save');
  }
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/sfoauth-3.png');

  // We will have been redirected to a failed salesforce oauth page.
  $assert_session
    ->pageTextContainsOnce('error=invalid_client_id');
}