You are here

public function PushParamsTest::testPushParams in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 8.3 modules/salesforce_mapping/tests/src/Functional/PushParamsTest.php \Drupal\Tests\salesforce_mapping\Functional\PushParamsTest::testPushParams()
  2. 5.0.x modules/salesforce_mapping/tests/src/Functional/PushParamsTest.php \Drupal\Tests\salesforce_mapping\Functional\PushParamsTest::testPushParams()

Test PushParams instantiation, where all the work gets done.

File

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

Class

PushParamsTest
Test that PushParams correctly creates data structures for Salesforce.

Namespace

Drupal\Tests\salesforce_mapping\Functional

Code

public function testPushParams() {
  date_default_timezone_set('America/New_York');
  $mapping = SalesforceMapping::load('test_mapping');
  $storedDate = date(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, \Drupal::time()
    ->getRequestTime());

  // 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' => $storedDate,
    'field_salesforce_test_email' => 'test2@example.com',
    'field_salesforce_test_link' => 'https://example.com',
    'field_salesforce_test_reference' => $entity1,
    'field_salesforce_test_multi' => [
      [
        'value' => 'Value 1',
      ],
      [
        'value' => 'Value 2',
      ],
      [
        'value' => 'Value 3',
      ],
    ],
  ]);
  $entity2
    ->save();
  $expectedDate = new DrupalDateTime($storedDate, 'UTC');

  // 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' => $expectedDate
      ->format('Y-m-d\\TH:i:sO'),
    '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);
}