for ($i = 0;
$i < 16;
$i++
) { $suffix =
$i % 2 ? 'odd' : 'even';
$tag = 'autocomplete_tag_test_' .
$suffix .
$this->
randomMachineName();
$tags[] =
$tag;
View::
create(['tag' =>
$tag, 'id' =>
$this->
randomMachineName()])->
save();
} // Make sure just ten results are returned.
$controller = ViewsUIController::
create($this->container
);
$request =
$this->container->
get('request_stack'
)->
getCurrentRequest();
$request->query->
set('q', 'autocomplete_tag_test'
);
$result =
$controller->
autocompleteTag($request);
$matches =
(array) json_decode($result->
getContent(), TRUE
);
$this->
assertCount(10,
$matches, 'Make sure the maximum amount of tag results is 10.'
);
// Make sure the returned array has the proper format.
$suggestions =
array_map(function D
$tag) { return ['value' =>
$tag, 'label' => Html::
escape($tag)];
},
$tags);
foreach ($matches as $match) { $this->
assertContains($match,
$suggestions, 'Make sure the returned array has the proper format.'
);
}