function ContentEntityNormalizerTest::testNormalize
Same name in other branches
- 9 core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ContentEntityNormalizerTest::testNormalize()
- 8.9.x core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ContentEntityNormalizerTest::testNormalize()
- 11.x core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ContentEntityNormalizerTest::testNormalize()
Tests the normalize() method.
@covers ::normalize
File
-
core/
modules/ serialization/ tests/ src/ Unit/ Normalizer/ ContentEntityNormalizerTest.php, line 71
Class
- ContentEntityNormalizerTest
- @coversDefaultClass \Drupal\serialization\Normalizer\ContentEntityNormalizer @group serialization
Namespace
Drupal\Tests\serialization\Unit\NormalizerCode
public function testNormalize() : void {
$this->serializer
->normalize(Argument::type(FieldItemListInterface::class), 'test_format', [
'account' => NULL,
])
->willReturn('test');
$definitions = [
'field_accessible_external' => $this->createMockFieldListItem(TRUE, FALSE),
'field_non-accessible_external' => $this->createMockFieldListItem(FALSE, FALSE),
'field_accessible_internal' => $this->createMockFieldListItem(TRUE, TRUE),
'field_non-accessible_internal' => $this->createMockFieldListItem(FALSE, TRUE),
];
$content_entity_mock = $this->createMockForContentEntity($definitions);
$normalized = $this->contentEntityNormalizer
->normalize($content_entity_mock, 'test_format');
$this->assertArrayHasKey('field_accessible_external', $normalized);
$this->assertEquals('test', $normalized['field_accessible_external']);
$this->assertArrayNotHasKey('field_non-accessible_external', $normalized);
$this->assertArrayNotHasKey('field_accessible_internal', $normalized);
$this->assertArrayNotHasKey('field_non-accessible_internal', $normalized);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.