3 namespace Drupal\link\Tests\Views;
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\field\Entity\FieldStorageConfig;
7 use Drupal\views\Tests\ViewTestBase;
8 use Drupal\views\Tests\ViewTestData;
11 * Tests the views integration for link tokens.
15 class LinkViewsTokensTest extends ViewTestBase {
22 public static $modules = ['link_test_views'];
25 * Views used by this test.
29 public static $testViews = ['test_link_tokens'];
32 * The field name used for the link field.
36 protected $fieldName = 'field_link';
41 protected function setUp($import_test_views = TRUE) {
42 parent::setUp($import_test_views);
43 ViewTestData::createTestViews(get_class($this), ['link_test_views']);
45 // Create Basic page node type.
46 $this->drupalCreateContentType([
48 'name' => 'Basic page'
52 FieldStorageConfig::create([
53 'field_name' => $this->fieldName,
55 'entity_type' => 'node',
59 'field_name' => $this->fieldName,
60 'entity_type' => 'node',
62 'label' => 'link field',
67 public function testLinkViewsTokens() {
68 // Array of URI's to test.
70 'http://www.drupal.org' => 'Drupal.org',
73 // Add nodes with the URI's and titles.
74 foreach ($uris as $uri => $title) {
75 $values = ['type' => 'page'];
76 $values[$this->fieldName][] = ['uri' => $uri, 'title' => $title, 'options' => ['attributes' => ['class' => 'test-link-class']]];
77 $this->drupalCreateNode($values);
80 $this->drupalGet('test_link_tokens');
82 foreach ($uris as $uri => $title) {
83 // Formatted link: {{ field_link }}<br />
84 $this->assertRaw("Formated: <a href=\"$uri\" class=\"test-link-class\">$title</a>");
86 // Raw uri: {{ field_link__uri }}<br />
87 $this->assertRaw("Raw uri: $uri");
89 // Raw title: {{ field_link__title }}<br />
90 $this->assertRaw("Raw title: $title");
92 // Raw options: {{ field_link__options }}<br />
93 // Options is an array and should return empty after token replace.
94 $this->assertRaw("Raw options: .");