function CategoryAutocompleteTest::testAutocompleteSuggestions

Same name in other branches
  1. 9 core/modules/block/tests/src/Unit/CategoryAutocompleteTest.php \Drupal\Tests\block\Unit\CategoryAutocompleteTest::testAutocompleteSuggestions()
  2. 10 core/modules/block/tests/src/Unit/CategoryAutocompleteTest.php \Drupal\Tests\block\Unit\CategoryAutocompleteTest::testAutocompleteSuggestions()
  3. 11.x 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));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.