class SalesforceMappingStorageTest in Salesforce Suite 8.3
Same name and namespace in other branches
- 8.4 modules/salesforce_mapping/tests/src/Unit/SalesforceMappingStorageTest.php \Drupal\Tests\salesforce_mapping\Unit\SalesforceMappingStorageTest
- 5.0.x modules/salesforce_mapping/tests/src/Unit/SalesforceMappingStorageTest.php \Drupal\Tests\salesforce_mapping\Unit\SalesforceMappingStorageTest
@coversDefaultClass \Drupal\salesforce_mapping\SalesforceMappingStorage @group salesforce_mapping
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\salesforce_mapping\Unit\SalesforceMappingStorageTest
Expanded class hierarchy of SalesforceMappingStorageTest
File
- modules/
salesforce_mapping/ tests/ src/ Unit/ SalesforceMappingStorageTest.php, line 19
Namespace
Drupal\Tests\salesforce_mapping\UnitView source
class SalesforceMappingStorageTest extends UnitTestCase {
/**
* The type ID of the entity under test.
*
* @var string
*/
protected $entityTypeId;
/**
* The UUID service.
*
* @var \Drupal\Component\Uuid\UuidInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $uuidService;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $languageManager;
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $configFactory;
/**
* Entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $etm;
/**
* Entity type under test.
*
* @var \Drupal\Core\Entity\EntityTypeInterface
*/
protected $entityType;
/**
* Mapping storage service mock.
*
* @var \PHPUnit\Framework\MockObject\MockObject
*/
protected $salesforceMappingStorage;
/**
* {@inheritdoc}
*
* @covers ::__construct
*/
protected function setUp() {
parent::setUp();
$this->entityTypeId = 'test_entity_type';
$this->entityType = new ConfigEntityType([
'id' => $this->entityTypeId,
'class' => SalesforceMapping::class,
'provider' => 'the_provider',
'config_prefix' => 'the_config_prefix',
'entity_keys' => [
'id' => 'id',
'uuid' => 'uuid',
'langcode' => 'langcode',
],
'list_cache_tags' => [
$this->entityTypeId . '_list',
],
]);
$this->uuidService = $this
->createMock(UuidInterface::class);
$this->languageManager = $this
->createMock(LanguageManagerInterface::class);
$this->configFactory = $this
->createMock(ConfigFactoryInterface::class);
$this->etm = $this
->getMockBuilder(EntityTypeManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$this->etm
->expects($this
->any())
->method('getDefinition')
->with($this
->equalTo('test_entityType'))
->willReturn($this->entityType);
$this->salesforceMappingStorage = $this
->getMockBuilder(SalesforceMappingStorage::class)
->setConstructorArgs([
$this->entityTypeId,
$this->configFactory,
$this->uuidService,
$this->languageManager,
$this->etm,
])
->disableOriginalConstructor()
->setMethods([
'loadByProperties',
])
->getMock();
}
/**
* @covers ::loadByDrupal
*/
public function testLoadByDrupal() {
$config_object = $this
->prophesize(SalesforceMapping::class);
$this->salesforceMappingStorage
->expects($this
->at(0))
->method('loadByProperties')
->with($this
->equalTo([
'drupal_entity_type' => $this->entityTypeId,
]))
->willReturn([
$config_object
->reveal(),
]);
$this->salesforceMappingStorage
->expects($this
->at(1))
->method('loadByProperties')
->with($this
->equalTo([
'drupal_entity_type' => 'dummy',
]))
->willReturn([]);
// Good entity type id provided means config object should be returned.
$entities = $this->salesforceMappingStorage
->loadByDrupal($this->entityTypeId);
$this
->assertEquals([
$config_object
->reveal(),
], $entities);
// Bad entity type provided means config should not be returned.
$entities = $this->salesforceMappingStorage
->loadByDrupal('dummy');
$this
->assertEquals([], $entities);
}
/**
* @covers ::loadPushMappings
*/
public function testLoadPushMappings() {
$foo_config_object = $this
->prophesize(SalesforceMapping::class);
$foo_config_object
->id()
->willReturn('foo');
$foo_config_object
->doesPush()
->willReturn(TRUE);
$bar_config_object = $this
->prophesize(SalesforceMapping::class);
$bar_config_object
->id()
->willReturn('bar');
$bar_config_object
->doesPush()
->willReturn(TRUE);
$zee_config_object = $this
->prophesize(SalesforceMapping::class);
$zee_config_object
->id()
->willReturn('zee');
// Zee does NOT push; make sure it's excluded from our load helper.
$zee_config_object
->doesPush()
->willReturn(FALSE);
$this->salesforceMappingStorage
->expects($this
->once())
->method('loadByProperties')
->willReturn([
'foo' => $foo_config_object
->reveal(),
'bar' => $bar_config_object
->reveal(),
'zee' => $zee_config_object
->reveal(),
]);
$entities = $this->salesforceMappingStorage
->loadPushMappings($this->entityTypeId);
$expected = [
'foo' => $foo_config_object
->reveal(),
'bar' => $bar_config_object
->reveal(),
];
$this
->assertContainsOnlyInstancesOf(EntityInterface::class, $entities);
$this
->assertEquals($expected, $entities);
}
/**
* @covers ::loadPullMappings
*/
public function testLoadPullMappings() {
$foo_config_object = $this
->prophesize(SalesforceMapping::class);
$foo_config_object
->id()
->willReturn('foo');
$foo_config_object
->doesPull()
->willReturn(TRUE);
$bar_config_object = $this
->prophesize(SalesforceMapping::class);
$bar_config_object
->id()
->willReturn('bar');
$bar_config_object
->doesPull()
->willReturn(TRUE);
$zee_config_object = $this
->prophesize(SalesforceMapping::class);
$zee_config_object
->id()
->willReturn('zee');
// Zee does NOT push; make sure it's excluded from our load helper.
$zee_config_object
->doesPull()
->willReturn(FALSE);
$this->salesforceMappingStorage
->expects($this
->once())
->method('loadByProperties')
->willReturn([
'foo' => $foo_config_object
->reveal(),
'bar' => $bar_config_object
->reveal(),
'zee' => $zee_config_object
->reveal(),
]);
$entities = $this->salesforceMappingStorage
->loadPullMappings($this->entityTypeId);
$expected = [
'foo' => $foo_config_object
->reveal(),
'bar' => $bar_config_object
->reveal(),
];
$this
->assertContainsOnlyInstancesOf(EntityInterface::class, $entities);
$this
->assertEquals($expected, $entities);
}
/**
* @covers ::getMappedSobjectTypes
*/
public function testGetMappedSobjectTypes() {
$foo_config_object = $this
->prophesize(SalesforceMapping::class);
$foo_config_object
->id()
->willReturn('foo');
$foo_config_object
->getSalesforceObjectType()
->willReturn('Account');
$bar_config_object = $this
->prophesize(SalesforceMapping::class);
$bar_config_object
->id()
->willReturn('bar');
$bar_config_object
->getSalesforceObjectType()
->willReturn('Account');
$zee_config_object = $this
->prophesize(SalesforceMapping::class);
$zee_config_object
->id()
->willReturn('zee');
$zee_config_object
->getSalesforceObjectType()
->willReturn('Contact');
$this->salesforceMappingStorage
->expects($this
->once())
->method('loadByProperties')
->willReturn([
$foo_config_object
->reveal(),
$bar_config_object
->reveal(),
$zee_config_object
->reveal(),
]);
$object_types = $this->salesforceMappingStorage
->getMappedSobjectTypes();
$expected = [
'Account' => 'Account',
'Contact' => 'Contact',
];
$this
->assertEquals($expected, $object_types);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
SalesforceMappingStorageTest:: |
protected | property | The config factory service. | |
SalesforceMappingStorageTest:: |
protected | property | Entity type under test. | |
SalesforceMappingStorageTest:: |
protected | property | The type ID of the entity under test. | |
SalesforceMappingStorageTest:: |
protected | property | Entity type manager service. | |
SalesforceMappingStorageTest:: |
protected | property | The language manager. | |
SalesforceMappingStorageTest:: |
protected | property | Mapping storage service mock. | |
SalesforceMappingStorageTest:: |
protected | property | The UUID service. | |
SalesforceMappingStorageTest:: |
protected | function |
@covers ::__construct Overrides UnitTestCase:: |
|
SalesforceMappingStorageTest:: |
public | function | @covers ::getMappedSobjectTypes | |
SalesforceMappingStorageTest:: |
public | function | @covers ::loadByDrupal | |
SalesforceMappingStorageTest:: |
public | function | @covers ::loadPullMappings | |
SalesforceMappingStorageTest:: |
public | function | @covers ::loadPushMappings | |
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. |