View source
<?php
namespace Drupal\Tests\jsonapi\Functional;
use Drupal\config_test\Entity\ConfigTest;
use Drupal\Core\Url;
class ConfigTestTest extends ResourceTestBase {
public static $modules = [
'config_test',
'config_test_rest',
];
protected static $entityTypeId = 'config_test';
protected static $resourceTypeName = 'config_test--config_test';
protected $entity;
protected function setUpAuthorization($method) {
$this
->grantPermissionsToTestedRole([
'view config_test',
]);
}
protected function getExpectedUnauthorizedAccessMessage($method) {
switch ($method) {
case 'GET':
return "The 'view config_test' permission is required.";
default:
return parent::getExpectedUnauthorizedAccessMessage($method);
}
}
protected function createEntity() {
$config_test = ConfigTest::create([
'id' => 'llama',
'label' => 'Llama',
]);
$config_test
->save();
return $config_test;
}
protected function getExpectedDocument() {
$self_url = Url::fromUri('base:/jsonapi/config_test/config_test/' . $this->entity
->uuid())
->setAbsolute()
->toString(TRUE)
->getGeneratedUrl();
return [
'jsonapi' => [
'meta' => [
'links' => [
'self' => 'http://jsonapi.org/format/1.0/',
],
],
'version' => '1.0',
],
'links' => [
'self' => $self_url,
],
'data' => [
'id' => $this->entity
->uuid(),
'type' => 'config_test--config_test',
'links' => [
'self' => $self_url,
],
'attributes' => [
'uuid' => $this->entity
->uuid(),
'id' => 'llama',
'weight' => 0,
'langcode' => 'en',
'status' => TRUE,
'dependencies' => [],
'label' => 'Llama',
'style' => NULL,
'size' => NULL,
'size_value' => NULL,
'protected_property' => NULL,
],
],
];
}
protected function getPostDocument() {
}
}