View source
<?php
namespace Drupal\Tests\jsonapi\Functional;
use Drupal\Core\Url;
use Drupal\node\Entity\NodeType;
class NodeTypeTest extends ResourceTestBase {
public static $modules = [
'node',
];
protected static $entityTypeId = 'node_type';
protected static $resourceTypeName = 'node_type--node_type';
protected $entity;
protected function setUpAuthorization($method) {
$this
->grantPermissionsToTestedRole([
'administer content types',
'access content',
]);
}
protected function createEntity() {
$camelids = NodeType::create([
'name' => 'Camelids',
'type' => 'camelids',
'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.',
]);
$camelids
->save();
return $camelids;
}
protected function getExpectedDocument() {
$self_url = Url::fromUri('base:/jsonapi/node_type/node_type/' . $this->entity
->uuid())
->setAbsolute()
->toString(TRUE)
->getGeneratedUrl();
return [
'jsonapi' => [
'meta' => [
'links' => [
'self' => [
'href' => 'http://jsonapi.org/format/1.0/',
],
],
],
'version' => '1.0',
],
'links' => [
'self' => [
'href' => $self_url,
],
],
'data' => [
'id' => $this->entity
->uuid(),
'type' => 'node_type--node_type',
'links' => [
'self' => [
'href' => $self_url,
],
],
'attributes' => [
'dependencies' => [],
'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.',
'display_submitted' => TRUE,
'help' => NULL,
'langcode' => 'en',
'name' => 'Camelids',
'new_revision' => TRUE,
'preview_mode' => 1,
'status' => TRUE,
'drupal_internal__type' => 'camelids',
],
],
];
}
protected function getPostDocument() {
}
protected function getExpectedUnauthorizedAccessMessage($method) {
return "The 'access content' permission is required.";
}
}