You are here

public function AutocompleteHandlerTest::testAutoCompleteHandler in Entity Reference Hierarchy 8.2

Same name and namespace in other branches
  1. 3.x tests/src/Kernel/AutocompleteHandlerTest.php \Drupal\Tests\entity_hierarchy\Kernel\AutocompleteHandlerTest::testAutoCompleteHandler()

Tests autocomplete handler.

File

tests/src/Kernel/AutocompleteHandlerTest.php, line 37

Class

AutocompleteHandlerTest
Tests autocomplete handler.

Namespace

Drupal\Tests\entity_hierarchy\Kernel

Code

public function testAutoCompleteHandler() {
  $child = $this
    ->createTestEntity($this->parent
    ->id(), 'Child');
  $grandchild = $this
    ->createTestEntity($child
    ->id(), 'Grandchild');
  $great_grandchild = $this
    ->createTestEntity($grandchild
    ->id(), 'Great Grandchild');
  $results = $this
    ->getAutocompleteResult('Great');
  $this
    ->assertCount(1, $results);
  $result = reset($results);
  $label = sprintf('Great Grandchild (%s ❭ Child ❭ Grandchild)', $this->parent
    ->label());
  $this
    ->assertEquals([
    'value' => sprintf('%s (%s)', $label, $great_grandchild
      ->id()),
    'label' => $label,
  ], $result);
}