You are here

public function TermAutocompleteTest::testAutocompleteOrderedResults in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/tests/src/Functional/TermAutocompleteTest.php \Drupal\Tests\taxonomy\Functional\TermAutocompleteTest::testAutocompleteOrderedResults()
  2. 9 core/modules/taxonomy/tests/src/Functional/TermAutocompleteTest.php \Drupal\Tests\taxonomy\Functional\TermAutocompleteTest::testAutocompleteOrderedResults()

Tests that the autocomplete method returns properly ordered results.

See also

\Drupal\taxonomy\Controller\TermAutocompleteController::autocomplete()

File

core/modules/taxonomy/tests/src/Functional/TermAutocompleteTest.php, line 205

Class

TermAutocompleteTest
Tests the autocomplete implementation of the taxonomy class.

Namespace

Drupal\Tests\taxonomy\Functional

Code

public function testAutocompleteOrderedResults() {
  $expectedResults = [
    'aaa 10 bbb',
    'aaa 11 bbb',
    'aaa 12 bbb',
    'aaa 20 bbb',
    'aaa 30 bbb',
    'aaa 40 bbb',
    'aaa 50 bbb',
    'aaa 70 bbb',
    'bbb 60 aaa',
  ];

  // Build $expected to match the autocomplete results.
  $expected = [];
  foreach ($expectedResults as $termName) {
    $expected[] = [
      'value' => $termName . ' (' . $this->termIds[$termName] . ')',
      'label' => $termName,
    ];
  }
  $data = $this
    ->drupalGetJson($this->autocompleteUrl, [
    'query' => [
      'q' => 'bbb',
    ],
  ]);
  $this
    ->assertSame($expected, $data);
}