function JsonApiFunctionalTestBase::setUp

Same name in other branches
  1. 8.9.x core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalTestBase.php \Drupal\Tests\jsonapi\Functional\JsonApiFunctionalTestBase::setUp()
  2. 10 core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalTestBase.php \Drupal\Tests\jsonapi\Functional\JsonApiFunctionalTestBase::setUp()
  3. 11.x core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalTestBase.php \Drupal\Tests\jsonapi\Functional\JsonApiFunctionalTestBase::setUp()

Overrides BrowserTestBase::setUp

2 calls to JsonApiFunctionalTestBase::setUp()
JsonApiFunctionalDateFieldTest::setUp in core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalDateFieldTest.php
JsonApiFunctionalMultilingualTest::setUp in core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalMultilingualTest.php
2 methods override JsonApiFunctionalTestBase::setUp()
JsonApiFunctionalDateFieldTest::setUp in core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalDateFieldTest.php
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::service('router.builder')->rebuild();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.