SalesforceAdminSettingsTest.php in Salesforce Suite 8.3
File
src/Tests/SalesforceAdminSettingsTest.php
View source
<?php
namespace Drupal\salesforce\Tests;
use Drupal\simpletest\WebTestBase;
class SalesforceAdminSettingsTest extends WebTestBase {
protected static $modules = [
'salesforce',
'user',
'salesforce_test_rest_client',
];
protected $normalUser;
protected $adminSalesforceUser;
public function setUp() {
parent::setUp();
$this->adminSalesforceUser = $this
->drupalCreateUser([
'administer salesforce',
'authorize salesforce',
]);
}
public function testAdminSettings() {
global $base_url;
$this
->drupalLogin($this->adminSalesforceUser);
$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);
$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']);
$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'));
}
public function testOauthCallback() {
$this
->drupalLogin($this->adminSalesforceUser);
$code = $this
->randomMachineName();
$this->maximumRedirects = 0;
$this
->drupalHead('salesforce/oauth_callback', [
'query' => [
'code' => $code,
],
]);
$this
->assertTrue(strstr($this
->drupalGetHeader('location'), 'admin/config/salesforce/authorize'));
}
}