protected function DisplayEntityReferenceTest::setUp in Drupal 9
Same name and namespace in other branches
- 8 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\PluginCode
protected function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
$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 => 'sometext',
])
->save();
}