function EntityReferenceAdminTest::setUp

Same name in this branch
  1. 10 core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceAdminTest::setUp()
Same name in other branches
  1. 9 core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\FunctionalJavascript\EntityReference\EntityReferenceAdminTest::setUp()
  2. 9 core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceAdminTest::setUp()
  3. 8.9.x core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\FunctionalJavascript\EntityReference\EntityReferenceAdminTest::setUp()
  4. 8.9.x core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceAdminTest::setUp()
  5. 11.x core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\FunctionalJavascript\EntityReference\EntityReferenceAdminTest::setUp()
  6. 11.x core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceAdminTest::setUp()

Overrides BrowserTestBase::setUp

File

core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php, line 65

Class

EntityReferenceAdminTest
Tests for the administrative UI.

Namespace

Drupal\Tests\field\FunctionalJavascript\EntityReference

Code

protected function setUp() : void {
    parent::setUp();
    $this->drupalPlaceBlock('system_breadcrumb_block');
    // Create a content type, with underscores.
    $type_name = $this->randomMachineName(8) . '_test';
    $type = $this->drupalCreateContentType([
        'name' => $type_name,
        'type' => $type_name,
    ]);
    $this->type = $type->id();
    // Create a second content type, to be a target for entity reference fields.
    $type_name = $this->randomMachineName(8) . '_test';
    $type = $this->drupalCreateContentType([
        'name' => $type_name,
        'type' => $type_name,
    ]);
    $this->targetType = $type->id();
    // Change the title field label.
    $fields = \Drupal::service('entity_field.manager')->getFieldDefinitions('node', $type->id());
    $fields['title']->getConfig($type->id())
        ->setLabel($type->id() . ' title')
        ->save();
    // Add text field to the second content type.
    FieldStorageConfig::create([
        'field_name' => 'field_text',
        'entity_type' => 'node',
        'type' => 'text',
        'entity_types' => [
            'node',
        ],
    ])->save();
    FieldConfig::create([
        'label' => 'Text Field',
        'field_name' => 'field_text',
        'entity_type' => 'node',
        'bundle' => $this->targetType,
        'settings' => [],
        'required' => FALSE,
    ])
        ->save();
    // Create test user.
    $admin_user = $this->drupalCreateUser([
        'access content',
        'administer node fields',
        'administer node display',
        'administer views',
        'create ' . $this->type . ' content',
        'edit own ' . $this->type . ' content',
    ]);
    $this->drupalLogin($admin_user);
}

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