ActionTest.php

Same filename in this branch
  1. 11.x core/modules/action/tests/src/Functional/Jsonapi/ActionTest.php
  2. 11.x core/modules/system/tests/src/Kernel/Action/ActionTest.php
  3. 11.x core/modules/system/tests/src/Kernel/Plugin/migrate/source/ActionTest.php
Same filename in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/ActionTest.php
  2. 9 core/modules/action/tests/src/Unit/Plugin/migrate/source/ActionTest.php
  3. 9 core/modules/system/tests/src/Kernel/Action/ActionTest.php
  4. 9 core/modules/system/tests/src/Kernel/Plugin/migrate/source/ActionTest.php
  5. 8.9.x core/modules/jsonapi/tests/src/Functional/ActionTest.php
  6. 8.9.x core/modules/action/tests/src/Kernel/Plugin/migrate/source/ActionTest.php
  7. 8.9.x core/modules/system/tests/src/Kernel/Action/ActionTest.php
  8. 10 core/modules/action/tests/src/Functional/Jsonapi/ActionTest.php
  9. 10 core/modules/system/tests/src/Kernel/Action/ActionTest.php
  10. 10 core/modules/system/tests/src/Kernel/Plugin/migrate/source/ActionTest.php
  11. 10 core/modules/jsonapi/tests/src/Functional/ActionTest.php

Namespace

Drupal\Tests\jsonapi\Functional

File

core/modules/jsonapi/tests/src/Functional/ActionTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\jsonapi\Functional;

use Drupal\Core\Url;
use Drupal\system\Entity\Action;
use Drupal\user\RoleInterface;

/**
 * JSON:API integration test for the "Action" config entity type.
 *
 * @group Action
 */
class ActionTest extends ConfigEntityResourceTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [];
    
    /**
     * {@inheritdoc}
     */
    protected static $entityTypeId = 'action';
    
    /**
     * {@inheritdoc}
     */
    protected static $resourceTypeName = 'action--action';
    
    /**
     * {@inheritdoc}
     *
     * @var \Drupal\system\ActionConfigEntityInterface
     */
    protected $entity;
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * {@inheritdoc}
     */
    protected function setUpAuthorization($method) {
        $this->grantPermissionsToTestedRole([
            'administer actions',
        ]);
    }
    
    /**
     * {@inheritdoc}
     */
    protected function createEntity() {
        $action = Action::create([
            'id' => 'user_add_role_action.' . RoleInterface::ANONYMOUS_ID,
            'type' => 'user',
            'label' => 'Add the anonymous role to the selected users',
            'configuration' => [
                'rid' => RoleInterface::ANONYMOUS_ID,
            ],
            'plugin' => 'user_add_role_action',
        ]);
        $action->save();
        return $action;
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getExpectedDocument() : array {
        $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',
                ],
            ],
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getPostDocument() : array {
        // @todo Update in https://www.drupal.org/node/2300677.
        return [];
    }

}

Classes

Title Deprecated Summary
ActionTest JSON:API integration test for the "Action" config entity type.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.