public function ContentEntityNormalizerTest::testNormalizeImageReferenceField in Acquia Content Hub 8
Tests the normalize() method for image references.
Tests 1 entity reference field and checks if it appears in the normalized result. It should return the normalized image, including alt/title attributes.
@covers ::normalize @covers ::addFieldsToContentHubEntity
File
- tests/
src/ Unit/ Normalizer/ ContentEntityNormalizerTest.php, line 686
Class
- ContentEntityNormalizerTest
- PHPUnit test for the ContentEntityNormalizer class.
Namespace
Drupal\Tests\acquia_contenthub\Unit\NormalizerCode
public function testNormalizeImageReferenceField() {
$this
->mockContainerResponseForNormalize();
$definitions = [
'field_image' => $this
->createMockImageEntityReferenceFieldItemList('field_image', TRUE, $this->userContext),
];
// Set our Serializer and expected serialized return value for the given
// fields.
$serializer = $this
->getFieldsSerializer($definitions, $this->userContext);
$this->contentEntityNormalizer
->setSerializer($serializer);
// Create our Content Entity.
$content_entity_mock = $this
->createMockForContentEntity($definitions, [
'en',
]);
// Normalize the Content Entity with the class that we are testing.
$normalized = $this->contentEntityNormalizer
->normalize($content_entity_mock, 'acquia_contenthub_cdf');
// Check if valid result.
$this
->doTestValidResultForOneEntity($normalized);
// Get our Content Hub Entity out of the result.
$normalized_entity = $this
->getContentHubEntityFromResult($normalized);
// Check if the field has the given value.
$this
->assertEquals($normalized_entity
->getAttribute('field_image')
->getValues(), [
'en' => [
0 => '{"alt":"test-alt-image-value","title":"test-alt-image-text","target_uuid":"[test-uuid-image-1]"}',
],
]);
}