class DesignTokenTest
Same name in this branch
- 11.x core/tests/Drupal/Tests/Core/Theme/DesignToken/DesignTokenTest.php \Drupal\Tests\Core\Theme\DesignToken\DesignTokenTest
Same name and namespace in other branches
- 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
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\jsonapi\Functional\ResourceTestBase uses \Drupal\Tests\jsonapi\Functional\ResourceResponseTestTrait, \Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait, \Drupal\Tests\jsonapi\Traits\GetDocumentFromResponseTrait, \Drupal\Tests\jsonapi\Functional\JsonApiRequestTestTrait extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\jsonapi\Functional\ConfigEntityResourceTestBase extends \Drupal\Tests\jsonapi\Functional\ResourceTestBase
- class \Drupal\Tests\jsonapi\Functional\DesignTokenTest extends \Drupal\Tests\jsonapi\Functional\ConfigEntityResourceTestBase
- class \Drupal\Tests\jsonapi\Functional\ConfigEntityResourceTestBase extends \Drupal\Tests\jsonapi\Functional\ResourceTestBase
- class \Drupal\Tests\jsonapi\Functional\ResourceTestBase uses \Drupal\Tests\jsonapi\Functional\ResourceResponseTestTrait, \Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait, \Drupal\Tests\jsonapi\Traits\GetDocumentFromResponseTrait, \Drupal\Tests\jsonapi\Functional\JsonApiRequestTestTrait extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of DesignTokenTest
File
-
core/
modules/ jsonapi/ tests/ src/ Functional/ DesignTokenTest.php, line 16
Namespace
Drupal\Tests\jsonapi\FunctionalView 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.