You are here

public function JsonApiDocumentTopLevelNormalizerTest::testDenormalize in JSON:API 8.2

Same name in this branch
  1. 8.2 tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Unit\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testDenormalize()
  2. 8.2 tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testDenormalize()
Same name and namespace in other branches
  1. 8 tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testDenormalize()

Try to POST a node and check if it exists afterwards.

@covers ::denormalize

File

tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php, line 446

Class

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

Namespace

Drupal\Tests\jsonapi\Kernel\Normalizer

Code

public function testDenormalize() {
  $payload = '{"data":{"type":"article","attributes":{"title":"Testing article"}}}';
  list($request, $resource_type) = $this
    ->generateProphecies('node', 'article', 'id');
  $node = $this
    ->getNormalizer()
    ->denormalize(Json::decode($payload), NULL, 'api_json', [
    'resource_type' => $resource_type,
  ]);
  $this
    ->assertInstanceOf(Node::class, $node);
  $this
    ->assertSame('Testing article', $node
    ->getTitle());
}