1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Testing that tokens can be used in link titles.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Testing that tokens can be used in link titles.
|
10
|
*/
|
11
|
class LinkEntityTokenTest extends LinkBaseTestClass {
|
12
|
|
13
|
/**
|
14
|
* Get Info.
|
15
|
*/
|
16
|
public static function getInfo() {
|
17
|
return array(
|
18
|
'name' => 'Link entity tokens test',
|
19
|
'description' => 'Tests that a link field appears properly in entity tokens',
|
20
|
'group' => 'Link',
|
21
|
'dependencies' => array('token', 'entity', 'entity_token'),
|
22
|
);
|
23
|
}
|
24
|
|
25
|
/**
|
26
|
* {@inheritdoc}
|
27
|
*/
|
28
|
public function setUp(array $modules = array()) {
|
29
|
$modules[] = 'token';
|
30
|
$modules[] = 'entity';
|
31
|
$modules[] = 'entity_token';
|
32
|
parent::setUp($modules);
|
33
|
}
|
34
|
|
35
|
/**
|
36
|
* Creates a link field, fills it, then uses a loaded node to test tokens.
|
37
|
*/
|
38
|
public function testFieldTokenNodeLoaded() {
|
39
|
// Create field.
|
40
|
$settings = array(
|
41
|
'instance[settings][enable_tokens]' => 0,
|
42
|
);
|
43
|
$field_name = $this->createLinkField('page',
|
44
|
$settings);
|
45
|
|
46
|
// Create page form.
|
47
|
$this->drupalGet('node/add/page');
|
48
|
// $field_name = 'field_' . $name;.
|
49
|
$this->assertField($field_name . '[und][0][title]', 'Title found');
|
50
|
$this->assertField($field_name . '[und][0][url]', 'URL found');
|
51
|
|
52
|
$token_url_tests = array(
|
53
|
1 => array(
|
54
|
'href' => 'http://example.com/' . $this->randomName(),
|
55
|
'label' => $this->randomName(),
|
56
|
),
|
57
|
2 => array(
|
58
|
'href' => 'http://example.com/' . $this->randomName() . '?property=value',
|
59
|
'label' => $this->randomName(),
|
60
|
),
|
61
|
3 => array(
|
62
|
'href' => 'http://example.com/' . $this->randomName() . '#position',
|
63
|
'label' => $this->randomName(),
|
64
|
),
|
65
|
4 => array(
|
66
|
'href' => 'http://example.com/' . $this->randomName() . '#lower?property=value2',
|
67
|
'label' => $this->randomName(),
|
68
|
),
|
69
|
);
|
70
|
// @codingStandardsIgnoreLine
|
71
|
// $this->assert('pass', '<pre>' . print_r($token_url_tests, TRUE) . '<pre>');.
|
72
|
foreach ($token_url_tests as &$input) {
|
73
|
$this->drupalGet('node/add/page');
|
74
|
|
75
|
$edit = array(
|
76
|
'title' => $input['label'],
|
77
|
$field_name . '[und][0][title]' => $input['label'],
|
78
|
$field_name . '[und][0][url]' => $input['href'],
|
79
|
);
|
80
|
$this->drupalPost(NULL, $edit, t('Save'));
|
81
|
$url = $this->getUrl();
|
82
|
$input['url'] = $url;
|
83
|
}
|
84
|
|
85
|
// Change to anonymous user.
|
86
|
$this->drupalLogout();
|
87
|
|
88
|
foreach ($token_url_tests as $index => $input2) {
|
89
|
$node = node_load($index);
|
90
|
$this->assertNotEqual(NULL, $node, "Do we have a node?");
|
91
|
$this->assertEqual($node->nid, $index, "Test that we have a node.");
|
92
|
$token_name = '[node:' . str_replace('_', '-', $field_name) . ':url]';
|
93
|
$assert_data = token_replace($token_name,
|
94
|
array('node' => $node));
|
95
|
$this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data);
|
96
|
}
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* Field Token Node Viewed.
|
101
|
*
|
102
|
* Creates a link field, fills it, then uses a loaded and node_view'd node to
|
103
|
* test tokens.
|
104
|
*/
|
105
|
public function testFieldTokenNodeViewed() {
|
106
|
// Create field.
|
107
|
$settings = array(
|
108
|
'instance[settings][enable_tokens]' => 0,
|
109
|
);
|
110
|
$field_name = $this->createLinkField('page',
|
111
|
$settings);
|
112
|
|
113
|
// Create page form.
|
114
|
$this->drupalGet('node/add/page');
|
115
|
// $field_name = 'field_' . $name;.
|
116
|
$this->assertField($field_name . '[und][0][title]', 'Title found');
|
117
|
$this->assertField($field_name . '[und][0][url]', 'URL found');
|
118
|
|
119
|
$token_url_tests = array(
|
120
|
1 => array(
|
121
|
'href' => 'http://example.com/' . $this->randomName(),
|
122
|
'label' => $this->randomName(),
|
123
|
),
|
124
|
2 => array(
|
125
|
'href' => 'http://example.com/' . $this->randomName() . '?property=value',
|
126
|
'label' => $this->randomName(),
|
127
|
),
|
128
|
3 => array(
|
129
|
'href' => 'http://example.com/' . $this->randomName() . '#position',
|
130
|
'label' => $this->randomName(),
|
131
|
),
|
132
|
4 => array(
|
133
|
'href' => 'http://example.com/' . $this->randomName() . '#lower?property=value2',
|
134
|
'label' => $this->randomName(),
|
135
|
),
|
136
|
);
|
137
|
|
138
|
//@codingStandardsIgnoreLine
|
139
|
// $this->assert('pass', '<pre>' . print_r($token_url_tests, TRUE) . '<pre>');.
|
140
|
foreach ($token_url_tests as &$input) {
|
141
|
$this->drupalGet('node/add/page');
|
142
|
|
143
|
$edit = array(
|
144
|
'title' => $input['label'],
|
145
|
$field_name . '[und][0][title]' => $input['label'],
|
146
|
$field_name . '[und][0][url]' => $input['href'],
|
147
|
);
|
148
|
$this->drupalPost(NULL, $edit, t('Save'));
|
149
|
$url = $this->getUrl();
|
150
|
$input['url'] = $url;
|
151
|
}
|
152
|
|
153
|
// Change to anonymous user.
|
154
|
$this->drupalLogout();
|
155
|
|
156
|
foreach ($token_url_tests as $index => $input2) {
|
157
|
$node = node_load($index);
|
158
|
$this->assertNotEqual(NULL, $node, "Do we have a node?");
|
159
|
$this->assertEqual($node->nid, $index, "Test that we have a node.");
|
160
|
$token_name = '[node:' . str_replace('_', '-', $field_name) . ':url]';
|
161
|
$assert_data = token_replace($token_name,
|
162
|
array('node' => $node));
|
163
|
$this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data);
|
164
|
}
|
165
|
}
|
166
|
|
167
|
}
|