comparison core/modules/link/src/Tests/Views/LinkViewsTokensTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\link\Tests\Views;
4
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\field\Entity\FieldStorageConfig;
7 use Drupal\views\Tests\ViewTestBase;
8 use Drupal\views\Tests\ViewTestData;
9
10 /**
11 * Tests the views integration for link tokens.
12 *
13 * @group link
14 */
15 class LinkViewsTokensTest extends ViewTestBase {
16
17 /**
18 * Modules to enable.
19 *
20 * @var array
21 */
22 public static $modules = ['link_test_views'];
23
24 /**
25 * Views used by this test.
26 *
27 * @var array
28 */
29 public static $testViews = ['test_link_tokens'];
30
31 /**
32 * The field name used for the link field.
33 *
34 * @var string
35 */
36 protected $fieldName = 'field_link';
37
38 /**
39 * {@inheritdoc}
40 */
41 protected function setUp() {
42 parent::setUp();
43 ViewTestData::createTestViews(get_class($this), ['link_test_views']);
44
45 // Create Basic page node type.
46 $this->drupalCreateContentType([
47 'type' => 'page',
48 'name' => 'Basic page'
49 ]);
50
51 // Create a field.
52 FieldStorageConfig::create([
53 'field_name' => $this->fieldName,
54 'type' => 'link',
55 'entity_type' => 'node',
56 'cardinality' => 1,
57 ])->save();
58 FieldConfig::create([
59 'field_name' => $this->fieldName,
60 'entity_type' => 'node',
61 'bundle' => 'page',
62 'label' => 'link field',
63 ])->save();
64
65 }
66
67 public function testLinkViewsTokens() {
68 // Array of URI's to test.
69 $uris = [
70 'http://www.drupal.org' => 'Drupal.org',
71 ];
72
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);
78 }
79
80 $this->drupalGet('test_link_tokens');
81
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>");
85
86 // Raw uri: {{ field_link__uri }}<br />
87 $this->assertRaw("Raw uri: $uri");
88
89 // Raw title: {{ field_link__title }}<br />
90 $this->assertRaw("Raw title: $title");
91
92 // Raw options: {{ field_link__options }}<br />
93 // Options is an array and should return empty after token replace.
94 $this->assertRaw("Raw options: .");
95 }
96 }
97
98 }