class DesignTokenTest

Same name in this branch
  1. 11.x core/tests/Drupal/Tests/Core/Theme/DesignToken/DesignTokenTest.php \Drupal\Tests\Core\Theme\DesignToken\DesignTokenTest
Same name and namespace in other branches
  1. main core/modules/jsonapi/tests/src/Functional/DesignTokenTest.php \Drupal\Tests\jsonapi\Functional\DesignTokenTest

JSON:API integration test for the "DesignToken" config entity type.

Attributes

#[Group('jsonapi')] #[RunTestsInSeparateProcesses]

Hierarchy

Expanded class hierarchy of DesignTokenTest

File

core/modules/jsonapi/tests/src/Functional/DesignTokenTest.php, line 16

Namespace

Drupal\Tests\jsonapi\Functional
View source
class DesignTokenTest extends ConfigEntityResourceTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [];
  
  /**
   * {@inheritdoc}
   */
  protected static $entityTypeId = 'design_token';
  
  /**
   * {@inheritdoc}
   */
  protected static $resourceTypeName = 'design_token--design_token';
  
  /**
   * {@inheritdoc}
   *
   * @var \Drupal\Core\Theme\Entity\DesignTokenInterface
   */
  protected $entity;
  
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';
  
  /**
   * {@inheritdoc}
   */
  protected function setUpAuthorization($method) : void {
    $this->grantPermissionsToTestedRole([
      'administer design tokens',
    ]);
  }
  
  /**
   * {@inheritdoc}
   */
  protected function createEntity() {
    // Create a design token.
    $entity = DesignToken::create([
      'id' => 'my_token',
      'path' => 'my-token',
      'type' => 'fontWeight',
      'scopes' => [
        ':root' => 500,
      ],
    ]);
    $entity->save();
    return $entity;
  }
  
  /**
   * {@inheritdoc}
   */
  protected function getExpectedDocument() : array {
    $self_url = Url::fromUri('base:/jsonapi/design_token/design_token/' . $this->entity
      ->uuid())
      ->setAbsolute()
      ->toString(TRUE)
      ->getGeneratedUrl();
    return [
      'jsonapi' => [
        'meta' => [
          'links' => [
            'self' => [
              'href' => JsonApiSpec::SUPPORTED_SPECIFICATION_PERMALINK,
            ],
          ],
        ],
        'version' => JsonApiSpec::SUPPORTED_SPECIFICATION_VERSION,
      ],
      'links' => [
        'self' => [
          'href' => $self_url,
        ],
      ],
      'data' => [
        'id' => $this->entity
          ->uuid(),
        'type' => 'design_token--design_token',
        'links' => [
          'self' => [
            'href' => $self_url,
          ],
        ],
        'attributes' => [
          'dependencies' => [],
          'langcode' => 'en',
          'status' => TRUE,
          'path' => 'my-token',
          'design_token_type' => 'fontWeight',
          'scopes' => [
            ':root' => '500',
          ],
          'drupal_internal__id' => 'my_token',
        ],
      ],
    ];
  }
  
  /**
   * {@inheritdoc}
   */
  protected function getPostDocument() : array {
    // @todo Update in https://www.drupal.org/node/2300677.
    return [];
  }

}

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