$actual =
$this->serializer->
serialize($normalized, 'json'
);
$this->
assertSame($expected,
$actual, 'A normalized array serializes to JSON when "json" is requested'
);
// Test 'ajax'.
$actual =
$this->serializer->
serialize($this->entity, 'ajax'
);
$this->
assertSame($expected,
$actual, 'Entity serializes to JSON when "ajax" is requested.'
);
$actual =
$this->serializer->
serialize($normalized, 'ajax'
);
$this->
assertSame($expected,
$actual, 'A normalized array serializes to JSON when "ajax" is requested'
);
// Generate the expected xml in a way that allows changes to entity property
// order.
$expected_created =
[ 'value' => DateTimePlus::
createFromTimestamp($this->entity->created->value, 'UTC'
)->
format(\DateTime::RFC3339
),
'format' => \DateTime::RFC3339,
];
$expected =
[ 'id' => '<id><value>' .
$this->entity->
id() . '</value></id>',
'uuid' => '<uuid><value>' .
$this->entity->
uuid() . '</value></uuid>',
'langcode' => '<langcode><value>en</value></langcode>',
'name' => '<name><value>' .
$this->values
['name'
] . '</value></name>',
'type' => '<type><value>entity_test_mulrev</value></type>',
'created' => '<created><value>' .
$expected_created['value'
] . '</value><format>' .
$expected_created['format'
] . '</format></created>',
'user_id' => '<user_id><target_id>' .
$this->user->
id() . '</target_id><target_type>' .
$this->user->
getEntityTypeId() . '</target_type><target_uuid>' .
$this->user->
uuid() . '</target_uuid><url>' .
$this->user->
toUrl()->
toString() . '</url></user_id>',