View source
<?php
namespace Drupal\Tests\jsonapi\Functional;
use Drupal\Core\Url;
use Drupal\system\Entity\Action;
use Drupal\user\RoleInterface;
class ActionTest extends ResourceTestBase {
protected static $modules = [
'action',
];
protected static $entityTypeId = 'action';
protected static $resourceTypeName = 'action--action';
protected $entity;
protected $defaultTheme = 'stark';
protected function setUpAuthorization($method) {
$this
->grantPermissionsToTestedRole([
'administer actions',
]);
}
protected function createEntity() {
$action = Action::create([
'id' => 'user_add_role_action.' . RoleInterface::ANONYMOUS_ID,
'type' => 'user',
'label' => t('Add the anonymous role to the selected users'),
'configuration' => [
'rid' => RoleInterface::ANONYMOUS_ID,
],
'plugin' => 'user_add_role_action',
]);
$action
->save();
return $action;
}
protected function getExpectedDocument() {
$self_url = Url::fromUri('base:/jsonapi/action/action/' . $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' => 'action--action',
'links' => [
'self' => [
'href' => $self_url,
],
],
'attributes' => [
'configuration' => [
'rid' => 'anonymous',
],
'dependencies' => [
'config' => [
'user.role.anonymous',
],
'module' => [
'user',
],
],
'label' => 'Add the anonymous role to the selected users',
'langcode' => 'en',
'plugin' => 'user_add_role_action',
'status' => TRUE,
'action_type' => 'user',
'drupal_internal__id' => 'user_add_role_action.anonymous',
],
],
];
}
protected function getPostDocument() {
}
}