function DisplayEntityReferenceTest::setUp

Same name in other branches
  1. 9 core/modules/views/tests/src/Functional/Plugin/DisplayEntityReferenceTest.php \Drupal\Tests\views\Functional\Plugin\DisplayEntityReferenceTest::setUp()
  2. 8.9.x core/modules/views/tests/src/Functional/Plugin/DisplayEntityReferenceTest.php \Drupal\Tests\views\Functional\Plugin\DisplayEntityReferenceTest::setUp()
  3. 10 core/modules/views/tests/src/Functional/Plugin/DisplayEntityReferenceTest.php \Drupal\Tests\views\Functional\Plugin\DisplayEntityReferenceTest::setUp()

Overrides ViewTestBase::setUp

File

core/modules/views/tests/src/Functional/Plugin/DisplayEntityReferenceTest.php, line 73

Class

DisplayEntityReferenceTest
Tests the entity reference display plugin.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

protected function setUp($import_test_views = TRUE, $modules = [
    'views_test_config',
]) : void {
    parent::setUp($import_test_views, $modules);
    $this->drupalLogin($this->drupalCreateUser([
        'administer views',
    ]));
    // Create the text field.
    $this->fieldName = 'field_test_entity_ref_display';
    $this->fieldStorage = FieldStorageConfig::create([
        'field_name' => $this->fieldName,
        'entity_type' => 'entity_test',
        'type' => 'text',
    ]);
    $this->fieldStorage
        ->save();
    // Create an instance of the text field on the content type.
    $this->field = FieldConfig::create([
        'field_storage' => $this->fieldStorage,
        'bundle' => 'entity_test',
    ]);
    $this->field
        ->save();
    // Add an entity reference field to reference the same base table.
    $this->entityRefFieldName = 'field_test_entity_ref_entity_ref';
    $this->createEntityReferenceField('entity_test', 'entity_test', $this->entityRefFieldName, NULL, 'entity_test');
    // Create some entities to search. Add a common string to the name and
    // the text field in two entities so we can test that we can search in both.
    for ($i = 0; $i < 5; $i++) {
        EntityTest::create([
            'bundle' => 'entity_test',
            'name' => 'name' . $i,
            $this->fieldName => 'text',
        ])
            ->save();
        EntityTest::create([
            'bundle' => 'entity_test',
            'name' => 'name',
            $this->fieldName => 'text' . $i,
        ])
            ->save();
    }
    EntityTest::create([
        'bundle' => 'entity_test',
        'name' => 'name',
        $this->fieldName => 'tex',
    ])
        ->save();
    EntityTest::create([
        'bundle' => 'entity_test',
        'name' => 'name',
        $this->fieldName => 'TEX',
    ])
        ->save();
    EntityTest::create([
        'bundle' => 'entity_test',
        'name' => 'name',
        $this->fieldName => 'some_text',
    ])
        ->save();
}

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