class DeleteHandlerTest in Salesforce Suite 8.3
Same name and namespace in other branches
- 8.4 modules/salesforce_pull/tests/src/Unit/DeleteHandlerTest.php \Drupal\Tests\salesforce_pull\Unit\DeleteHandlerTest
- 5.0.x modules/salesforce_pull/tests/src/Unit/DeleteHandlerTest.php \Drupal\Tests\salesforce_pull\Unit\DeleteHandlerTest
Test Object instantitation.
@group salesforce_pull
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\salesforce_pull\Unit\DeleteHandlerTest
Expanded class hierarchy of DeleteHandlerTest
File
- modules/
salesforce_pull/ tests/ src/ Unit/ DeleteHandlerTest.php, line 25
Namespace
Drupal\Tests\salesforce_pull\UnitView source
class DeleteHandlerTest extends UnitTestCase {
protected static $modules = [
'salesforce_pull',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$result = [
'totalSize' => 1,
'done' => TRUE,
'deletedRecords' => [
[
'id' => '1234567890abcde',
'attributes' => [
'type' => 'dummy',
],
'name' => 'Example',
],
],
];
$prophecy = $this
->prophesize(RestClientInterface::CLASS);
$prophecy
->getDeleted(Argument::any(), Argument::any(), Argument::any())
->willReturn($result);
$this->sfapi = $prophecy
->reveal();
// Mock an atribtary Drupal entity.
$prophecy = $this
->prophesize(User::CLASS);
$prophecy
->delete()
->willReturn(TRUE);
$prophecy
->id()
->willReturn(1);
$prophecy
->label()
->willReturn('foo');
$this->entity = $prophecy
->reveal();
$this->mapping = $this
->getMock(SalesforceMappingInterface::CLASS);
$this->mapping
->expects($this
->any())
->method('__get')
->with($this
->equalTo('id'))
->willReturn(1);
$this->mapping
->expects($this
->any())
->method('__get')
->with($this
->equalTo('entity'))
->willReturn($this->entity);
$this->mapping
->expects($this
->any())
->method('getSalesforceObjectType')
->willReturn('default');
$this->mapping
->expects($this
->any())
->method('getPullFieldsArray')
->willReturn([
'Name' => 'Name',
'Account Number' => 'Account Number',
]);
$this->mapping
->expects($this
->any())
->method('checkTriggers')
->with([
MappingConstants::SALESFORCE_MAPPING_SYNC_SF_DELETE,
])
->willReturn(TRUE);
// Mock mapped object.
$this->entityTypeId = new \stdClass();
$this->entityId = new \stdClass();
$this->entityRef = new \stdClass();
$this->entityTypeId->value = 'test';
$this->entityId->value = '1';
$this->entityRef->entity = $this->mapping;
$this->mappedObject = $this
->getMock(MappedObjectInterface::CLASS);
$this->mappedObject
->expects($this
->any())
->method('delete')
->willReturn(TRUE);
$this->mappedObject
->expects($this
->any())
->method('getMapping')
->willReturn($this->mapping);
$this->mappedObject
->expects($this
->any())
->method('getFieldDefinitions')
->willReturn([
'drupal_entity',
'salesforce_mapping',
]);
$this->mappedObject
->expects($this
->any())
->method('getMappedEntity')
->willReturn($this->entity);
// Mock mapping ConfigEntityStorage object.
$prophecy = $this
->prophesize(SalesforceMappingStorage::CLASS);
$prophecy
->loadByProperties(Argument::any())
->willReturn([
$this->mapping,
]);
$prophecy
->load(Argument::any())
->willReturn($this->mapping);
$prophecy
->loadMultiple()
->willReturn([
$this->mapping,
]);
$this->configStorage = $prophecy
->reveal();
// Mock mapped object EntityStorage object.
$this->entityStorage = $this
->getMockBuilder(MappedObjectStorage::CLASS)
->disableOriginalConstructor()
->getMock();
$this->entityStorage
->expects($this
->any())
->method('loadBySfid')
->willReturn([
$this->mappedObject,
]);
// Mock Drupal entity EntityStorage object.
$prophecy = $this
->prophesize(EntityStorageBase::CLASS);
$prophecy
->load(Argument::any())
->willReturn($this->entity);
$this->drupalEntityStorage = $prophecy
->reveal();
// Mock EntityTypeManagerInterface.
$prophecy = $this
->prophesize(EntityTypeManagerInterface::CLASS);
$prophecy
->getStorage('salesforce_mapping')
->willReturn($this->configStorage);
$prophecy
->getStorage('salesforce_mapped_object')
->willReturn($this->entityStorage);
$prophecy
->getStorage('test')
->willReturn($this->drupalEntityStorage);
$this->etm = $prophecy
->reveal();
// Mock state.
$prophecy = $this
->prophesize(StateInterface::CLASS);
$prophecy
->get('salesforce.mapping_pull_info', Argument::any())
->willReturn([
1 => [
'last_delete_timestamp' => '1485787434',
],
]);
$prophecy
->set('salesforce.mapping_pull_info', Argument::any())
->willReturn(NULL);
$this->state = $prophecy
->reveal();
// Mock event dispatcher.
$prophecy = $this
->prophesize(ContainerAwareEventDispatcher::CLASS);
$prophecy
->dispatch(Argument::any(), Argument::any())
->willReturn();
$this->ed = $prophecy
->reveal();
$this->dh = new DeleteHandler($this->sfapi, $this->etm, $this->state, $this->ed);
}
/**
* Test object creation.
*/
public function testObject() {
$this
->assertTrue($this->dh instanceof DeleteHandler);
}
/**
* Test processDeletedRecords.
*/
public function testGetUpdatedRecords() {
$result = $this->dh
->processDeletedRecords();
$this
->assertTrue($result);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeleteHandlerTest:: |
protected static | property | ||
DeleteHandlerTest:: |
protected | function |
Overrides UnitTestCase:: |
|
DeleteHandlerTest:: |
public | function | Test processDeletedRecords. | |
DeleteHandlerTest:: |
public | function | Test object creation. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |