RoleTest.php

Same filename in this branch
  1. 10 core/modules/user/tests/src/Kernel/Plugin/migrate/source/d6/RoleTest.php
  2. 10 core/modules/user/tests/src/Kernel/Plugin/migrate/source/d7/RoleTest.php
Same filename and directory in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/RoleTest.php
  2. 9 core/modules/user/tests/src/Kernel/Plugin/migrate/source/d6/RoleTest.php
  3. 9 core/modules/user/tests/src/Kernel/Plugin/migrate/source/d7/RoleTest.php
  4. 8.9.x core/modules/jsonapi/tests/src/Functional/RoleTest.php
  5. 8.9.x core/modules/user/tests/src/Kernel/Plugin/migrate/source/d6/RoleTest.php
  6. 8.9.x core/modules/user/tests/src/Kernel/Plugin/migrate/source/d7/RoleTest.php
  7. 11.x core/modules/jsonapi/tests/src/Functional/RoleTest.php
  8. 11.x core/modules/user/tests/src/Kernel/Plugin/migrate/source/d6/RoleTest.php
  9. 11.x core/modules/user/tests/src/Kernel/Plugin/migrate/source/d7/RoleTest.php

Namespace

Drupal\Tests\jsonapi\Functional

File

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

View source
<?php

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

use Drupal\Core\Url;
use Drupal\user\Entity\Role;

/**
 * JSON:API integration test for the "Role" config entity type.
 *
 * @group jsonapi
 * @group #slow
 */
class RoleTest extends ConfigEntityResourceTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'user',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';
  
  /**
   * {@inheritdoc}
   */
  protected static $entityTypeId = 'user_role';
  
  /**
   * {@inheritdoc}
   */
  protected static $resourceTypeName = 'user_role--user_role';
  
  /**
   * {@inheritdoc}
   *
   * @var \Drupal\user\RoleInterface
   */
  protected $entity;
  
  /**
   * {@inheritdoc}
   */
  protected function setUpAuthorization($method) {
    $this->grantPermissionsToTestedRole([
      'administer permissions',
    ]);
  }
  
  /**
   * {@inheritdoc}
   */
  protected function createEntity() {
    $role = Role::create([
      'id' => 'llama',
      'label' => 'Llama',
    ]);
    $role->save();
    return $role;
  }
  
  /**
   * {@inheritdoc}
   */
  protected function getExpectedDocument() {
    $self_url = Url::fromUri('base:/jsonapi/user_role/user_role/' . $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' => 'user_role--user_role',
        'links' => [
          'self' => [
            'href' => $self_url,
          ],
        ],
        'attributes' => [
          'weight' => 2,
          'langcode' => 'en',
          'status' => TRUE,
          'dependencies' => [],
          'label' => 'Llama',
          'is_admin' => NULL,
          'permissions' => [],
          'drupal_internal__id' => 'llama',
        ],
      ],
    ];
  }
  
  /**
   * {@inheritdoc}
   */
  protected function getPostDocument() {
    // @todo Update in https://www.drupal.org/node/2300677.
    return [];
  }

}

Classes

Title Deprecated Summary
RoleTest JSON:API integration test for the "Role" config entity type.

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