You are here

protected function NameAutocompleteTest::getAutocompleteResult in Log entity 2.x

Returns the result of an 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.

Throws

\Exception

2 calls to NameAutocompleteTest::getAutocompleteResult()
NameAutocompleteTest::testLogNameAutocomplete in tests/src/Kernel/NameAutocompleteTest.php
Tests name autocomplete route.
NameAutocompleteTest::testLogNameAutocompleteMultipleLogs in tests/src/Kernel/NameAutocompleteTest.php
Tests the order of logs returned.

File

tests/src/Kernel/NameAutocompleteTest.php, line 119

Class

NameAutocompleteTest
Tests name autocomplete for logs.

Namespace

Drupal\Tests\log\Kernel

Code

protected function getAutocompleteResult($input) {

  // Rebuild the route cache on each request to avoid parameter bag cache
  // leaks.
  $this->container
    ->get('router.builder')
    ->rebuild();

  // Build the autocomplete request, 'q' is the right parameter to mock this.
  $request = Request::create('/log/default/autocomplete');
  $request->query
    ->set('q', $input);

  /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel */
  $http_kernel = $this->container
    ->get('http_kernel');
  $response = $http_kernel
    ->handle($request);

  // The response is a JsonResponse and the content is a string that needs to
  // be decoded to array.
  $result = $response
    ->getContent();
  return Json::decode($result);
}