function JsonApiRegressionTest::testRecursionDetectedWhenResponseContainsViolationsFrom3042124
Same name in other branches
- 9 core/modules/jsonapi/tests/src/Functional/JsonApiRegressionTest.php \Drupal\Tests\jsonapi\Functional\JsonApiRegressionTest::testRecursionDetectedWhenResponseContainsViolationsFrom3042124()
- 8.9.x core/modules/jsonapi/tests/src/Functional/JsonApiRegressionTest.php \Drupal\Tests\jsonapi\Functional\JsonApiRegressionTest::testRecursionDetectedWhenResponseContainsViolationsFrom3042124()
- 11.x core/modules/jsonapi/tests/src/Functional/JsonApiRegressionTest.php \Drupal\Tests\jsonapi\Functional\JsonApiRegressionTest::testRecursionDetectedWhenResponseContainsViolationsFrom3042124()
Tests that the response still has meaningful error messages.
File
-
core/
modules/ jsonapi/ tests/ src/ Functional/ JsonApiRegressionTest.php, line 609
Class
- JsonApiRegressionTest
- JSON:API regression tests.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
public function testRecursionDetectedWhenResponseContainsViolationsFrom3042124() : void {
$this->config('jsonapi.settings')
->set('read_only', FALSE)
->save(TRUE);
// Set up default request.
$url = Url::fromUri('internal:/jsonapi/node/article');
$request_options = [
RequestOptions::HEADERS => [
'Content-Type' => 'application/vnd.api+json',
'Accept' => 'application/vnd.api+json',
],
RequestOptions::JSON => [
'data' => [
'type' => 'node--article',
'attributes' => [],
],
],
];
// Set up test users.
$user = $this->drupalCreateUser([
'bypass node access',
], 'Sam');
$admin = $this->drupalCreateUser([], 'Gandalf', TRUE);
// Make request as regular user.
$request_options[RequestOptions::AUTH] = [
$user->getAccountName(),
$user->pass_raw,
];
$this->request('POST', $url, $request_options);
$response = $this->request('POST', $url, $request_options);
// Assert that the response has a body.
$data = $this->getDocumentFromResponse($response, FALSE);
$this->assertSame(422, $response->getStatusCode());
$this->assertNotNull($data);
$this->assertSame(sprintf('title: This value should not be null.'), $data['errors'][0]['detail']);
// Make request as regular user.
$request_options[RequestOptions::AUTH] = [
$admin->getAccountName(),
$admin->pass_raw,
];
$this->request('POST', $url, $request_options);
$response = $this->request('POST', $url, $request_options);
// Assert that the response has a body.
$data = $this->getDocumentFromResponse($response, FALSE);
$this->assertSame(422, $response->getStatusCode());
$this->assertNotNull($data);
$this->assertSame(sprintf('title: This value should not be null.'), $data['errors'][0]['detail']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.