You are here

protected function SelectionTest::setUp in Drupal 10

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()
  2. 10 core/modules/field/tests/src/Kernel/EntityReference/Views/SelectionTest.php \Drupal\Tests\field\Kernel\EntityReference\Views\SelectionTest::setUp()
Same name and namespace in other branches
  1. 8 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/Kernel/EntityReference/Views/SelectionTest.php \Drupal\Tests\field\Kernel\EntityReference\Views\SelectionTest::setUp()

Overrides KernelTestBase::setUp

File

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

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 = strtolower($this
    ->randomMachineName());
  NodeType::create([
    'type' => $type,
  ])
    ->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;
  }

  // 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);
}