function JsonApiFunctionalTestBase::setUp
Same name in other branches
- 9 core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalTestBase.php \Drupal\Tests\jsonapi\Functional\JsonApiFunctionalTestBase::setUp()
- 8.9.x core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalTestBase.php \Drupal\Tests\jsonapi\Functional\JsonApiFunctionalTestBase::setUp()
- 11.x core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalTestBase.php \Drupal\Tests\jsonapi\Functional\JsonApiFunctionalTestBase::setUp()
Overrides BrowserTestBase::setUp
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 99
Class
- JsonApiFunctionalTestBase
- Provides helper methods for the JSON:API module's functional tests.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
protected function setUp() : void {
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', 'node', 'article');
$this->createImageField('field_no_hero', 'node', '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.