function FieldPluginBaseTest::providerTestRenderAsLinkWithPathAndOptions

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php \Drupal\Tests\views\Unit\Plugin\field\FieldPluginBaseTest::providerTestRenderAsLinkWithPathAndOptions()
  2. 10 core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php \Drupal\Tests\views\Unit\Plugin\field\FieldPluginBaseTest::providerTestRenderAsLinkWithPathAndOptions()
  3. 11.x 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 345

Class

FieldPluginBaseTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21views%21src%21Plugin%21views%21field%21FieldPluginBase.php/class/FieldPluginBase/8.9.x" title="Base class for views fields." class="local">\Drupal\views\Plugin\views\field\FieldPluginBase</a> @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->createMock('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>',
    ];
    $data[] = [
        'www.drupal.org',
        [
            'external' => TRUE,
        ],
        [],
        '<a href="http://www.drupal.org">value</a>',
    ];
    $data[] = [
        '',
        [
            'external' => TRUE,
        ],
        [],
        'value',
    ];
    return $data;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.