You are here

public function EntityReferenceFieldItemNormalizerTest::testNormalizeWithNoEntity in Zircon Profile 8

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

@covers ::normalize

File

core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php, line 103
Contains \Drupal\Tests\serialization\Unit\Normalizer\EntityReferenceFieldItemNormalizerTest.

Class

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

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

public function testNormalizeWithNoEntity() {
  $entity_reference = $this
    ->prophesize(TypedDataInterface::class);
  $entity_reference
    ->getValue()
    ->willReturn(NULL)
    ->shouldBeCalled();
  $this->fieldItem
    ->get('entity')
    ->willReturn($entity_reference
    ->reveal())
    ->shouldBeCalled();
  $normalized = $this->normalizer
    ->normalize($this->fieldItem
    ->reveal());
  $expected = [
    'target_id' => [
      'value' => 'test',
    ],
  ];
  $this
    ->assertSame($expected, $normalized);
}