You are here

protected function JsonApiFunctionalTestBase::setUp in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalTestBase.php \Drupal\Tests\jsonapi\Functional\JsonApiFunctionalTestBase::setUp()

Overrides BrowserTestBase::setUp

1 call to JsonApiFunctionalTestBase::setUp()
JsonApiFunctionalMultilingualTest::setUp in core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalMultilingualTest.php
1 method overrides JsonApiFunctionalTestBase::setUp()
JsonApiFunctionalMultilingualTest::setUp in core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalMultilingualTest.php

File

core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalTestBase.php, line 95

Class

JsonApiFunctionalTestBase
Provides helper methods for the JSON:API module's functional tests.

Namespace

Drupal\Tests\jsonapi\Functional

Code

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

  // Set up a HTTP client that accepts relative URLs.
  $this->httpClient = $this->container
    ->get('http_client_factory')
    ->fromOptions([
    'base_uri' => $this->baseUrl,
  ]);

  // Create Basic page and Article node types.
  if ($this->profile != 'standard') {
    $this
      ->drupalCreateContentType([
      'type' => 'article',
      'name' => 'Article',
    ]);

    // Setup vocabulary.
    Vocabulary::create([
      'vid' => 'tags',
      'name' => 'Tags',
    ])
      ->save();

    // Add tags and field_image to the article.
    $this
      ->createEntityReferenceField('node', 'article', 'field_tags', 'Tags', 'taxonomy_term', 'default', [
      'target_bundles' => [
        'tags' => 'tags',
      ],
      'auto_create' => TRUE,
    ], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
    $this
      ->createImageField('field_image', 'article');
    $this
      ->createImageField('field_heroless', 'article');
  }
  FieldStorageConfig::create([
    'field_name' => 'field_link',
    'entity_type' => 'node',
    'type' => 'link',
    'settings' => [],
    'cardinality' => 1,
  ])
    ->save();
  $field_config = FieldConfig::create([
    'field_name' => 'field_link',
    'label' => 'Link',
    'entity_type' => 'node',
    'bundle' => 'article',
    'required' => FALSE,
    'settings' => [],
    'description' => '',
  ]);
  $field_config
    ->save();

  // Field for testing sorting.
  FieldStorageConfig::create([
    'field_name' => 'field_sort1',
    'entity_type' => 'node',
    'type' => 'integer',
  ])
    ->save();
  FieldConfig::create([
    'field_name' => 'field_sort1',
    'entity_type' => 'node',
    'bundle' => 'article',
  ])
    ->save();

  // Another field for testing sorting.
  FieldStorageConfig::create([
    'field_name' => 'field_sort2',
    'entity_type' => 'node',
    'type' => 'integer',
  ])
    ->save();
  FieldConfig::create([
    'field_name' => 'field_sort2',
    'entity_type' => 'node',
    'bundle' => 'article',
  ])
    ->save();
  $this->user = $this
    ->drupalCreateUser([
    'create article content',
    'edit any article content',
    'delete any article content',
  ]);

  // Create a user that can.
  $this->userCanViewProfiles = $this
    ->drupalCreateUser([
    'access user profiles',
  ]);
  $this
    ->grantPermissions(Role::load(RoleInterface::ANONYMOUS_ID), [
    'access user profiles',
    'administer taxonomy',
  ]);
  drupal_flush_all_caches();
}