protected function MappedObjectTest::setUp in Salesforce Suite 8.3
Same name and namespace in other branches
- 8.4 modules/salesforce_mapping/tests/src/Unit/MappedObjectTest.php \Drupal\Tests\salesforce_mapping\Unit\MappedObjectTest::setUp()
- 5.0.x modules/salesforce_mapping/tests/src/Unit/MappedObjectTest.php \Drupal\Tests\salesforce_mapping\Unit\MappedObjectTest::setUp()
Overrides UnitTestCase::setUp
File
- modules/
salesforce_mapping/ tests/ src/ Unit/ MappedObjectTest.php, line 26
Class
- MappedObjectTest
- Test Mapped Object instantitation.
Namespace
Drupal\Tests\salesforce_mapping\UnitCode
protected function setUp() {
parent::setUp();
$this->entityTypeId = $this
->randomMachineName();
$this->bundle = $this
->randomMachineName();
$this->mapped_object_id = 1;
$this->salesforce_id = '1234567890abcdeAAA';
$this->mapping_id = 1;
$this->entity_id = 1;
$this->sf_object = new SObject([
'id' => $this->salesforce_id,
'attributes' => [
'type' => $this
->randomMachineName(),
],
'foo' => 'bar',
]);
$this->sfid = $this
->getMockBuilder(SFID::CLASS)
->setConstructorArgs([
$this->salesforce_id,
])
->getMock();
$this->sfid
->expects($this
->any())
->method('__toString')
->willReturn($this->salesforce_id);
$this->entityType = $this
->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
$this->entityType
->expects($this
->any())
->method('getKeys')
->will($this
->returnValue([
'id' => 'id',
'uuid' => 'uuid',
]));
$this->entityManager = $this
->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
$this->entityManager
->expects($this
->any())
->method('getDefinition')
->with($this->entityTypeId)
->will($this
->returnValue($this->entityType));
$this->mappedObjectEntityType = $this
->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
$this->mappedObjectEntityType
->expects($this
->any())
->method('getKeys')
->will($this
->returnValue([
'id' => 'id',
'entity_id' => 'entity_id',
'salesforce_id' => 'salesforce_id',
]));
$this->entityManager = $this
->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
$this->entityManager
->expects($this
->any())
->method('getDefinition')
->with('salesforce_mapped_object')
->will($this
->returnValue($this->mappedObjectEntityType));
$this->event_dispatcher = $this
->getMock('\\Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
$this->client = $this
->getMock(RestClientInterface::CLASS);
$this->fieldTypePluginManager = $this
->getMockBuilder('\\Drupal\\Core\\Field\\FieldTypePluginManager')
->disableOriginalConstructor()
->getMock();
$this->fieldTypePluginManager
->expects($this
->any())
->method('getDefaultStorageSettings')
->will($this
->returnValue([]));
$this->fieldTypePluginManager
->expects($this
->any())
->method('getDefaultFieldSettings')
->will($this
->returnValue([]));
$this->fieldTypePluginManager
->expects($this
->any())
->method('createFieldItemList')
->will($this
->returnValue($this
->getMock('Drupal\\Core\\Field\\FieldItemListInterface')));
$this->time = $this
->getMock(TimeInterface::CLASS);
$container = new ContainerBuilder();
$container
->set('entity.manager', $this->entityManager);
$container
->set('salesforce.client', $this->client);
$container
->set('event_dispatcher', $this->event_dispatcher);
$container
->set('plugin.manager.field.field_type', $this->fieldTypePluginManager);
$container
->set('datetime.time', $this->time);
\Drupal::setContainer($container);
$this->entity = $this
->getMock('\\Drupal\\Core\\Entity\\ContentEntityInterface');
$this->entity
->expects($this
->any())
->method('id')
->willReturn($this->entity_id);
$this->entity
->expects($this
->any())
->method('isTranslatable')
->willReturn(FALSE);
// Mock salesforce mapping.
$this->mapping = $this
->getMock(SalesforceMappingInterface::CLASS);
$this->mapping
->expects($this
->any())
->method('getFieldMappings')
->willReturn([]);
$this->mapping
->expects($this
->any())
->method('getPullFields')
->willReturn([]);
$this->mapping
->expects($this
->any())
->method('getSalesforceObjectType')
->willReturn('dummy_sf_object_type');
$this->mapped_object = $this
->getMockBuilder(MappedObject::CLASS)
->disableOriginalConstructor()
->setMethods([
'getMappedEntity',
'getMapping',
'getEntityType',
'sfid',
'set',
'save',
'setNewRevision',
'client',
])
->getMock();
$this->mapped_object
->expects($this
->any())
->method('getMappedEntity')
->willReturn($this->entity);
$this->mapped_object
->expects($this
->any())
->method('getMapping')
->willReturn($this->mapping);
$this->mapped_object
->expects($this
->any())
->method('getEntityType')
->willReturn($this->mappedObjectEntityType);
$this->mapped_object
->expects($this
->any())
->method('set')
->willReturn($this->mapped_object);
$this->mapped_object
->expects($this
->any())
->method('client')
->willReturn($this->client);
}