You are here

protected static function JsonExtrasApiFunctionalTest::overrideResources in JSON:API Extras 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/JsonExtrasApiFunctionalTest.php \Drupal\Tests\jsonapi_extras\Functional\JsonExtrasApiFunctionalTest::overrideResources()

Creates the JSON API Resource Config entities to override the resources.

1 call to JsonExtrasApiFunctionalTest::overrideResources()
JsonExtrasApiFunctionalTest::setUp in tests/src/Functional/JsonExtrasApiFunctionalTest.php

File

tests/src/Functional/JsonExtrasApiFunctionalTest.php, line 293

Class

JsonExtrasApiFunctionalTest
The test class for the main functionality.

Namespace

Drupal\Tests\jsonapi_extras\Functional

Code

protected static function overrideResources() {

  // Disable the user resource.
  JsonapiResourceConfig::create([
    'id' => 'taxonomy_vocabulary--taxonomy_vocabulary',
    'disabled' => TRUE,
    'path' => 'taxonomy_vocabulary/taxonomy_vocabulary',
    'resourceType' => 'taxonomy_vocabulary--taxonomy_vocabulary',
  ])
    ->save();

  // Override paths and fields in the articles resource.
  JsonapiResourceConfig::create([
    'id' => 'node--article',
    'disabled' => FALSE,
    'path' => 'articles',
    'resourceType' => 'articles',
    'resourceFields' => [
      'nid' => [
        'fieldName' => 'nid',
        'publicName' => 'internalId',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => FALSE,
      ],
      'uuid' => [
        'fieldName' => 'uuid',
        'publicName' => 'uuid',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => TRUE,
      ],
      'vid' => [
        'fieldName' => 'vid',
        'publicName' => 'vid',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => TRUE,
      ],
      'langcode' => [
        'fieldName' => 'langcode',
        'publicName' => 'langcode',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => TRUE,
      ],
      'type' => [
        'fieldName' => 'type',
        'publicName' => 'contentType',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => FALSE,
      ],
      'status' => [
        'fieldName' => 'status',
        'publicName' => 'isPublished',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => FALSE,
      ],
      'title' => [
        'fieldName' => 'title',
        'publicName' => 'title',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => FALSE,
      ],
      'uid' => [
        'fieldName' => 'uid',
        'publicName' => 'owner',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => FALSE,
      ],
      'created' => [
        'fieldName' => 'created',
        'publicName' => 'createdAt',
        'enhancer' => [
          'id' => 'date_time',
          'settings' => [
            'dateTimeFormat' => 'Y-m-d\\TH:i:sO',
          ],
        ],
        'disabled' => FALSE,
      ],
      'changed' => [
        'fieldName' => 'changed',
        'publicName' => 'updatedAt',
        'enhancer' => [
          'id' => 'date_time',
          'settings' => [
            'dateTimeFormat' => 'Y-m-d\\TH:i:sO',
          ],
        ],
        'disabled' => FALSE,
      ],
      'promote' => [
        'fieldName' => 'promote',
        'publicName' => 'isPromoted',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => FALSE,
      ],
      'sticky' => [
        'fieldName' => 'sticky',
        'publicName' => 'sticky',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => TRUE,
      ],
      'revision_timestamp' => [
        'fieldName' => 'revision_timestamp',
        'publicName' => 'revision_timestamp',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => TRUE,
      ],
      'revision_uid' => [
        'fieldName' => 'revision_uid',
        'publicName' => 'revision_uid',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => TRUE,
      ],
      'revision_log' => [
        'fieldName' => 'revision_log',
        'publicName' => 'revision_log',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => TRUE,
      ],
      'revision_translation_affected' => [
        'fieldName' => 'revision_translation_affected',
        'publicName' => 'revision_translation_affected',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => TRUE,
      ],
      'default_langcode' => [
        'fieldName' => 'default_langcode',
        'publicName' => 'default_langcode',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => TRUE,
      ],
      'path' => [
        'fieldName' => 'path',
        'publicName' => 'path',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => FALSE,
      ],
      'body' => [
        'fieldName' => 'body',
        'publicName' => 'body',
        'enhancer' => [
          'id' => 'nested',
          'settings' => [
            'path' => 'value',
          ],
        ],
        'disabled' => FALSE,
      ],
      'field_link' => [
        'fieldName' => 'field_link',
        'publicName' => 'link',
        'enhancer' => [
          'id' => 'uuid_link',
        ],
        'disabled' => FALSE,
      ],
      'field_timestamp' => [
        'fieldName' => 'field_timestamp',
        'publicName' => 'timestamp',
        'enhancer' => [
          'id' => 'date_time',
          'settings' => [
            'dateTimeFormat' => 'Y-m-d\\TH:i:sO',
          ],
        ],
        'disabled' => FALSE,
      ],
      'comment' => [
        'fieldName' => 'comment',
        'publicName' => 'comment',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => FALSE,
      ],
      'field_image' => [
        'fieldName' => 'field_image',
        'publicName' => 'image',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => FALSE,
      ],
      'field_recipes' => [
        'fieldName' => 'field_recipes',
        'publicName' => 'recipes',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => FALSE,
      ],
      'field_tags' => [
        'fieldName' => 'field_tags',
        'publicName' => 'tags',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => FALSE,
      ],
    ],
  ])
    ->save();

  // Override the resource type in the node_type resource.
  JsonapiResourceConfig::create([
    'id' => 'node_type--node_type',
    'disabled' => FALSE,
    'path' => 'contentTypes',
    'resourceType' => 'contentTypes',
    'resourceFields' => [
      'type' => [
        'fieldName' => 'type',
        'publicName' => 'machineName',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => FALSE,
      ],
      'status' => [
        'fieldName' => 'status',
        'publicName' => 'isEnabled',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => FALSE,
      ],
      'langcode' => [
        'fieldName' => 'langcode',
        'publicName' => 'langcode',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => TRUE,
      ],
      'uuid' => [
        'fieldName' => 'uuid',
        'publicName' => 'uuid',
        'enhancer' => [
          'id' => '',
        ],
        'disabled' => TRUE,
      ],
    ],
  ])
    ->save();
}