drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page'
]);
// Create a field.
FieldStorageConfig::create([
'field_name' => $this->fieldName,
'type' => 'link',
'entity_type' => 'node',
'cardinality' => 1,
])->save();
FieldConfig::create([
'field_name' => $this->fieldName,
'entity_type' => 'node',
'bundle' => 'page',
'label' => 'link field',
])->save();
}
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 }}
$this->assertRaw("Formated: $title");
// Raw uri: {{ field_link__uri }}
$this->assertRaw("Raw uri: $uri");
// Raw title: {{ field_link__title }}
$this->assertRaw("Raw title: $title");
// Raw options: {{ field_link__options }}
// Options is an array and should return empty after token replace.
$this->assertRaw("Raw options: .");
}
}
}