You are here

public function NodeTitleFailoverTest::testFailover in Freelinking 4.0.x

Same name and namespace in other branches
  1. 8.3 tests/src/Unit/Plugin/freelinking/NodeTitleFailoverTest.php \Drupal\Tests\freelinking\Unit\Plugin\freelinking\NodeTitleFailoverTest::testFailover()

Assert that failover option displays correctly.

@dataProvider failoverProvider

Parameters

string $failoverOption: The failover option to test.

array $expected: The expected render array.

File

tests/src/Unit/Plugin/freelinking/NodeTitleFailoverTest.php, line 92

Class

NodeTitleFailoverTest
Tests the failover options for nodetitle plugin.

Namespace

Drupal\Tests\freelinking\Unit\Plugin\freelinking

Code

public function testFailover($failoverOption, array $expected) {
  $plugin = NodeTitle::create($this->container, [
    'settings' => [
      'nodetypes' => [],
      'failover' => $failoverOption,
    ],
  ], 'nodetitle', []);

  // Mock the parsed target array.
  $target = [
    'dest' => 'Test Node',
    'language' => $this
      ->getDefaultLanguage(),
    'target' => 'Test Node|Test Node',
  ];

  // Populate #url for the search test because container.
  if ($failoverOption === 'error') {
    $expected['#message'] = new TranslatableMarkup('Node title %target does not exist', [
      '%target' => 'Test Node',
    ], [], $this->translationInterfaceMock);
  }
  $link = $plugin
    ->buildLink($target);
  $this
    ->assertEquals($expected, $link);
}