View source
<?php
namespace Drupal\Tests\jsonapi\Functional;
use Drupal\Core\Url;
use Drupal\shortcut\Entity\ShortcutSet;
class ShortcutSetTest extends ResourceTestBase {
public static $modules = [
'shortcut',
];
protected static $entityTypeId = 'shortcut_set';
protected static $resourceTypeName = 'shortcut_set--shortcut_set';
protected $entity;
protected function setUpAuthorization($method) {
switch ($method) {
case 'GET':
$this
->grantPermissionsToTestedRole([
'access shortcuts',
]);
break;
case 'POST':
case 'PATCH':
$this
->grantPermissionsToTestedRole([
'access shortcuts',
'customize shortcut links',
]);
break;
case 'DELETE':
$this
->grantPermissionsToTestedRole([
'administer shortcuts',
]);
break;
}
}
protected function getExpectedUnauthorizedAccessMessage($method) {
switch ($method) {
case 'GET':
return "The 'access shortcuts' permission is required.";
default:
return parent::getExpectedUnauthorizedAccessMessage($method);
}
}
protected function createEntity() {
$set = ShortcutSet::create([
'id' => 'llama_set',
'label' => 'Llama Set',
]);
$set
->save();
return $set;
}
protected function getExpectedDocument() {
$self_url = Url::fromUri('base:/jsonapi/shortcut_set/shortcut_set/' . $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' => 'shortcut_set--shortcut_set',
'links' => [
'self' => [
'href' => $self_url,
],
],
'attributes' => [
'label' => 'Llama Set',
'status' => TRUE,
'langcode' => 'en',
'dependencies' => [],
'drupal_internal__id' => 'llama_set',
],
],
];
}
protected function getPostDocument() {
}
}