You are here

protected function SalesforceMappingTest::setUp in Salesforce Suite 8.3

Same name and namespace in other branches
  1. 8.4 modules/salesforce_mapping/tests/src/Unit/SalesforceMappingTest.php \Drupal\Tests\salesforce_mapping\Unit\SalesforceMappingTest::setUp()
  2. 5.0.x modules/salesforce_mapping/tests/src/Unit/SalesforceMappingTest.php \Drupal\Tests\salesforce_mapping\Unit\SalesforceMappingTest::setUp()

Overrides UnitTestCase::setUp

File

modules/salesforce_mapping/tests/src/Unit/SalesforceMappingTest.php, line 29

Class

SalesforceMappingTest
Test Object instantitation.

Namespace

Drupal\Tests\salesforce_mapping\Unit

Code

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);
}