protected function EntityToJsonApiTest::assertEntity in JSON:API Extras 8.3
Same name and namespace in other branches
- 8.2 tests/src/Kernel/EntityToJsonApiTest.php \Drupal\Tests\jsonapi_extras\Kernel\EntityToJsonApiTest::assertEntity()
Checks entity's serialization/normalization.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity to serialize/normalize.
string[] $include_fields: The list of fields to include.
array[] $expected_includes: The list of partial structures of the "included" key.
1 call to EntityToJsonApiTest::assertEntity()
- EntityToJsonApiTest::testSerialize in tests/
src/ Kernel/ EntityToJsonApiTest.php - @covers ::serialize @covers ::normalize
File
- tests/
src/ Kernel/ EntityToJsonApiTest.php, line 237
Class
- EntityToJsonApiTest
- @coversDefaultClass \Drupal\jsonapi_extras\EntityToJsonApi @group jsonapi @group jsonapi_serializer @group legacy
Namespace
Drupal\Tests\jsonapi_extras\KernelCode
protected function assertEntity(EntityInterface $entity, array $include_fields = [], array $expected_includes = []) {
$output = $this->sut
->serialize($entity, $include_fields);
$this
->assertTrue(is_string($output));
$this
->assertJsonApi(Json::decode($output));
$output = $this->sut
->normalize($entity, $include_fields);
$this
->assertTrue(is_array($output));
$this
->assertJsonApi($output);
// Check the includes if they were passed.
if (!empty($include_fields)) {
$this
->assertJsonApiIncludes($output, $expected_includes);
}
}