You are here

public function EntityReferenceFieldNormalizerTest::setUp in JSON:API 8

Overrides UnitTestCase::setUp

File

tests/src/Unit/Normalizer/EntityReferenceFieldNormalizerTest.php, line 46

Class

EntityReferenceFieldNormalizerTest
@coversDefaultClass \Drupal\jsonapi\Normalizer\EntityReferenceFieldNormalizer @group jsonapi

Namespace

Drupal\Tests\jsonapi\Unit\Normalizer

Code

public function setUp() {
  $target_resource_type = new ResourceType('lorem', 'dummy_bundle', NULL);
  $this->resourceType = new ResourceType('fake_entity_type', 'dummy_bundle', NULL);
  $this->resourceType
    ->setRelatableResourceTypes([
    'field_dummy' => [
      $target_resource_type,
    ],
    'field_dummy_single' => [
      $target_resource_type,
    ],
  ]);
  $link_manager = $this
    ->prophesize(LinkManager::class);
  $field_manager = $this
    ->prophesize(EntityFieldManagerInterface::class);
  $field_definition = $this
    ->prophesize(FieldConfig::class);
  $item_definition = $this
    ->prophesize(FieldItemDataDefinition::class);
  $item_definition
    ->getMainPropertyName()
    ->willReturn('bunny');
  $item_definition
    ->getSetting('target_type')
    ->willReturn('fake_entity_type');
  $item_definition
    ->getSetting('handler_settings')
    ->willReturn([
    'target_bundles' => [
      'dummy_bundle',
    ],
  ]);
  $field_definition
    ->getItemDefinition()
    ->willReturn($item_definition
    ->reveal());
  $storage_definition = $this
    ->prophesize(FieldStorageDefinitionInterface::class);
  $storage_definition
    ->isMultiple()
    ->willReturn(TRUE);
  $field_definition
    ->getFieldStorageDefinition()
    ->willReturn($storage_definition
    ->reveal());
  $field_definition2 = $this
    ->prophesize(FieldConfig::class);
  $field_definition2
    ->getItemDefinition()
    ->willReturn($item_definition
    ->reveal());
  $storage_definition2 = $this
    ->prophesize(FieldStorageDefinitionInterface::class);
  $storage_definition2
    ->isMultiple()
    ->willReturn(FALSE);
  $field_definition2
    ->getFieldStorageDefinition()
    ->willReturn($storage_definition2
    ->reveal());
  $field_manager
    ->getFieldDefinitions('fake_entity_type', 'dummy_bundle')
    ->willReturn([
    'field_dummy' => $field_definition
      ->reveal(),
    'field_dummy_single' => $field_definition2
      ->reveal(),
  ]);
  $plugin_manager = $this
    ->prophesize(FieldTypePluginManagerInterface::class);
  $plugin_manager
    ->createFieldItemList(Argument::type(FieldableEntityInterface::class), Argument::type('string'), Argument::type('array'))
    ->willReturnArgument(2);
  $resource_type_repository = $this
    ->prophesize(ResourceTypeRepository::class);
  $resource_type_repository
    ->get('fake_entity_type', 'dummy_bundle')
    ->willReturn($this->resourceType);
  $entity = $this
    ->prophesize(EntityInterface::class);
  $entity
    ->uuid()
    ->willReturn('4e6cb61d-4f04-437f-99fe-42c002393658');
  $entity
    ->id()
    ->willReturn(42);
  $entity_repository = $this
    ->prophesize(EntityRepositoryInterface::class);
  $entity_repository
    ->loadEntityByUuid('lorem', '4e6cb61d-4f04-437f-99fe-42c002393658')
    ->willReturn($entity
    ->reveal());
  $this->normalizer = new EntityReferenceFieldNormalizer($link_manager
    ->reveal(), $field_manager
    ->reveal(), $plugin_manager
    ->reveal(), $resource_type_repository
    ->reveal(), $entity_repository
    ->reveal());
}