function JsonApiTopLevelResourceNormalizerTest::testDenormalize

Same name and namespace in other branches
  1. 11.x core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiTopLevelResourceNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiTopLevelResourceNormalizerTest::testDenormalize()

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

File

core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiTopLevelResourceNormalizerTest.php, line 573

Class

JsonApiTopLevelResourceNormalizerTest
Tests Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer.

Namespace

Drupal\Tests\jsonapi\Kernel\Normalizer

Code

public function testDenormalize() : void {
  $payload = '{"data":{"type":"article","attributes":{"title":"Testing article"}}}';
  $resource_type = $this->container
    ->get('jsonapi.resource_type.repository')
    ->get('node', 'article');
  $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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.