function TermAutocompleteTest::testAutocompleteCountResults
Same name in other branches
- 9 core/modules/taxonomy/tests/src/Functional/TermAutocompleteTest.php \Drupal\Tests\taxonomy\Functional\TermAutocompleteTest::testAutocompleteCountResults()
- 8.9.x core/modules/taxonomy/tests/src/Functional/TermAutocompleteTest.php \Drupal\Tests\taxonomy\Functional\TermAutocompleteTest::testAutocompleteCountResults()
- 11.x core/modules/taxonomy/tests/src/Functional/TermAutocompleteTest.php \Drupal\Tests\taxonomy\Functional\TermAutocompleteTest::testAutocompleteCountResults()
Tests that the autocomplete method returns the good number of results.
See also
\Drupal\taxonomy\Controller\TermAutocompleteController::autocomplete()
File
-
core/
modules/ taxonomy/ tests/ src/ Functional/ TermAutocompleteTest.php, line 169
Class
- TermAutocompleteTest
- Tests the autocomplete implementation of the taxonomy class.
Namespace
Drupal\Tests\taxonomy\FunctionalCode
public function testAutocompleteCountResults() : void {
// Test that no matching term found.
$data = $this->drupalGetJson($this->autocompleteUrl, [
'query' => [
'q' => 'zzz',
],
]);
$this->assertEmpty($data, 'Autocomplete returned no results');
// Test that only one matching term found, when only one matches.
$data = $this->drupalGetJson($this->autocompleteUrl, [
'query' => [
'q' => 'aaa 10',
],
]);
$this->assertCount(1, $data, 'Autocomplete returned 1 result');
// Test the correct number of matches when multiple are partial matches.
$data = $this->drupalGetJson($this->autocompleteUrl, [
'query' => [
'q' => 'aaa 1',
],
]);
$this->assertCount(3, $data, 'Autocomplete returned 3 results');
// Tests that only 10 results are returned, even if there are more than 10
// matches.
$data = $this->drupalGetJson($this->autocompleteUrl, [
'query' => [
'q' => 'aaa',
],
]);
$this->assertCount(10, $data, 'Autocomplete returned only 10 results (for over 10 matches)');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.