Unverified Commit 68996afb authored by larowlan's avatar larowlan

Issue #3035732 by Lendude, nod_, Vidushi Mehta, Kristen Pol, jungle, larowlan:...

Issue #3035732 by Lendude, nod_, Vidushi Mehta, Kristen Pol, jungle, larowlan: Views UI tags do not use autocomplete suggestions

(cherry picked from commit 8fac18c8)
parent 498fd743
......@@ -2,6 +2,7 @@
namespace Drupal\views_ui\Controller;
use Drupal\Component\Utility\Tags;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Link;
use Drupal\Core\Url;
......@@ -188,13 +189,15 @@ public function autocompleteTag(Request $request) {
// Keep track of previously processed tags so they can be skipped.
$tags = [];
foreach ($views as $view) {
$tag = $view->get('tag');
if ($tag && !in_array($tag, $tags)) {
$tags[] = $tag;
if (strpos($tag, $string) === 0) {
$matches[] = ['value' => $tag, 'label' => Html::escape($tag)];
if (count($matches) >= 10) {
break;
$view_tag = $view->get('tag');
foreach (Tags::explode($view_tag) as $tag) {
if ($tag && !in_array($tag, $tags, TRUE)) {
$tags[] = $tag;
if (mb_stripos($tag, $string) !== FALSE) {
$matches[] = ['value' => $tag, 'label' => Html::escape($tag)];
if (count($matches) >= 10) {
break 2;
}
}
}
}
......
......@@ -22,7 +22,7 @@ class TagTest extends ViewsKernelTestBase {
protected static $modules = ['views', 'views_ui', 'user'];
/**
* Tests the views_ui_autocomplete_tag function.
* Tests the ViewsUIController::autocompleteTag() function.
*/
public function testViewsUiAutocompleteTag() {
\Drupal::moduleHandler()->loadInclude('views_ui', 'inc', 'admin');
......@@ -68,4 +68,41 @@ public function testViewsUiAutocompleteTag() {
$this->assertCount(0, $matches, "Make sure an invalid tag doesn't return anything.");
}
/**
* Tests that comma delimited tags are treated as individual tags.
*
* @dataProvider providerViewsUiAutocompleteIndividualTags
*/
public function testViewsUiAutocompleteIndividualTags($expected_tag, $search_string) {
$controller = ViewsUIController::create($this->container);
$request = $this->container->get('request_stack')->getCurrentRequest();
$tag = 'comma, 你好, Foo bar';
View::create(['tag' => $tag, 'id' => $this->randomMachineName()])->save();
$request->query->set('q', $search_string);
$result = $controller->autocompleteTag($request);
$matches = (array) json_decode($result->getContent());
$this->assertCount(1, $matches);
$this->assertSame($expected_tag, $matches[0]->value);
}
/**
* Data provider for testViewsUiAutocompleteIndividualTags().
*
* @return array[]
* The data set.
*/
public function providerViewsUiAutocompleteIndividualTags() {
return [
'tag' => ['comma', 'comma'],
'case insensitive tag' => ['comma', 'COMMA'],
'Hello in Chinese (partial 1)' => ['你好', '你'],
'Hello in Chinese (partial 2)' => ['你好', '好'],
'Hello in Chinese' => ['你好', '你好'],
'Starts with partial and case-sensitive' => ['Foo bar', 'Foo'],
'Starts with partial and case-insensitive' => ['Foo bar', 'fOO'],
'Ends with partial and case-sensitive' => ['Foo bar', 'bar'],
'Ends with partial and case-insensitive' => ['Foo bar', 'BAR'],
];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment