function EntityReferenceSelectionReferenceableTest::setUp
Same name in other branches
- 9 core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php \Drupal\Tests\system\Kernel\Entity\EntityReferenceSelectionReferenceableTest::setUp()
- 8.9.x core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php \Drupal\Tests\system\Kernel\Entity\EntityReferenceSelectionReferenceableTest::setUp()
- 10 core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php \Drupal\Tests\system\Kernel\Entity\EntityReferenceSelectionReferenceableTest::setUp()
Overrides KernelTestBase::setUp
File
-
core/
modules/ system/ tests/ src/ Kernel/ Entity/ EntityReferenceSelectionReferenceableTest.php, line 60
Class
- EntityReferenceSelectionReferenceableTest
- Tests entity reference selection plugins.
Namespace
Drupal\Tests\system\Kernel\EntityCode
protected function setUp() : void {
parent::setUp();
$this->installEntitySchema('entity_test_no_label');
$this->installEntitySchema('node');
/** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
$storage = $this->container
->get('entity_type.manager')
->getStorage('entity_test_no_label');
// Create a new node-type.
NodeType::create([
'type' => $node_type = $this->randomMachineName(),
'name' => $this->randomString(),
])
->save();
// Create an entity reference field targeting 'entity_test_no_label'
// entities.
$field_name = $this->randomMachineName();
$this->createEntityReferenceField('node', $node_type, $field_name, $this->randomString(), 'entity_test_no_label');
$field_config = FieldConfig::loadByName('node', $node_type, $field_name);
$this->selectionHandler = $this->container
->get('plugin.manager.entity_reference_selection')
->getSelectionHandler($field_config);
// Generate a bundle name to be used with 'entity_test_no_label'.
$this->bundle = $this->randomMachineName();
// Create 6 entities to be referenced by the field.
foreach (static::$labels as $name) {
$storage->create([
'id' => $this->randomMachineName(),
'name' => $name,
'type' => $this->bundle,
])
->save();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.