You are here

public function FieldPluginBaseTest::testRenderAsLinkWithUrlAndOptions in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php \Drupal\Tests\views\Unit\Plugin\field\FieldPluginBaseTest::testRenderAsLinkWithUrlAndOptions()

Tests link rendering with a URL and options.

@dataProvider providerTestRenderAsLinkWithUrlAndOptions @covers ::renderAsLink

File

core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php, line 395
Contains \Drupal\Tests\views\Unit\Plugin\field\FieldPluginBaseTest.

Class

FieldPluginBaseTest
@coversDefaultClass \Drupal\views\Plugin\views\field\FieldPluginBase @group views

Namespace

Drupal\Tests\views\Unit\Plugin\field

Code

public function testRenderAsLinkWithUrlAndOptions(Url $url, $alter, Url $expected_url, $url_path, Url $expected_link_url, $link_html, $final_html = NULL) {
  $alter += [
    'make_link' => TRUE,
    'url' => $url,
  ];
  $final_html = isset($final_html) ? $final_html : $link_html;
  $this
    ->setUpUrlIntegrationServices();
  $this
    ->setupDisplayWithEmptyArgumentsAndFields();
  $field = $this
    ->setupTestField([
    'alter' => $alter,
  ]);
  $field->field_alias = 'key';
  $row = new ResultRow([
    'key' => 'value',
  ]);
  $expected_url
    ->setOptions($expected_url
    ->getOptions() + $this->defaultUrlOptions);
  $expected_link_url
    ->setUrlGenerator($this->urlGenerator);
  $expected_url_options = $expected_url
    ->getOptions();
  unset($expected_url_options['attributes']);
  $this->urlGenerator
    ->expects($this
    ->once())
    ->method('generateFromRoute')
    ->with($expected_url
    ->getRouteName(), $expected_url
    ->getRouteParameters(), $expected_url_options, TRUE)
    ->willReturn((new GeneratedUrl())
    ->setGeneratedUrl($url_path));
  $result = $field
    ->advancedRender($row);
  $this
    ->assertEquals($final_html, $result);
}