protected function MappedObjectTest::setUp in Salesforce Suite 5.0.x
Same name and namespace in other branches
- 8.4 modules/salesforce_mapping/tests/src/Unit/MappedObjectTest.php \Drupal\Tests\salesforce_mapping\Unit\MappedObjectTest::setUp()
- 8.3 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 38
Class
- MappedObjectTest
- Test Mapped Object instantitation.
Namespace
Drupal\Tests\salesforce_mapping\UnitCode
protected function setUp() : void {
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
->getMockBuilder(EntityTypeInterface::class)
->getMock();
$this->entityType
->expects($this
->any())
->method('getKeys')
->will($this
->returnValue([
'id' => 'id',
'uuid' => 'uuid',
]));
$this->etm = $this
->getMockBuilder(EntityTypeManagerInterface::class)
->getMock();
$this->etm
->expects($this
->any())
->method('getDefinition')
->with($this->entityTypeId)
->will($this
->returnValue($this->entityType));
$this->mappedObjectEntityType = $this
->getMockBuilder(EntityTypeInterface::class)
->getMock();
$this->mappedObjectEntityType
->expects($this
->any())
->method('getKeys')
->will($this
->returnValue([
'id' => 'id',
'entity_id' => 'entity_id',
'salesforce_id' => 'salesforce_id',
]));
$this->etm
->expects($this
->any())
->method('getDefinition')
->with('salesforce_mapped_object')
->will($this
->returnValue($this->mappedObjectEntityType));
$this->event_dispatcher = $this
->getMockBuilder(EventDispatcherInterface::class)
->getMock();
$this->client = $this
->getMockBuilder(RestClientInterface::CLASS)
->getMock();
$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
->getMockBuilder(FieldItemListInterface::class)
->getMock()));
$this->time = $this
->getMockBuilder(TimeInterface::CLASS)
->getMock();
$container = new ContainerBuilder();
$container
->set('entity_type.manager', $this->etm);
$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
->getMockBuilder(ContentEntityInterface::class)
->getMock();
$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
->getMockBuilder(SalesforceMappingInterface::CLASS)
->getMock();
$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);
}