You are here

public function LinkitAutocompleteTest::testAutocompletionAccess in Linkit 8.5

Tests that inaccessible entities isn't included in the results.

File

tests/src/Kernel/LinkitAutocompleteTest.php, line 73

Class

LinkitAutocompleteTest
Tests the linkit autocomplete functionality.

Namespace

Drupal\Tests\linkit\Kernel

Code

public function testAutocompletionAccess() {

  /** @var \Drupal\linkit\MatcherInterface $plugin */
  $plugin = $this->matcherManager
    ->createInstance('entity:entity_test');
  $this->linkitProfile
    ->addMatcher($plugin
    ->getConfiguration());
  $this->linkitProfile
    ->save();
  $entity_1 = EntityTest::create([
    'name' => 'no_forbid_access',
  ]);
  $entity_1
    ->save();
  $entity_2 = EntityTest::create([
    'name' => 'forbid_access',
  ]);
  $entity_2
    ->save();
  $suggestions = $this
    ->getAutocompleteResult('forbid');
  $this
    ->assertTrue(count($suggestions) == 1, 'Autocomplete returned the expected amount of suggestions.');
  $this
    ->assertSame($entity_1
    ->label(), $suggestions[0]['label'], 'Autocomplete did not include the inaccessible entity.');
}