function SelectionTest::setUp

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

Overrides KernelTestBase::setUp

File

core/modules/field/tests/src/Kernel/EntityReference/Views/SelectionTest.php, line 57

Class

SelectionTest
Tests entity reference selection handler.

Namespace

Drupal\Tests\field\Kernel\EntityReference\Views

Code

protected function setUp() : void {
    parent::setUp();
    $this->installConfig([
        'entity_reference_test',
        'filter',
    ]);
    $this->installEntitySchema('user');
    $this->installEntitySchema('node');
    // Create test nodes.
    $type = $this->randomMachineName();
    NodeType::create([
        'type' => $type,
        'name' => $this->randomString(),
    ])
        ->save();
    $node1 = $this->createNode([
        'type' => $type,
    ]);
    $node2 = $this->createNode([
        'type' => $type,
    ]);
    $node3 = $this->createNode();
    foreach ([
        $node1,
        $node2,
        $node3,
    ] as $node) {
        $this->nodes[$node->id()] = $node;
    }
    // Ensure the bundle to which the field is attached actually exists, or we
    // will get config validation errors.
    entity_test_create_bundle('test_bundle');
    // Create an entity reference field.
    $handler_settings = [
        'view' => [
            'view_name' => 'test_entity_reference',
            'display_name' => 'entity_reference_1',
        ],
    ];
    $this->createEntityReferenceField('entity_test', 'test_bundle', 'test_field', $this->randomString(), 'node', 'views', $handler_settings);
    $field_config = FieldConfig::loadByName('entity_test', 'test_bundle', 'test_field');
    $this->selectionHandler = $this->container
        ->get('plugin.manager.entity_reference_selection')
        ->getSelectionHandler($field_config);
}

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