You are here

public function JsonApiDocumentTopLevelNormalizerTest::testNormalizeException in Drupal 8

@covers ::normalize

File

core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php, line 390

Class

JsonApiDocumentTopLevelNormalizerTest
@coversDefaultClass \Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer @group jsonapi

Namespace

Drupal\Tests\jsonapi\Kernel\Normalizer

Code

public function testNormalizeException() {
  $normalized = $this->container
    ->get('jsonapi.serializer')
    ->normalize(new JsonApiDocumentTopLevel(new ErrorCollection([
    new BadRequestHttpException('Lorem'),
  ]), new NullIncludedData(), new LinkCollection([])), 'api_json', [])
    ->getNormalization();
  $this
    ->assertNotEmpty($normalized['errors']);
  $this
    ->assertArrayNotHasKey('data', $normalized);
  $this
    ->assertEquals(400, $normalized['errors'][0]['status']);
  $this
    ->assertEquals('Lorem', $normalized['errors'][0]['detail']);
  $this
    ->assertEquals([
    'info' => [
      'href' => 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1',
    ],
    'via' => [
      'href' => 'http://localhost/',
    ],
  ], $normalized['errors'][0]['links']);
}