You are here

protected function AutocompleteHandlerTest::getAutocompleteResult in Entity Reference Hierarchy 3.x

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

Returns the result of an Entity reference autocomplete request.

Parameters

string $input: The label of the entity to query by.

Return value

mixed The JSON value encoded in its appropriate PHP type.

1 call to AutocompleteHandlerTest::getAutocompleteResult()
AutocompleteHandlerTest::testAutoCompleteHandler in tests/src/Kernel/AutocompleteHandlerTest.php
Tests autocomplete handler.

File

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

Class

AutocompleteHandlerTest
Tests autocomplete handler.

Namespace

Drupal\Tests\entity_hierarchy\Kernel

Code

protected function getAutocompleteResult($input) {
  $request = Request::create('entity_reference_autocomplete/' . self::ENTITY_TYPE . '/entity_hierarchy');
  $request->query
    ->set('q', $input);
  $selection_settings_key = Crypt::hmacBase64(serialize($this->settings) . self::ENTITY_TYPE . 'entity_hierarchy', Settings::getHashSalt());
  \Drupal::keyValue('entity_autocomplete')
    ->set($selection_settings_key, $this->settings);
  $entity_reference_controller = EntityAutocompleteController::create($this->container);
  $result = $entity_reference_controller
    ->handleAutocomplete($request, self::ENTITY_TYPE, 'entity_hierarchy', $selection_settings_key)
    ->getContent();
  return Json::decode($result);
}