function FieldPluginBaseTest::providerTestRenderAsLinkWithPathAndOptions

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

Class

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

Namespace

Drupal\Tests\views\Unit\Plugin\field

Code

public static 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.
    $data[] = [
        'test-path',
        [
            'entity' => new \stdClass(),
        ],
        '<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',
        ],
        'test_prefix<a href="/test-path">value</a>',
    ];
    // suffix.
    $data[] = [
        'test-path',
        [
            'suffix' => 'test_suffix',
        ],
        '<a href="/test-path">value</a>test_suffix',
    ];
    // External URL.
    $data[] = [
        'https://www.example.com',
        [],
        '<a href="https://www.example.com">value</a>',
    ];
    $data[] = [
        'www.example.com',
        [
            'external' => TRUE,
        ],
        '<a href="http://www.example.com">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.