You are here

final class RequestTestJsonapi in OpenAPI for JSON:API 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/RequestTestJsonapi.php \Drupal\Tests\openapi_jsonapi\Functional\RequestTestJsonapi

REST tests for requests on OpenAPI routes.

@group openapi_jsonapi

Hierarchy

  • class \Drupal\Tests\openapi_jsonapi\Functional\RequestTestJsonapi extends \Drupal\Tests\openapi\Functional\RequestTestBase

Expanded class hierarchy of RequestTestJsonapi

File

tests/src/Functional/RequestTestJsonapi.php, line 12

Namespace

Drupal\Tests\openapi_jsonapi\Functional
View source
final class RequestTestJsonapi extends RequestTestBase {

  /**
   * The API module being tested.
   */
  const API_MODULE = 'jsonapi';

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'field',
    'filter',
    'text',
    'taxonomy',
    'serialization',
    'jsonapi',
    'schemata',
    'schemata_json_schema',
    'openapi',
    'openapi_test',
    'openapi_jsonapi',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    \Drupal::service('router.builder')
      ->rebuild();
  }

  /**
   * Tests OpenAPI requests.
   *
   * @dataProvider providerRequestTypes
   */
  public function testRequests($api_module, $options = []) {
    $this
      ->requestOpenApiJson($api_module, $options);
  }

  /**
   * {@inheritdoc}
   */
  protected function getRouteBase() {
    return ltrim(\Drupal::getContainer()
      ->getParameter('jsonapi.base_path'), '/');
  }

  /**
   * {@inheritdoc}
   */
  protected function assertMimeType(array $actual, array $options = []) {
    $this
      ->assertEquals([
      'application/vnd.api+json',
    ], $actual, "JSON:API root should only contain application/vnd.api+json");
  }

  /**
   * Builds the expectations directory.
   *
   * @return string
   *   The expectations directory.
   */
  protected function buildExpectationsDirectory() {
    return sprintf('%s/expectations/%s', dirname(dirname(__DIR__)), static::API_MODULE);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RequestTestJsonapi::$modules public static property
RequestTestJsonapi::API_MODULE constant The API module being tested.
RequestTestJsonapi::assertMimeType protected function
RequestTestJsonapi::buildExpectationsDirectory protected function Builds the expectations directory.
RequestTestJsonapi::getRouteBase protected function
RequestTestJsonapi::setUp protected function
RequestTestJsonapi::testRequests public function Tests OpenAPI requests.