function EntityReferenceFieldItemNormalizerTest::assertDenormalize

Same name and namespace in other branches
  1. 8.9.x core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\EntityReferenceFieldItemNormalizerTest::assertDenormalize()
  2. 10 core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\EntityReferenceFieldItemNormalizerTest::assertDenormalize()
  3. 11.x core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\EntityReferenceFieldItemNormalizerTest::assertDenormalize()

Asserts denormalization process is correct for give data.

@internal

Parameters

array $data: The data to denormalize.

7 calls to EntityReferenceFieldItemNormalizerTest::assertDenormalize()
EntityReferenceFieldItemNormalizerTest::testConstructValueProperties in core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php
@covers ::constructValue
EntityReferenceFieldItemNormalizerTest::testDenormalizeWithEmptyUuid in core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php
@covers ::denormalize
EntityReferenceFieldItemNormalizerTest::testDenormalizeWithId in core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php
@covers ::denormalize
EntityReferenceFieldItemNormalizerTest::testDenormalizeWithTypeAndUuid in core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php
@covers ::denormalize
EntityReferenceFieldItemNormalizerTest::testDenormalizeWithTypeWithIncorrectUuid in core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php
@covers ::denormalize

... See full list

File

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

Class

EntityReferenceFieldItemNormalizerTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21serialization%21src%21Normalizer%21EntityReferenceFieldItemNormalizer.php/class/EntityReferenceFieldItemNormalizer/9" title="Adds the file URI to embedded file entities." class="local">\Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer</a> @group serialization

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

protected function assertDenormalize(array $data) : void {
    $this->fieldItem
        ->getParent()
        ->willReturn($this->prophesize(FieldItemListInterface::class)
        ->reveal());
    $this->fieldItem
        ->getFieldDefinition()
        ->willReturn($this->fieldDefinition
        ->reveal());
    if (!empty($data['target_uuid'])) {
        $this->fieldDefinition
            ->getSetting('target_type')
            ->willReturn('test_type')
            ->shouldBeCalled();
    }
    // Avoid a static method call by returning dummy serialized property data.
    $this->fieldDefinition
        ->getFieldStorageDefinition()
        ->willReturn()
        ->shouldBeCalled();
    $this->fieldDefinition
        ->getName()
        ->willReturn('field_reference')
        ->shouldBeCalled();
    $entity = $this->prophesize(EntityInterface::class);
    $entity_type = $this->prophesize(EntityTypeInterface::class);
    $entity->getEntityType()
        ->willReturn($entity_type->reveal())
        ->shouldBeCalled();
    $this->fieldItem
        ->getPluginDefinition()
        ->willReturn([
        'serialized_property_names' => [
            'foo' => 'bar',
        ],
    ])
        ->shouldBeCalled();
    $this->fieldItem
        ->getEntity()
        ->willReturn($entity->reveal())
        ->shouldBeCalled();
    $context = [
        'target_instance' => $this->fieldItem
            ->reveal(),
    ];
    $denormalized = $this->normalizer
        ->denormalize($data, EntityReferenceItem::class, 'json', $context);
    $this->assertSame($context['target_instance'], $denormalized);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.