You are here

public function LinkitFilterEntityTest::testFilterEntityAccess in Linkit 8.5

Tests the linkit filter for entities with different access.

File

tests/src/Kernel/LinkitFilterEntityTest.php, line 62

Class

LinkitFilterEntityTest
Tests the Linkit filter.

Namespace

Drupal\Tests\linkit\Kernel

Code

public function testFilterEntityAccess() {

  // Create an entity that no one have access to.
  $entity_no_access = EntityTest::create([
    'name' => 'forbid_access',
  ]);
  $entity_no_access
    ->save();

  // Create an entity that is accessible.
  $entity_with_access = EntityTest::create([
    'name' => $this
      ->randomMachineName(),
  ]);
  $entity_with_access
    ->save();

  // Automatically set the title.
  $this->filter
    ->setConfiguration([
    'settings' => [
      'title' => 1,
    ],
  ]);

  // Make sure the title is not included.
  $input = '<a data-entity-type="' . $entity_no_access
    ->getEntityTypeId() . '" data-entity-uuid="' . $entity_no_access
    ->uuid() . '">Link text</a>';
  $this
    ->assertFalse(strpos($this
    ->process($input)
    ->getProcessedText(), 'title'), 'The link does not contain a title attribute.');
  $this
    ->assertLinkitFilterWithTitle($entity_with_access);
}