You are here

public function SalesforceAdminSettingsTest::testAdminSettings in Salesforce Suite 8.3

Tests webform admin settings.

File

src/Tests/SalesforceAdminSettingsTest.php, line 41

Class

SalesforceAdminSettingsTest
Tests for salesforce admin settings.

Namespace

Drupal\salesforce\Tests

Code

public function testAdminSettings() {
  global $base_url;
  $this
    ->drupalLogin($this->adminSalesforceUser);

  // Salesforce config.
  $config = \Drupal::config('salesforce.settings');
  $this
    ->assertNull($config
    ->get('consumer_key'));
  $this
    ->assertNull($config
    ->get('consumer_secret'));
  $this
    ->assertNull($config
    ->get('login_url'));
  $key = $this
    ->randomMachineName();
  $secret = rand(100000, 10000000);
  $url = 'https://login.salesforce.com';
  $post = [
    'consumer_key' => $key,
    'consumer_secret' => $secret,
    'login_url' => $url,
  ];
  $this
    ->drupalPostForm('admin/config/salesforce/authorize', $post, t('Save configuration'));
  $newurl = parse_url($this
    ->getUrl());
  $query = [];
  parse_str($newurl['query'], $query);

  // Check the redirect URL matches expectations:
  $this
    ->assertEqual($key, $query['client_id']);
  $this
    ->assertEqual('code', $query['response_type']);
  $this
    ->assertEqual(str_replace('http://', 'https://', $base_url) . '/salesforce/oauth_callback', $query['redirect_uri']);

  // Check that our config was updated:
  $config = \Drupal::config('salesforce.settings');
  $this
    ->assertEqual($key, $config
    ->get('consumer_key'));
  $this
    ->assertEqual($secret, $config
    ->get('consumer_secret'));
  $this
    ->assertEqual($url, $config
    ->get('login_url'));
}