You are here

public function PathAliasTest::testBuildLink in Freelinking 8.3

Same name and namespace in other branches
  1. 4.0.x tests/src/Unit/Plugin/freelinking/PathAliasTest.php \Drupal\Tests\freelinking\Unit\Plugin\freelinking\PathAliasTest::testBuildLink()

Asserts that buildLink is functional for valid and invalid path aliases.

@dataProvider buildLinkProvider

Parameters

string $alias: The alias string to test.

array $expected: The expected render array without container dependencies.

File

tests/src/Unit/Plugin/freelinking/PathAliasTest.php, line 124

Class

PathAliasTest
Tests the path_alias plugin.

Namespace

Drupal\Tests\freelinking\Unit\Plugin\freelinking

Code

public function testBuildLink($alias, array $expected) {
  $target = [
    'text' => 'A valid path alias',
    'dest' => $alias,
    'target' => 'alias:' . $alias . '|A valid path alias',
    'language' => NULL,
  ];
  $plugin = $this
    ->getPlugin('error');
  if ($alias === 'validalias') {
    $expected['#url'] = Url::fromUri('base:node/1', [
      'language' => NULL,
    ]);
    $expected['#attributes'] = [
      'title' => new TranslatableMarkup('Click to view a local node.', [], [], $this->translationInterfaceMock),
    ];
  }
  else {
    $expected['#message'] = new TranslatableMarkup('path “%path” not found', [
      '%path' => '/invalidalias',
    ], [], $this->translationInterfaceMock);
  }
  $this
    ->assertEquals($expected, $plugin
    ->buildLink($target));
}