function EntityReferenceFieldItemNormalizerTest::testNormalizeWithEmptyTaxonomyTermReference

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

@covers ::normalize

File

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

Class

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

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

public function testNormalizeWithEmptyTaxonomyTermReference() {
    // Override the serializer prophecy from setUp() to return a zero value.
    $this->serializer = $this->prophesize(Serializer::class);
    // Set up the serializer to return an entity property.
    $this->serializer
        ->normalize(Argument::cetera())
        ->willReturn(0);
    $this->normalizer
        ->setSerializer($this->serializer
        ->reveal());
    $entity_reference = $this->prophesize(TypedDataInterface::class);
    $entity_reference->getValue()
        ->willReturn(NULL)
        ->shouldBeCalled();
    $field_definition = $this->prophesize(FieldDefinitionInterface::class);
    $field_definition->getSetting('target_type')
        ->willReturn('taxonomy_term');
    $this->fieldItem
        ->getFieldDefinition()
        ->willReturn($field_definition->reveal());
    $this->fieldItem
        ->get('entity')
        ->willReturn($entity_reference)
        ->shouldBeCalled();
    $this->fieldItem
        ->getProperties(TRUE)
        ->willReturn([
        'target_id' => $this->getTypedDataProperty(FALSE),
    ])
        ->shouldBeCalled();
    $normalized = $this->normalizer
        ->normalize($this->fieldItem
        ->reveal());
    $expected = [
        'target_id' => NULL,
    ];
    $this->assertSame($expected, $normalized);
}

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