You are here

public function UserTest::testBuildLink in Freelinking 8.3

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

Assert the buildLink method returns render array.

@dataProvider buildLinkProvider

Parameters

array $target: The target array.

array $expected: The expected render array.

bool $shouldFailover: Test logic to place container-dependent render array items.

File

tests/src/Unit/Plugin/freelinking/UserTest.php, line 112

Class

UserTest
Tests the user plugin.

Namespace

Drupal\Tests\freelinking\Unit\Plugin\freelinking

Code

public function testBuildLink(array $target, array $expected, $shouldFailover = FALSE) {
  if ($shouldFailover) {
    $defaultMessage = $expected['#message'];
    $expected['#message'] = new TranslatableMarkup($defaultMessage, [
      '%user' => '2',
    ], [], $this->translationInterfaceMock);
  }
  else {
    $expected['#url'] = Url::fromRoute('entity.user.canonical', [
      'user' => 1,
    ], [
      'language' => NULL,
    ]);
    $expected['#attributes']['title'] = new TranslatableMarkup('Click to view user profile.', [], [], $this->translationInterfaceMock);
  }
  $this
    ->assertEquals($expected, $this->plugin
    ->buildLink($target));
}