class RestJsonApiUnsupported
Same name and namespace in other branches
- 10 core/modules/jsonapi/tests/src/Functional/RestJsonApiUnsupported.php \Drupal\Tests\jsonapi\Functional\RestJsonApiUnsupported
- 8.9.x core/modules/jsonapi/tests/src/Functional/RestJsonApiUnsupported.php \Drupal\Tests\jsonapi\Functional\RestJsonApiUnsupported
Ensures that the 'api_json' format is not supported by the REST module.
@group jsonapi
@internal
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\rest\Functional\ResourceTestBase extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\jsonapi\Functional\RestJsonApiUnsupported uses \Drupal\Tests\rest\Functional\AnonResourceTestTrait extends \Drupal\Tests\rest\Functional\ResourceTestBase
- class \Drupal\Tests\rest\Functional\ResourceTestBase extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of RestJsonApiUnsupported
File
-
core/
modules/ jsonapi/ tests/ src/ Functional/ RestJsonApiUnsupported.php, line 19
Namespace
Drupal\Tests\jsonapi\FunctionalView source
class RestJsonApiUnsupported extends ResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'jsonapi',
'node',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected static $format = 'api_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/vnd.api+json';
/**
* {@inheritdoc}
*/
protected static $resourceConfigId = 'entity.node';
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
switch ($method) {
case 'GET':
$this->grantPermissionsToTestedRole([
'access content',
]);
break;
default:
throw new \UnexpectedValueException();
}
}
/**
* {@inheritdoc}
*/
public function setUp() : void {
parent::setUp();
$this->config('system.logging')
->set('error_level', ERROR_REPORTING_HIDE)
->save();
// Create a "Camelids" node type.
NodeType::create([
'name' => 'Camelids',
'type' => 'camelids',
])->save();
// Create a "Llama" node.
$node = Node::create([
'type' => 'camelids',
]);
$node->setTitle('Llama')
->setOwnerId(0)
->setPublished()
->save();
}
/**
* Deploying a REST resource using api_json format results in 400 responses.
*
* @see \Drupal\jsonapi\EventSubscriber\JsonApiRequestValidator::validateQueryParams()
*/
public function testApiJsonNotSupportedInRest() {
$this->assertSame([
'json',
'xml',
], $this->container
->getParameter('serializer.formats'));
$this->provisionResource([
'api_json',
], []);
$this->setUpAuthorization('GET');
$url = Node::load(1)->toUrl()
->setOption('query', [
'_format' => 'api_json',
]);
$request_options = [];
$response = $this->request('GET', $url, $request_options);
$this->assertResourceErrorResponse(400, FALSE, $response, [
'4xx-response',
'config:system.logging',
'config:user.role.anonymous',
'http_response',
'node:1',
], [
'url.query_args:_format',
'url.site',
'user.permissions',
], 'MISS', 'MISS');
}
/**
* {@inheritdoc}
*/
protected function assertNormalizationEdgeCases($method, Url $url, array $request_options) : void {
}
/**
* {@inheritdoc}
*/
protected function getExpectedUnauthorizedAccessMessage($method) {
return '';
}
/**
* {@inheritdoc}
*/
protected function getExpectedUnauthorizedAccessCacheability() {
return new CacheableMetadata();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.