You are here

public function PushParamsTest::testPushEmptyDate in Salesforce Suite 5.0.x

Same name and namespace in other branches
  1. 8.4 modules/salesforce_mapping/tests/src/Functional/PushParamsTest.php \Drupal\Tests\salesforce_mapping\Functional\PushParamsTest::testPushEmptyDate()

Test PushParams instantiation with blank date.

File

modules/salesforce_mapping/tests/src/Functional/PushParamsTest.php, line 105

Class

PushParamsTest
Test that PushParams correctly creates data structures for Salesforce.

Namespace

Drupal\Tests\salesforce_mapping\Functional

Code

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 = \Drupal::entityTypeManager()
    ->getStorage('salesforce_mapped_object')
    ->loadByEntityAndMapping($entity1, $mapping);
  $mappedObject
    ->set('salesforce_id', '0123456789ABCDEFGH');
  $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,
    'field_salesforce_test_multi' => [
      'Value 1',
      'Value 2',
      'Value 3',
    ],
  ]);
  $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' => null,
    'd5__Do_Not_Mail__c' => TRUE,
    'ReportsToId' => '0123456789ABCDEFGH',
    'RecordTypeId' => '012i0000001B15mAAC',
    'Description' => 'https://example.com',
    'd5__Multipicklist_Test__c' => 'Value 1;Value 2;Value 3',
  ];
  $actual = $pushParams
    ->getParams();
  ksort($actual);
  ksort($expected);
  $this
    ->assertEquals($expected, $actual);
}