You are here

protected function JsonExtrasApiFunctionalTest::setUp 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::setUp()

Overrides JsonApiFunctionalTestBase::setUp

File

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

Class

JsonExtrasApiFunctionalTest
The test class for the main functionality.

Namespace

Drupal\Tests\jsonapi_extras\Functional

Code

protected function setUp() {
  parent::setUp();

  // Add vocabs field to the tags.
  $this
    ->createEntityReferenceField('taxonomy_term', 'tags', 'vocabs', 'Vocabularies', 'taxonomy_vocabulary', 'default', [
    'target_bundles' => [
      'tags' => 'taxonomy_vocabulary',
    ],
    'auto_create' => TRUE,
  ], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  FieldStorageConfig::create([
    'field_name' => 'field_timestamp',
    'entity_type' => 'node',
    'type' => 'timestamp',
    'settings' => [],
    'cardinality' => 1,
  ])
    ->save();
  $field_config = FieldConfig::create([
    'field_name' => 'field_timestamp',
    'label' => 'Timestamp',
    'entity_type' => 'node',
    'bundle' => 'article',
    'required' => FALSE,
    'settings' => [],
    'description' => '',
  ]);
  $field_config
    ->save();
  $config = \Drupal::configFactory()
    ->getEditable('jsonapi_extras.settings');
  $config
    ->set('path_prefix', 'api');
  $config
    ->set('include_count', TRUE);
  $config
    ->save(TRUE);
  $this
    ->grantPermissions(Role::load(Role::ANONYMOUS_ID), [
    'access jsonapi resource list',
  ]);
  static::overrideResources();
  $this
    ->resetAll();
  $role = $this->user
    ->get('roles')[0]->entity;
  $this
    ->grantPermissions($role, [
    'administer nodes',
    'administer site configuration',
  ]);
}