You are here

public function FieldPluginBaseTest::providerTestRenderAsLinkWithPathAndOptions in Zircon Profile 8.0

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::providerTestRenderAsLinkWithPathAndOptions()

Data provider for ::testRenderAsLinkWithPathAndOptions().

Return value

array Test data.

File

core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php, line 291
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 providerTestRenderAsLinkWithPathAndOptions() {
  $data = [];

  // Simple path with default options.
  $data[] = [
    'test-path',
    [],
    [],
    '<a href="/test-path">value</a>',
  ];

  // Add a fragment.
  $data[] = [
    'test-path',
    [
      'fragment' => 'test',
    ],
    '<a href="/test-path#test">value</a>',
  ];

  // Rel attributes.
  $data[] = [
    'test-path',
    [
      'rel' => 'up',
    ],
    '<a href="/test-path" rel="up">value</a>',
  ];

  // Target attributes.
  $data[] = [
    'test-path',
    [
      'target' => '_blank',
    ],
    '<a href="/test-path" target="_blank">value</a>',
  ];

  // Link attributes.
  $data[] = [
    'test-path',
    [
      'link_attributes' => [
        'foo' => 'bar',
      ],
    ],
    '<a href="/test-path" foo="bar">value</a>',
  ];

  // Manual specified query.
  $data[] = [
    'test-path',
    [
      'query' => [
        'foo' => 'bar',
      ],
    ],
    '<a href="/test-path?foo=bar">value</a>',
  ];

  // Query specified as part of the path.
  $data[] = [
    'test-path?foo=bar',
    [],
    '<a href="/test-path?foo=bar">value</a>',
  ];

  // Query specified as option and path.
  // @todo Do we expect that options override all existing ones?
  $data[] = [
    'test-path?foo=bar',
    [
      'query' => [
        'key' => 'value',
      ],
    ],
    '<a href="/test-path?key=value">value</a>',
  ];

  // Alias flag.
  $data[] = [
    'test-path',
    [
      'alias' => TRUE,
    ],
    '<a href="/test-path">value</a>',
  ];

  // Note: In contrast to the testRenderAsLinkWithUrlAndOptions test we don't
  // test the language, because the path processor for the language won't be
  // executed for paths which aren't routed.
  // Entity flag.
  $entity = $this
    ->getMock('Drupal\\Core\\Entity\\EntityInterface');
  $data[] = [
    'test-path',
    [
      'entity' => $entity,
    ],
    '<a href="/test-path">value</a>',
  ];

  // entity_type flag.
  $entity_type_id = 'node';
  $data[] = [
    'test-path',
    [
      'entity_type' => $entity_type_id,
    ],
    '<a href="/test-path">value</a>',
  ];

  // prefix
  $data[] = [
    'test-path',
    [
      'prefix' => 'test_prefix',
    ],
    '<a href="/test-path">value</a>',
    'test_prefix<a href="/test-path">value</a>',
  ];

  // suffix.
  $data[] = [
    'test-path',
    [
      'suffix' => 'test_suffix',
    ],
    '<a href="/test-path">value</a>',
    '<a href="/test-path">value</a>test_suffix',
  ];

  // External URL.
  $data[] = [
    'https://www.drupal.org',
    [],
    [],
    '<a href="https://www.drupal.org">value</a>',
  ];
  return $data;
}