You are here

public function ParentCandidateTest::testGetParentCandidate in Entity Reference Hierarchy 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/ParentCandidateTest.php \Drupal\Tests\entity_hierarchy\Kernel\ParentCandidateTest::testGetParentCandidate()

Tests field candidates.

File

tests/src/Kernel/ParentCandidateTest.php, line 19

Class

ParentCandidateTest
Defines a class for testing ParentCandidate.

Namespace

Drupal\Tests\entity_hierarchy\Kernel

Code

public function testGetParentCandidate() {
  $this
    ->installEntitySchema('entity_test_rev');
  $parentCandidate = $this->container
    ->get('entity_hierarchy.information.parent_candidate');
  $this
    ->assertEquals([
    'parents',
  ], $parentCandidate
    ->getCandidateFields($this->parent));
  entity_test_create_bundle('fooey');
  $entity = EntityTest::create([
    'type' => 'fooey',
  ]);
  $entity
    ->save();
  $this
    ->assertEquals([
    'parents',
  ], $parentCandidate
    ->getCandidateFields($entity));

  // Add a bundle limit.
  $field = FieldConfig::load('entity_test.entity_test.parents');
  $settings = $field
    ->getSetting('handler_settings');
  $settings['target_bundles'] = [
    'entity_test',
  ];
  $field
    ->setSetting('handler_settings', $settings);
  $field
    ->save();
  $this
    ->assertEquals([], $parentCandidate
    ->getCandidateFields($entity));
  $entity_rev = EntityTestRev::create();
  $entity_rev
    ->save();
  $this
    ->assertEquals([], $parentCandidate
    ->getCandidateFields($entity_rev));
}