You are here

RoleTest.php in JSON:API 8

Same filename and directory in other branches
  1. 8.2 tests/src/Functional/RoleTest.php

File

tests/src/Functional/RoleTest.php
View source
<?php

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
 */
class RoleTest extends ResourceTestBase {

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'user',
  ];

  /**
   * {@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',
      'name' => $this
        ->randomString(),
    ]);
    $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' => 'http://jsonapi.org/format/1.0/',
          ],
        ],
        'version' => '1.0',
      ],
      'links' => [
        'self' => $self_url,
      ],
      'data' => [
        'id' => $this->entity
          ->uuid(),
        'type' => 'user_role--user_role',
        'links' => [
          'self' => $self_url,
        ],
        'attributes' => [
          'uuid' => $this->entity
            ->uuid(),
          'weight' => 2,
          'langcode' => 'en',
          'status' => TRUE,
          'dependencies' => [],
          'id' => 'llama',
          'label' => NULL,
          'is_admin' => NULL,
          'permissions' => [],
        ],
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  protected function getPostDocument() {

    // @todo Update in https://www.drupal.org/node/2300677.
  }

}

Classes

Namesort descending Description
RoleTest JSON API integration test for the "Role" config entity type.