You are here

public function EntityReferenceFieldItemNormalizerTest::testDenormalizeWithTypeAndUuid in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\EntityReferenceFieldItemNormalizerTest::testDenormalizeWithTypeAndUuid()
  2. 9 core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\EntityReferenceFieldItemNormalizerTest::testDenormalizeWithTypeAndUuid()

@covers ::denormalize

File

core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php, line 298

Class

EntityReferenceFieldItemNormalizerTest
@coversDefaultClass \Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer @group serialization

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

public function testDenormalizeWithTypeAndUuid() {
  $data = [
    'target_id' => 'test',
    'target_type' => 'test_type',
    'target_uuid' => '080e3add-f9d5-41ac-9821-eea55b7b42fb',
  ];
  $entity = $this
    ->prophesize(FieldableEntityInterface::class);
  $entity
    ->id()
    ->willReturn('test')
    ->shouldBeCalled();
  $this->entityRepository
    ->loadEntityByUuid($data['target_type'], $data['target_uuid'])
    ->willReturn($entity)
    ->shouldBeCalled();
  $this->fieldItem
    ->getProperties()
    ->willReturn([
    'target_id' => $this
      ->prophesize(IntegerInterface::class),
  ]);
  $this->fieldItem
    ->setValue([
    'target_id' => 'test',
  ])
    ->shouldBeCalled();
  $this
    ->assertDenormalize($data);
}