You are here

public function CategoryAutocompleteTest::testAutocompleteSuggestions in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/block/tests/src/Unit/CategoryAutocompleteTest.php \Drupal\Tests\block\Unit\CategoryAutocompleteTest::testAutocompleteSuggestions()
  2. 9 core/modules/block/tests/src/Unit/CategoryAutocompleteTest.php \Drupal\Tests\block\Unit\CategoryAutocompleteTest::testAutocompleteSuggestions()

Tests the autocomplete method.

@dataProvider providerTestAutocompleteSuggestions

Parameters

string $string: The string entered into the autocomplete.

array $suggestions: The array of expected suggestions.

See also

\Drupal\block\Controller\CategoryAutocompleteController::autocomplete()

File

core/modules/block/tests/src/Unit/CategoryAutocompleteTest.php, line 44

Class

CategoryAutocompleteTest
@coversDefaultClass \Drupal\block\Controller\CategoryAutocompleteController @group block

Namespace

Drupal\Tests\block\Unit

Code

public function testAutocompleteSuggestions($string, $suggestions) {
  $suggestions = array_map(function ($suggestion) {
    return [
      'value' => $suggestion,
      'label' => Html::escape($suggestion),
    ];
  }, $suggestions);
  $result = $this->autocompleteController
    ->autocomplete(new Request([
    'q' => $string,
  ]));
  $this
    ->assertSame($suggestions, json_decode($result
    ->getContent(), TRUE));
}