public function PathAliasTest::testBuildLink in Freelinking 4.0.x
Same name and namespace in other branches
- 8.3 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 127
Class
- PathAliasTest
- Tests the path_alias plugin.
Namespace
Drupal\Tests\freelinking\Unit\Plugin\freelinkingCode
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));
}