Skip to content
Snippets Groups Projects
Commit 77482601 authored by Aaron Crosman's avatar Aaron Crosman Committed by Aaron Bauman
Browse files

Issue #3114456 by acrosman: Optional date field getting set to 'now' on push

parent 4b25ecd7
No related branches found
No related tags found
No related merge requests found
......@@ -204,8 +204,10 @@ abstract class SalesforceMappingFieldPluginBase extends PluginBase implements Sa
case 'date':
case 'datetime':
$date = new DrupalDateTime($value, 'UTC');
$value = $date->format(DateTime::ISO8601);
if (!empty($value)) {
$date = new DrupalDateTime($value, 'UTC');
$value = $date->format(DateTime::ISO8601);
}
break;
case 'double':
......
......@@ -93,4 +93,56 @@ class PushParamsTest extends BrowserTestBase {
$this->assertEquals($expected, $actual);
}
/**
* Test PushParams instantiation with blank date.
*/
public function testPushEmptyDate() {
date_default_timezone_set('America/New_York');
$mapping = SalesforceMapping::load('test_mapping');
// Entity 1 is the target reference.
$entity1 = Node::create([
'type' => 'salesforce_mapping_test_content',
'title' => 'Test Example',
]);
$entity1->save();
// Mapped Object to be used for RelatedIDs push params property.
$mappedObject = MappedObject::create([
'drupal_entity' => $entity1,
'salesforce_mapping' => $mapping,
'salesforce_id' => '0123456789ABCDEFGH',
'salesforce_link' => NULL,
]);
$mappedObject->save();
// Entity 2 to be mapped to Salesforce.
$entity2 = Node::create([
'type' => 'salesforce_mapping_test_content',
'title' => 'Test Example 2',
'field_salesforce_test_bool' => 1,
'field_salesforce_test_date' => '',
'field_salesforce_test_email' => 'test2@example.com',
'field_salesforce_test_link' => 'https://example.com',
'field_salesforce_test_reference' => $entity1,
]);
$entity2->save();
// Create a PushParams and assert it's created as we expect.
$pushParams = new PushParams($mapping, $entity2);
$expected = [
'FirstName' => 'SALESFORCE TEST',
'Email' => 'test2@example.com',
'Birthdate' => '',
'd5__Do_Not_Mail__c' => TRUE,
'ReportsToId' => '0123456789ABCDEFGH',
'RecordTypeId' => '012i0000001B15mAAC',
'Description' => 'https://example.com',
];
$actual = $pushParams->getParams();
ksort($actual);
ksort($expected);
$this->assertEquals($expected, $actual);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment