You are here

public function SearchFailoverTest::testBuildLink in Freelinking 8.3

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

Asserts the failover functionality for the search plugin.

@dataProvider buildLinkProvider

Parameters

string $failoverOption: The failover option to test.

array $expected: The expected render array without any items depending on the container.

File

tests/src/Unit/Plugin/freelinking/SearchFailoverTest.php, line 70

Class

SearchFailoverTest
Tests the failover options for search plugin.

Namespace

Drupal\Tests\freelinking\Unit\Plugin\freelinking

Code

public function testBuildLink($failoverOption, array $expected) {
  $target = [
    'target' => 'search:Test Search|Test Search',
    'dest' => 'Test Search',
    'text' => 'Test Search',
    'language' => NULL,
  ];

  // Build out the expected array depending on the failover option.
  if ($failoverOption === 'google') {
    $expected['#url'] = Url::fromUri('https://google.com/search', [
      'query' => [
        'q' => 'Test+Search',
        'hl' => 'en',
      ],
      'language' => NULL,
      'absolute' => TRUE,
    ]);
  }
  elseif ($failoverOption === 'error') {
    $expected['#message'] = new TranslatableMarkup('Search unavailable', [], [], $this->translationInterfaceMock);
  }
  $plugin_definition = [
    'id' => 'search',
    'title' => 'Search',
    'hidden' => FALSE,
    'weight' => 0,
    'settings' => [
      'failover' => $failoverOption,
    ],
  ];
  $configuration = [
    'settings' => [
      'failover' => $failoverOption,
    ],
  ];
  $plugin = Search::create($this->container, $configuration, 'search', $plugin_definition);
  $this
    ->assertEquals($expected, $plugin
    ->buildLink($target));
}