You are here

public function SalesforceJwtTest::testJwtAuth in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 5.0.x modules/salesforce_jwt/tests/src/FunctionalJavascript/SalesforceJwtTest.php \Drupal\Tests\salesforce_jwt\FunctionalJavascript\SalesforceJwtTest::testJwtAuth()

Test adding a jwt provider plugin.

File

modules/salesforce_jwt/tests/src/FunctionalJavascript/SalesforceJwtTest.php, line 72

Class

SalesforceJwtTest
Test JWT Auth.

Namespace

Drupal\Tests\salesforce_jwt\FunctionalJavascript

Code

public function testJwtAuth() {
  $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('jwt');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $edit = [
    'provider_settings[consumer_key]' => 'foo',
    'provider_settings[login_user]' => 'bar',
    'provider_settings[login_url]' => 'https://login.salesforce.com',
    'provider_settings[encrypt_key]' => self::KEY_ID,
  ];
  foreach ($edit as $key => $value) {
    $assert_session
      ->fieldExists($key);
    $page
      ->fillField($key, $value);
  }
  $this
    ->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/sfjwt-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/sfjwt-2.png');
    $page
      ->pressButton('Save');
  }
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/sfjwt-3.png');
  $assert_session
    ->addressEquals('admin/config/salesforce/authorize/list');
  $assert_session
    ->pageTextContainsOnce($label);
  $assert_session
    ->pageTextContainsOnce('Authorized');
  $assert_session
    ->pageTextContainsOnce('Salesforce JWT OAuth');
}