View source
<?php
namespace Drupal\salesforce_mapping\Tests;
use Drupal\simpletest\WebTestBase;
class SalesforceMappingCrudFormTest extends WebTestBase {
protected static $modules = [
'salesforce',
'salesforce_test_rest_client',
'salesforce_mapping',
'user',
'link',
'dynamic_entity_reference',
];
protected $normalUser;
protected $adminSalesforceUser;
public function setUp() {
parent::setUp();
$this->adminSalesforceUser = $this
->drupalCreateUser([
'administer salesforce mapping',
]);
}
public function testMappingCrudForm() {
global $base_path;
$mappingStorage = \Drupal::entityTypeManager()
->getStorage('salesforce_mapping');
$this
->drupalLogin($this->adminSalesforceUser);
$mapping_name = 'mapping' . rand(100, 10000);
$post = [
'id' => $mapping_name,
'label' => $mapping_name,
'drupal_entity_type' => 'user',
'drupal_bundle' => 'user',
'salesforce_object_type' => 'Contact',
];
$this
->drupalPostForm('admin/structure/salesforce/mappings/add', $post, t('Save'));
$newurl = parse_url($this
->getUrl());
$this
->assertEqual($newurl['path'], $base_path . 'admin/structure/salesforce/mappings/manage/' . $mapping_name . '/fields');
$mapping = $mappingStorage
->load($mapping_name);
$this
->assertEqual($mapping
->id(), $mapping_name);
$this
->assertEqual($mapping
->label(), $mapping_name);
drupal_flush_all_caches();
$post = [
'label' => $this
->randomMachineName(),
'drupal_entity_type' => 'user',
'drupal_bundle' => 'user',
'salesforce_object_type' => 'Contact',
];
$this
->drupalPostForm('admin/structure/salesforce/mappings/manage/' . $mapping_name, $post, t('Save'));
$this
->assertFieldByName('label', $post['label']);
$mappingFieldsPluginManager = \Drupal::service('plugin.manager.salesforce_mapping_field');
$field_plugins = $mappingFieldsPluginManager
->getDefinitions();
foreach ($field_plugins as $definition) {
if (call_user_func([
$definition['class'],
'isAllowed',
], $mapping)) {
$post = [
'field_type' => $definition['id'],
];
$this
->drupalPostForm('admin/structure/salesforce/mappings/manage/' . $mapping_name . '/fields', $post, t('Add a field mapping to get started'));
}
}
}
}