You are here

class NodeTypeTest in Drupal 10

Same name in this branch
  1. 10 core/modules/node/tests/src/Functional/NodeTypeTest.php \Drupal\Tests\node\Functional\NodeTypeTest
  2. 10 core/modules/jsonapi/tests/src/Functional/NodeTypeTest.php \Drupal\Tests\jsonapi\Functional\NodeTypeTest
Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/src/Functional/NodeTypeTest.php \Drupal\Tests\jsonapi\Functional\NodeTypeTest
  2. 9 core/modules/jsonapi/tests/src/Functional/NodeTypeTest.php \Drupal\Tests\jsonapi\Functional\NodeTypeTest

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

@group jsonapi

Hierarchy

Expanded class hierarchy of NodeTypeTest

File

core/modules/jsonapi/tests/src/Functional/NodeTypeTest.php, line 13

Namespace

Drupal\Tests\jsonapi\Functional
View source
class NodeTypeTest extends ConfigEntityResourceTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'node',
  ];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  protected static $entityTypeId = 'node_type';

  /**
   * {@inheritdoc}
   */
  protected static $resourceTypeName = 'node_type--node_type';

  /**
   * {@inheritdoc}
   *
   * @var \Drupal\node\NodeTypeInterface
   */
  protected $entity;

  /**
   * {@inheritdoc}
   */
  protected function setUpAuthorization($method) {
    $this
      ->grantPermissionsToTestedRole([
      'administer content types',
      'access content',
    ]);
  }

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

    // Create a "Camelids" node type.
    $camelids = NodeType::create([
      'name' => 'Camelids',
      'type' => 'camelids',
      'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.',
    ]);
    $camelids
      ->save();
    return $camelids;
  }

  /**
   * {@inheritdoc}
   */
  protected function getExpectedDocument() {
    $self_url = Url::fromUri('base:/jsonapi/node_type/node_type/' . $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' => 'node_type--node_type',
        'links' => [
          'self' => [
            'href' => $self_url,
          ],
        ],
        'attributes' => [
          'dependencies' => [],
          'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.',
          'display_submitted' => TRUE,
          'help' => NULL,
          'langcode' => 'en',
          'name' => 'Camelids',
          'new_revision' => TRUE,
          'preview_mode' => 1,
          'status' => TRUE,
          'drupal_internal__type' => 'camelids',
        ],
      ],
    ];
  }

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

    // @todo Update in https://www.drupal.org/node/2300677.
    return [];
  }

  /**
   * {@inheritdoc}
   */
  protected function getExpectedUnauthorizedAccessMessage($method) {
    return "The 'access content' permission is required.";
  }

}

Members