ActionResourceTestBase.php

Same filename in this branch
  1. 11.x core/modules/action/tests/src/Functional/Rest/ActionResourceTestBase.php
Same filename and directory in other branches
  1. 9 core/modules/system/tests/src/Functional/Rest/ActionResourceTestBase.php
  2. 8.9.x core/modules/rest/tests/src/Functional/EntityResource/Action/ActionResourceTestBase.php
  3. 8.9.x core/modules/system/tests/src/Functional/Rest/ActionResourceTestBase.php
  4. 10 core/modules/action/tests/src/Functional/Rest/ActionResourceTestBase.php
  5. 10 core/modules/system/tests/src/Functional/Rest/ActionResourceTestBase.php

Namespace

Drupal\Tests\system\Functional\Rest

File

core/modules/system/tests/src/Functional/Rest/ActionResourceTestBase.php

View source
<?php

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

use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\rest\Functional\EntityResource\ConfigEntityResourceTestBase;
use Drupal\system\Entity\Action;
use Drupal\user\RoleInterface;

/**
 * Resource test base for the action entity.
 */
abstract class ActionResourceTestBase extends ConfigEntityResourceTestBase {
  use StringTranslationTrait;
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'user',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected static $entityTypeId = 'action';
  
  /**
   * @var \Drupal\system\ActionConfigEntityInterface
   */
  protected $entity;
  
  /**
   * {@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' => $this->t('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 getExpectedNormalizedEntity() {
    return [
      'configuration' => [
        'rid' => 'anonymous',
      ],
      'dependencies' => [
        'config' => [
          'user.role.anonymous',
        ],
        'module' => [
          'user',
        ],
      ],
      'id' => 'user_add_role_action.anonymous',
      'label' => 'Add the anonymous role to the selected users',
      'langcode' => 'en',
      'plugin' => 'user_add_role_action',
      'status' => TRUE,
      'type' => 'user',
      'uuid' => $this->entity
        ->uuid(),
    ];
  }
  
  /**
   * {@inheritdoc}
   */
  protected function getNormalizedPostEntity() {
    // @todo Update in https://www.drupal.org/node/2300677.
    return [];
  }
  
  /**
   * {@inheritdoc}
   */
  protected function getExpectedCacheContexts() {
    return [
      'user.permissions',
    ];
  }

}

Classes

Title Deprecated Summary
ActionResourceTestBase Resource test base for the action entity.

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