You are here

public function EntityReferenceFieldItemNormalizerTest::testNormalize 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::testNormalize()

@covers ::normalize

File

core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php, line 74
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 testNormalize() {
  $test_url = '/test/100';
  $entity = $this
    ->prophesize(EntityInterface::class);
  $entity
    ->url('canonical')
    ->willReturn($test_url)
    ->shouldBeCalled();
  $entity_reference = $this
    ->prophesize(TypedDataInterface::class);
  $entity_reference
    ->getValue()
    ->willReturn($entity
    ->reveal())
    ->shouldBeCalled();
  $this->fieldItem
    ->get('entity')
    ->willReturn($entity_reference)
    ->shouldBeCalled();
  $normalized = $this->normalizer
    ->normalize($this->fieldItem
    ->reveal());
  $expected = [
    'target_id' => [
      'value' => 'test',
    ],
    'url' => $test_url,
  ];
  $this
    ->assertSame($expected, $normalized);
}