class SalesforceMappingTest in Salesforce Suite 8.4
Same name and namespace in other branches
- 8.3 modules/salesforce_mapping/tests/src/Unit/SalesforceMappingTest.php \Drupal\Tests\salesforce_mapping\Unit\SalesforceMappingTest
- 5.0.x modules/salesforce_mapping/tests/src/Unit/SalesforceMappingTest.php \Drupal\Tests\salesforce_mapping\Unit\SalesforceMappingTest
Test Object instantitation.
@group salesforce_mapping
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\salesforce_mapping\Unit\SalesforceMappingTest
Expanded class hierarchy of SalesforceMappingTest
File
- modules/
salesforce_mapping/ tests/ src/ Unit/ SalesforceMappingTest.php, line 22
Namespace
Drupal\Tests\salesforce_mapping\UnitView source
class SalesforceMappingTest extends UnitTestCase {
/**
* Required modules.
*
* @var array
*/
public static $modules = [
'salesforce_mapping',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->id = $this
->randomMachineName();
$this->saleforceObjectType = $this
->randomMachineName();
$this->drupalEntityTypeId = $this
->randomMachineName();
$this->drupalBundleId = $this
->randomMachineName();
$this->values = [
'id' => $this->id,
'langcode' => 'en',
'uuid' => '3bb9ee60-bea5-4622-b89b-a63319d10b3a',
'label' => 'Test Mapping',
'weight' => 0,
'type' => 'salesforce_mapping',
'key' => 'Drupal_id__c',
'async' => 1,
'pull_trigger_date' => 'LastModifiedDate',
'push_limit' => 0,
'push_frequency' => 0,
'pull_frequency' => 0,
'sync_triggers' => [
MappingConstants::SALESFORCE_MAPPING_SYNC_DRUPAL_CREATE => 1,
MappingConstants::SALESFORCE_MAPPING_SYNC_DRUPAL_UPDATE => 1,
MappingConstants::SALESFORCE_MAPPING_SYNC_DRUPAL_DELETE => 1,
MappingConstants::SALESFORCE_MAPPING_SYNC_SF_CREATE => 1,
MappingConstants::SALESFORCE_MAPPING_SYNC_SF_UPDATE => 1,
MappingConstants::SALESFORCE_MAPPING_SYNC_SF_DELETE => 1,
],
'salesforce_object_type' => $this->saleforceObjectType,
'drupal_entity_type' => $this->drupalEntityTypeId,
'drupal_bundle' => $this->drupalBundleId,
'field_mappings' => [
[
'drupal_field_type' => 'properties',
'drupal_field_value' => 'title',
'salesforce_field' => 'Name',
'direction' => 'sync',
],
[
'drupal_field_type' => 'properties',
'drupal_field_value' => 'nid',
'salesforce_field' => 'Drupal_id_c',
'direction' => 'sync',
],
],
];
// Mock EntityType Definition.
$this->entityTypeId = $this
->randomMachineName();
$this->provider = $this
->randomMachineName();
$prophecy = $this
->prophesize(ConfigEntityTypeInterface::CLASS);
$prophecy
->getProvider(Argument::any())
->willReturn($this->provider);
$prophecy
->getConfigPrefix(Argument::any())
->willReturn('test_provider.' . $this->entityTypeId);
$this->entityDefinition = $prophecy
->reveal();
// Mock EntityTypeManagerInterface.
$prophecy = $this
->prophesize(EntityTypeManagerInterface::CLASS);
$prophecy
->getDefinition($this->entityTypeId)
->willReturn($this->entityDefinition);
$this->etm = $prophecy
->reveal();
// Mock Properties SalesforceMappingField.
$prophecy = $this
->prophesize(Properties::CLASS);
$prophecy
->pull()
->willReturn(TRUE);
$sf_mapping_field = $prophecy
->reveal();
// Mode field plugin manager.
$prophecy = $this
->prophesize(SalesforceMappingFieldPluginManager::CLASS);
$prophecy
->createInstance(Argument::any(), Argument::any())
->willReturn($sf_mapping_field);
$field_manager = $prophecy
->reveal();
// Mock state.
$prophecy = $this
->prophesize(StateInterface::CLASS);
$prophecy
->get('salesforce.mapping_pull_info', Argument::any())
->willReturn([]);
$prophecy
->get('salesforce.mapping_push_info', Argument::any())
->willReturn([
$this->id => [
'last_timestamp' => 0,
],
]);
$prophecy
->set('salesforce.mapping_push_info', Argument::any())
->willReturn(NULL);
$this->state = $prophecy
->reveal();
$container = new ContainerBuilder();
$container
->set('state', $this->state);
\Drupal::setContainer($container);
$this->mapping = $this
->getMockBuilder(SalesforceMapping::CLASS)
->setMethods([
'fieldManager',
])
->setConstructorArgs([
$this->values,
$this->entityTypeId,
])
->getMock();
$this->mapping
->expects($this
->any())
->method('fieldManager')
->willReturn($field_manager);
}
/**
* Test object instantiation.
*/
public function testObject() {
$this
->assertTrue($this->mapping instanceof SalesforceMapping);
$this
->assertEquals($this->id, $this->mapping
->id());
}
/**
* Test getPullFields()
*/
public function testGetPullFields() {
$fields_array = $this->mapping
->getPullFields();
$this
->assertTrue(is_array($fields_array));
$this
->assertTrue($fields_array[0] instanceof Properties);
}
/**
* Test checkTriggers()
*/
public function testCheckTriggers() {
$triggers = $this->mapping
->checkTriggers([
MappingConstants::SALESFORCE_MAPPING_SYNC_DRUPAL_CREATE,
MappingConstants::SALESFORCE_MAPPING_SYNC_DRUPAL_UPDATE,
]);
$this
->assertTrue($triggers);
}
/**
* Test getPullQuery()
*/
public function testGetPullQuery() {
$start = strtotime('-5 minutes');
$stop = time();
$query = $this->mapping
->getPullQuery([], $start, $stop);
$expectedQuery = new SelectQuery($this->saleforceObjectType);
$expectedQuery
->addCondition($this->mapping
->getPullTriggerDate(), gmdate('Y-m-d\\TH:i:s\\Z', $start), '>');
$expectedQuery
->addCondition($this->mapping
->getPullTriggerDate(), gmdate('Y-m-d\\TH:i:s\\Z', $stop), '<');
$expectedQuery->fields = $this->mapping
->getPullFieldsArray();
$expectedQuery->fields[] = 'Id';
$expectedQuery->fields[] = $this->mapping
->getPullTriggerDate();
$expectedQuery->order[$this->mapping
->getPullTriggerDate()] = 'ASC';
$this
->assertArrayEquals($expectedQuery->fields, $query->fields);
$this
->assertArrayEquals($expectedQuery->order, $query->order);
$this
->assertArrayEquals($expectedQuery->conditions, $query->conditions);
$this
->assertEquals($expectedQuery->objectType, $query->objectType);
$this
->assertEquals($expectedQuery->limit, $query->limit);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
SalesforceMappingTest:: |
public static | property | Required modules. | |
SalesforceMappingTest:: |
protected | function |
Overrides UnitTestCase:: |
|
SalesforceMappingTest:: |
public | function | Test checkTriggers() | |
SalesforceMappingTest:: |
public | function | Test getPullFields() | |
SalesforceMappingTest:: |
public | function | Test getPullQuery() | |
SalesforceMappingTest:: |
public | function | Test object instantiation. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |