You are here

BlockContentTypeTest.php in JSON:API 8

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

File

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

namespace Drupal\Tests\jsonapi\Functional;

use Drupal\block_content\Entity\BlockContentType;
use Drupal\Core\Url;

/**
 * JSON API integration test for the "BlockContentType" config entity type.
 *
 * @group jsonapi
 */
class BlockContentTypeTest extends ResourceTestBase {

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

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

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

  /**
   * {@inheritdoc}
   *
   * @var \Drupal\block_content\BlockContentTypeInterface
   */
  protected $entity;

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

  /**
   * {@inheritdoc}
   */
  protected function createEntity() {
    $block_content_type = BlockContentType::create([
      'id' => 'pascal',
      'label' => 'Pascal',
      'revision' => FALSE,
      'description' => 'Provides a competitive alternative to the "basic" type',
    ]);
    $block_content_type
      ->save();
    return $block_content_type;
  }

  /**
   * {@inheritdoc}
   */
  protected function getExpectedDocument() {
    $self_url = Url::fromUri('base:/jsonapi/block_content_type/block_content_type/' . $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' => 'block_content_type--block_content_type',
        'links' => [
          'self' => $self_url,
        ],
        'attributes' => [
          'dependencies' => [],
          'description' => 'Provides a competitive alternative to the "basic" type',
          'id' => 'pascal',
          'label' => 'Pascal',
          'langcode' => 'en',
          'revision' => 0,
          'status' => TRUE,
          'uuid' => $this->entity
            ->uuid(),
        ],
      ],
    ];
  }

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

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

}

Classes

Namesort descending Description
BlockContentTypeTest JSON API integration test for the "BlockContentType" config entity type.