function NodeTest::testGetIndividual
Same name in other branches
- 9 core/modules/jsonapi/tests/src/Functional/NodeTest.php \Drupal\Tests\jsonapi\Functional\NodeTest::testGetIndividual()
- 8.9.x core/modules/jsonapi/tests/src/Functional/NodeTest.php \Drupal\Tests\jsonapi\Functional\NodeTest::testGetIndividual()
- 10 core/modules/jsonapi/tests/src/Functional/NodeTest.php \Drupal\Tests\jsonapi\Functional\NodeTest::testGetIndividual()
Overrides ResourceTestBase::testGetIndividual
File
-
core/
modules/ jsonapi/ tests/ src/ Functional/ NodeTest.php, line 321
Class
- NodeTest
- JSON:API integration test for the "Node" content entity type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
public function testGetIndividual() : void {
// Cacheable normalizations are written after the response is flushed to
// the client. We use WaitTerminateTestTrait to wait for Drupal to perform
// its termination work before continuing.
$this->setWaitForTerminate();
parent::testGetIndividual();
$this->assertCacheableNormalizations();
// Unpublish node.
$this->entity
->setUnpublished()
->save();
// @todo Remove line below in favor of commented line in https://www.drupal.org/project/drupal/issues/2878463.
$url = Url::fromRoute(sprintf('jsonapi.%s.individual', static::$resourceTypeName), [
'entity' => $this->entity
->uuid(),
]);
// $url = $this->entity->toUrl('jsonapi');
$request_options = $this->getAuthenticationRequestOptions();
// 403 when accessing own unpublished node.
$response = $this->request('GET', $url, $request_options);
$this->assertResourceErrorResponse(403, 'The current user is not allowed to GET the selected resource.', $url, $response, '/data', [
'4xx-response',
'http_response',
'node:1',
], [
'url.query_args',
'url.site',
'user.permissions',
], 'UNCACHEABLE (request policy)', TRUE);
// 200 after granting permission.
$this->grantPermissionsToTestedRole([
'view own unpublished content',
]);
$response = $this->request('GET', $url, $request_options);
$this->assertResourceResponse(200, FALSE, $response, $this->getExpectedCacheTags(), $this->getExpectedCacheContexts(), 'UNCACHEABLE (request policy)', TRUE);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.