class DependencyFieldMapGeneratorTest in Entity Reference Integrity 8
Test the field map generator.
@group entity_reference_integrity
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\entity_reference_integrity\Unit\DependencyFieldMapGeneratorTest
Expanded class hierarchy of DependencyFieldMapGeneratorTest
File
- tests/
src/ Unit/ DependencyFieldMapGeneratorTest.php, line 17
Namespace
Drupal\Tests\entity_reference_integrity\UnitView source
class DependencyFieldMapGeneratorTest extends UnitTestCase {
/**
* Test the field map.
*
* @dataProvider fieldMapTestCases
*/
public function testFieldMap($has_custom_storage, $has_storage_definition, $revision_metadata_fields, $field_map, $expected_result) {
$target_entity_type_id = 'target_entity_type_id';
$entityFieldManager = $this
->createMock(EntityFieldManagerInterface::class);
$entityFieldManager
->expects($this
->any())
->method('getFieldMapByFieldType')
->willReturn($field_map);
$storage_definition = $this
->createMock(FieldStorageDefinitionInterface::class);
$storage_definition
->expects($this
->any())
->method('hasCustomStorage')
->willReturn($has_custom_storage);
$storage_definition
->expects($this
->any())
->method('getSetting')
->willReturn($target_entity_type_id);
$entityFieldManager
->expects($this
->any())
->method('getFieldStorageDefinitions')
->willReturn($has_storage_definition ? [
'field_name' => $storage_definition,
] : []);
$entityTypeManager = $this
->createMock(EntityTypeManagerInterface::class);
$mockDefinition = $this
->createMock(ContentEntityTypeInterface::class);
$mockDefinition
->method('getRevisionMetadataKeys')
->willReturn($revision_metadata_fields);
$entityTypeManager
->method('getDefinition')
->willReturn($mockDefinition);
$field_map = new DependencyFieldMapGenerator($entityFieldManager, $entityTypeManager, 'entity_reference', 'target_type');
$generated_map = $field_map
->getReferencingFields($target_entity_type_id);
$this
->assertEquals($expected_result, $generated_map);
}
/**
* Test cases for ::testFieldMap.
*/
public function fieldMapTestCases() {
return [
'Standard field' => [
FALSE,
TRUE,
[],
[
'foo_entity_type_id' => [
'field_name' => [],
],
],
[
'foo_entity_type_id' => [
'field_name',
],
],
],
'Custom storage field' => [
TRUE,
TRUE,
[],
[
'foo_entity_type_id' => [
'field_name' => [],
],
],
[],
],
'No storage definition' => [
FALSE,
FALSE,
[],
[
'foo_entity_type_id' => [
'field_name' => [],
],
],
[],
],
'Field is revision metadata' => [
FALSE,
TRUE,
[
'field_name',
],
[
'foo_entity_type_id' => [
'field_name' => [],
],
],
[],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencyFieldMapGeneratorTest:: |
public | function | Test cases for ::testFieldMap. | |
DependencyFieldMapGeneratorTest:: |
public | function | Test the field map. | |
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. | |
UnitTestCase:: |
protected | function | 340 |