function LinkViewsTokensTest::testLinkViewsTokens

Same name in other branches
  1. 8.9.x core/modules/link/tests/src/Functional/Views/LinkViewsTokensTest.php \Drupal\Tests\link\Functional\Views\LinkViewsTokensTest::testLinkViewsTokens()
  2. 10 core/modules/link/tests/src/Functional/Views/LinkViewsTokensTest.php \Drupal\Tests\link\Functional\Views\LinkViewsTokensTest::testLinkViewsTokens()
  3. 11.x core/modules/link/tests/src/Functional/Views/LinkViewsTokensTest.php \Drupal\Tests\link\Functional\Views\LinkViewsTokensTest::testLinkViewsTokens()

File

core/modules/link/tests/src/Functional/Views/LinkViewsTokensTest.php, line 70

Class

LinkViewsTokensTest
Tests the views integration for link tokens.

Namespace

Drupal\Tests\link\Functional\Views

Code

public function testLinkViewsTokens() {
    // Array of URI's to test.
    $uris = [
        'http://www.drupal.org' => 'Drupal.org',
    ];
    // Add nodes with the URI's and titles.
    foreach ($uris as $uri => $title) {
        $values = [
            'type' => 'page',
        ];
        $values[$this->fieldName][] = [
            'uri' => $uri,
            'title' => $title,
            'options' => [
                'attributes' => [
                    'class' => 'test-link-class',
                ],
            ],
        ];
        $this->drupalCreateNode($values);
    }
    $this->drupalGet('test_link_tokens');
    foreach ($uris as $uri => $title) {
        // Formatted link: {{ field_link }}<br />
        $this->assertSession()
            ->responseContains("Formatted: <a href=\"{$uri}\" class=\"test-link-class\">{$title}</a>");
        // Raw uri: {{ field_link__uri }}<br />
        $this->assertSession()
            ->responseContains("Raw uri: {$uri}");
        // Raw title: {{ field_link__title }}<br />
        $this->assertSession()
            ->responseContains("Raw title: {$title}");
        // Raw options: {{ field_link__options }}<br />
        // Options is an array and should return empty after token replace.
        $this->assertSession()
            ->responseContains("Raw options: .");
    }
}

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