View source
<?php
namespace Drupal\Tests\jsonapi\Functional;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Url;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\ResourceTestBase;
class RestJsonApiUnsupported extends ResourceTestBase {
use AnonResourceTestTrait;
protected static $modules = [
'jsonapi',
'node',
];
protected $defaultTheme = 'stark';
protected static $format = 'api_json';
protected static $mimeType = 'application/vnd.api+json';
protected static $resourceConfigId = 'entity.node';
protected function setUpAuthorization($method) {
switch ($method) {
case 'GET':
$this
->grantPermissionsToTestedRole([
'access content',
]);
break;
default:
throw new \UnexpectedValueException();
}
}
protected function setUp() : void {
parent::setUp();
$this->httpClient = $this->container
->get('http_client_factory')
->fromOptions([
'base_uri' => $this->baseUrl,
]);
NodeType::create([
'name' => 'Camelids',
'type' => 'camelids',
])
->save();
$node = Node::create([
'type' => 'camelids',
]);
$node
->setTitle('Llama')
->setOwnerId(0)
->setPublished()
->save();
}
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:user.role.anonymous',
'http_response',
'node:1',
], [
'url.query_args:_format',
'url.site',
'user.permissions',
], 'MISS', 'MISS');
}
protected function assertNormalizationEdgeCases($method, Url $url, array $request_options) : void {
}
protected function getExpectedUnauthorizedAccessMessage($method) {
return '';
}
protected function getExpectedUnauthorizedAccessCacheability() {
return new CacheableMetadata();
}
}