SalesforceJwtTest.php in Salesforce Suite 8.4
File
modules/salesforce_jwt/tests/src/FunctionalJavascript/SalesforceJwtTest.php
View source
<?php
namespace Drupal\Tests\salesforce_jwt\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class SalesforceJwtTest extends WebDriverTestBase {
protected $defaultTheme = 'stark';
protected $testKey;
public static $modules = [
'key',
'typed_data',
'dynamic_entity_reference',
'salesforce',
'salesforce_test_rest_client',
'salesforce_jwt',
];
protected $adminUser;
const KEY_ID = 'salesforce_jwt_test_key';
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'authorize salesforce',
]);
$this
->drupalLogin($this->adminUser);
$this
->createTestKey(self::KEY_ID, 'authentication', 'file');
\Drupal\key\Entity\Key::load(self::KEY_ID)
->set('key_provider_settings', [
'file_location' => __DIR__ . '/testKey.pem',
'strip_line_breaks' => FALSE,
])
->save();
}
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');
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');
}
protected function createTestKey($id, $type = NULL, $provider = NULL) {
$keyArgs = [
'id' => $id,
'label' => 'Test key',
];
if ($type != NULL) {
$keyArgs['key_type'] = $type;
}
if ($provider != NULL) {
$keyArgs['key_provider'] = $provider;
}
$this->testKey = \Drupal\key\Entity\Key::create($keyArgs);
$this->testKey
->save();
return $this->testKey;
}
}