protected function ContentEntityNormalizerTest::getFieldsSerializer in Acquia Content Hub 8
Make sure we return the expected normalization results.
For all the given definitions of fields with their respective values, we need to be sure that when ->normalize is executed, it returns the expected results.
Parameters
array $definitions: The field definitions.
\Drupal\Core\Session\AccountInterface $user_context: The user context such as the account.
Return value
\Symfony\Component\Serializer\Serializer|\PHPUnit_Framework_MockObject_MockObject The Serializer.
13 calls to ContentEntityNormalizerTest::getFieldsSerializer()
- ContentEntityNormalizerTest::testNormalizeImageReferenceField in tests/
src/ Unit/ Normalizer/ ContentEntityNormalizerTest.php - Tests the normalize() method for image references.
- ContentEntityNormalizerTest::testNormalizeOneField in tests/
src/ Unit/ Normalizer/ ContentEntityNormalizerTest.php - Tests the normalize() method.
- ContentEntityNormalizerTest::testNormalizeOneFieldMultiValued in tests/
src/ Unit/ Normalizer/ ContentEntityNormalizerTest.php - Tests the normalize() method.
- ContentEntityNormalizerTest::testNormalizeReferenceField in tests/
src/ Unit/ Normalizer/ ContentEntityNormalizerTest.php - Tests the normalize() method.
- ContentEntityNormalizerTest::testNormalizeTypeReferenceField in tests/
src/ Unit/ Normalizer/ ContentEntityNormalizerTest.php - Tests the normalize() method.
File
- tests/
src/ Unit/ Normalizer/ ContentEntityNormalizerTest.php, line 825
Class
- ContentEntityNormalizerTest
- PHPUnit test for the ContentEntityNormalizer class.
Namespace
Drupal\Tests\acquia_contenthub\Unit\NormalizerCode
protected function getFieldsSerializer(array $definitions, AccountInterface $user_context = NULL) {
$serializer = $this
->getMockBuilder('Symfony\\Component\\Serializer\\Serializer')
->disableOriginalConstructor()
->setMethods([
'normalize',
])
->getMock();
$serializer
->method('normalize')
->with($this
->containsOnlyInstancesOf('Drupal\\Core\\Field\\FieldItemListInterface'), 'json', [
'account' => $user_context,
'query_params' => [],
'entity_type' => 'node',
])
->willReturnCallback(function ($field, $format, $context) {
if ($field) {
return $field
->getValue();
}
return NULL;
});
return $serializer;
}