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 LinkTokenTest extends LinkBaseTestClass {
|
12
|
|
13
|
/**
|
14
|
* Get Info.
|
15
|
*/
|
16
|
public static function getInfo() {
|
17
|
return array(
|
18
|
'name' => 'Link tokens - browser test',
|
19
|
'description' => 'Tests including tokens in link titles, making sure they appear in node views.',
|
20
|
'group' => 'Link',
|
21
|
'dependencies' => array('token'),
|
22
|
);
|
23
|
}
|
24
|
|
25
|
/**
|
26
|
* {@inheritdoc}
|
27
|
*/
|
28
|
public function setUp(array $modules = array()) {
|
29
|
$modules[] = 'token';
|
30
|
parent::setUp($modules);
|
31
|
}
|
32
|
|
33
|
/**
|
34
|
* Creates a link field with a required title enabled for user-entered tokens.
|
35
|
*
|
36
|
* Creates a node with a token in the link title and checks the value.
|
37
|
*/
|
38
|
public function testUserTokenLinkCreate() {
|
39
|
// Create field.
|
40
|
$settings = array(
|
41
|
'instance[settings][enable_tokens]' => 1,
|
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
|
$input = array(
|
53
|
'href' => 'http://example.com/' . $this->randomName(),
|
54
|
'label' => $this->randomName(),
|
55
|
);
|
56
|
|
57
|
// $this->drupalLogin($this->web_user);.
|
58
|
$this->drupalGet('node/add/page');
|
59
|
|
60
|
$edit = array(
|
61
|
'title' => $input['label'],
|
62
|
$field_name . '[und][0][title]' => $input['label'] . " [node:content-type:machine-name]",
|
63
|
$field_name . '[und][0][url]' => $input['href'],
|
64
|
);
|
65
|
$this->drupalPost(NULL, $edit, t('Save'));
|
66
|
$url = $this->getUrl();
|
67
|
|
68
|
// Change to anonymous user.
|
69
|
$this->drupalLogout();
|
70
|
$this->drupalGet($url);
|
71
|
|
72
|
$this->assertRaw(l($input['label'] . ' page', $input['href']));
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* Creates a link field with a static title and an admin-entered token.
|
77
|
*
|
78
|
* Creates a node with a link and checks the title value.
|
79
|
*/
|
80
|
public function testStaticTokenLinkCreate() {
|
81
|
// Create field.
|
82
|
$name = $this->randomName();
|
83
|
$settings = array(
|
84
|
'instance[settings][title]' => 'value',
|
85
|
'instance[settings][title_value]' => $name . ' [node:content-type:machine-name]',
|
86
|
);
|
87
|
$field_name = $this->createLinkField('page', $settings);
|
88
|
|
89
|
// Create page form.
|
90
|
$this->drupalGet('node/add/page');
|
91
|
$this->assertField($field_name . '[und][0][url]', 'URL found');
|
92
|
|
93
|
$input = array(
|
94
|
'href' => 'http://example.com/' . $this->randomName(),
|
95
|
);
|
96
|
|
97
|
// $this->drupalLogin($this->web_user);.
|
98
|
$this->drupalGet('node/add/page');
|
99
|
|
100
|
$edit = array(
|
101
|
'title' => $name,
|
102
|
$field_name . '[und][0][url]' => $input['href'],
|
103
|
);
|
104
|
$this->drupalPost(NULL, $edit, t('Save'));
|
105
|
|
106
|
$url = $this->getUrl();
|
107
|
|
108
|
// Change to anonymous user.
|
109
|
$this->drupalLogout();
|
110
|
$this->drupalGet($url);
|
111
|
|
112
|
$this->assertRaw(l($name . ' page', $input['href']));
|
113
|
}
|
114
|
|
115
|
/**
|
116
|
* Creates a link field with a static title and an admin-entered token.
|
117
|
*
|
118
|
* Creates a node with a link and checks the title value.
|
119
|
*
|
120
|
* Basically, I want to make sure the [title-raw] token works, because it's a
|
121
|
* token that changes from node to node, where [type]'s always going to be the
|
122
|
* same.
|
123
|
*/
|
124
|
public function testStaticTokenLinkCreate2() {
|
125
|
// Create field.
|
126
|
$name = $this->randomName();
|
127
|
$settings = array(
|
128
|
'instance[settings][title]' => 'value',
|
129
|
'instance[settings][title_value]' => $name . ' [node:title]',
|
130
|
);
|
131
|
$field_name = $this->createLinkField('page', $settings);
|
132
|
|
133
|
// Create page form.
|
134
|
$this->drupalGet('node/add/page');
|
135
|
$this->assertField($field_name . '[und][0][url]', 'URL found');
|
136
|
|
137
|
$input = array(
|
138
|
'href' => 'http://example.com/' . $this->randomName(),
|
139
|
);
|
140
|
|
141
|
// $this->drupalLogin($this->web_user);.
|
142
|
$this->drupalGet('node/add/page');
|
143
|
|
144
|
$edit = array(
|
145
|
'title' => $name,
|
146
|
$field_name . '[und][0][url]' => $input['href'],
|
147
|
);
|
148
|
$this->drupalPost(NULL, $edit, t('Save'));
|
149
|
|
150
|
$url = $this->getUrl();
|
151
|
|
152
|
// Change to anonymous user.
|
153
|
$this->drupalLogout();
|
154
|
$this->drupalGet($url);
|
155
|
|
156
|
$this->assertRaw(l($name . ' ' . $name, $input['href']));
|
157
|
}
|
158
|
|
159
|
/**
|
160
|
* This test doesn't seem to actually work, due to lack of 'title' in url.
|
161
|
*
|
162
|
* @codingStandardsIgnoreStart
|
163
|
*/
|
164
|
public function xTestLinkWithTitleAttributeTokenUrlForm() {
|
165
|
/* $this->loginWithPermissions($this->permissions);
|
166
|
$this->acquireContentTypes(1);
|
167
|
$field_settings = array(
|
168
|
'type' => 'link',
|
169
|
'widget_type' => 'link',
|
170
|
'type_name' => $this->content_types[0]->name,
|
171
|
'attributes' => array(
|
172
|
'class' => '',
|
173
|
'target' => 'default',
|
174
|
'rel' => 'nofollow',
|
175
|
'title' => '',
|
176
|
),
|
177
|
);
|
178
|
|
179
|
$field = $this->createField($field_settings, 0);
|
180
|
//$this->fail('<pre>'. print_r($field, TRUE) .'</pre>');
|
181
|
$field_name = $field['field_name'];
|
182
|
$field_db_info = content_database_info($field);
|
183
|
$url_type = str_replace('_', '-', $this->content_types[0]->type);
|
184
|
|
185
|
$edit = array('attributes[title]' => '['. $field_name .'-url]',
|
186
|
'enable_tokens' => TRUE);
|
187
|
// @codingStandardsIgnoreLine
|
188
|
$this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'],
|
189
|
$edit, t('Save field settings'));
|
190
|
$this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));*/
|
191
|
// @codingStandardsIgnoreEnd
|
192
|
$name = $this->randomName();
|
193
|
$settings = array(
|
194
|
'instance[settings][attributes][rel]' => 'nofollow',
|
195
|
);
|
196
|
|
197
|
$field_name = $this->createLinkField('page', $settings);
|
198
|
|
199
|
// So, having saved this field_name, let's see if it works...
|
200
|
// $this->acquireNodes(1);
|
201
|
// $node = node_load($this->nodes[0]->nid);
|
202
|
// $this->drupalGet('node/'. $this->nodes[0]->nid);.
|
203
|
$edit = array();
|
204
|
$test_link_url = 'http://www.example.com/test';
|
205
|
$edit[$field_name . '[und][0][url]'] = $test_link_url;
|
206
|
$title = 'title_' . $this->randomName(20);
|
207
|
$edit[$field_name . '[und][0][title]'] = $title;
|
208
|
$edit['title'] = $name;
|
209
|
|
210
|
$this->drupalGet('node/add/page');
|
211
|
$this->drupalPost(NULL, $edit, t('Save'));
|
212
|
|
213
|
// Make sure we get a new version!
|
214
|
// $node = node_load($this->nodes[0]->nid, NULL, TRUE);.
|
215
|
$this->assertText(t('Basic page @title has been updated.',
|
216
|
array('@title' => $name)));
|
217
|
|
218
|
// $this->drupalGet('node/'. $node->nid);.
|
219
|
$this->assertText($title, 'Make sure the link title/text shows');
|
220
|
$this->assertRaw(' title="' . $test_link_url . '"', "Do we show the link url as the title attribute?");
|
221
|
$this->assertNoRaw(' title="[' . $field_name . '-url]"');
|
222
|
$this->assertTrue(module_exists('token'), t('Assure that Token Module is enabled.'));
|
223
|
// $this->fail($this->content);.
|
224
|
}
|
225
|
|
226
|
/**
|
227
|
* Link With Title Attribute token title form.
|
228
|
*
|
229
|
* If the title of the link is set to the title attribute, then the title
|
230
|
* attribute isn't supposed to show.
|
231
|
*
|
232
|
* @codingStandardsIgnoreStart
|
233
|
*/
|
234
|
public function xTestLinkWithTitleAttributeTokenTitleForm() {
|
235
|
// @codingStandardsIgnoreEnd
|
236
|
$this->loginWithPermissions($this->permissions);
|
237
|
$this->acquireContentTypes(1);
|
238
|
$field_settings = array(
|
239
|
'type' => 'link',
|
240
|
'widget_type' => 'link',
|
241
|
'type_name' => $this->content_types[0]->name,
|
242
|
'attributes' => array(
|
243
|
'class' => '',
|
244
|
'target' => 'default',
|
245
|
'rel' => 'nofollow',
|
246
|
'title' => '',
|
247
|
),
|
248
|
);
|
249
|
|
250
|
$field = $this->createField($field_settings, 0);
|
251
|
$field_name = $field['field_name'];
|
252
|
$url_type = str_replace('_', '-', $this->content_types[0]->type);
|
253
|
|
254
|
$edit = array(
|
255
|
'attributes[title]' => '[' . $field_name . '-title]',
|
256
|
'enable_tokens' => TRUE,
|
257
|
);
|
258
|
|
259
|
$this->drupalPost('admin/content/node-type/' . $url_type . '/fields/' . $field['field_name'],
|
260
|
$edit, t('Save field settings'));
|
261
|
$this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));
|
262
|
|
263
|
// So, having saved this field_name, let's see if it works...
|
264
|
$this->acquireNodes(1);
|
265
|
|
266
|
$this->drupalGet('node/' . $this->nodes[0]->nid);
|
267
|
|
268
|
$edit = array();
|
269
|
$edit[$field['field_name'] . '[0][url]'] = 'http://www.example.com/test';
|
270
|
$title = 'title_' . $this->randomName(20);
|
271
|
$edit[$field['field_name'] . '[0][title]'] = $title;
|
272
|
|
273
|
$this->drupalPost('node/' . $this->nodes[0]->nid . '/edit', $edit, t('Save'));
|
274
|
|
275
|
// Make sure we get a new version!
|
276
|
$node = node_load($this->nodes[0]->nid, NULL, TRUE);
|
277
|
$this->assertText(t('@type @title has been updated.',
|
278
|
array(
|
279
|
'@title' => $node->title,
|
280
|
'@type' => $this->content_types[0]->name,
|
281
|
)));
|
282
|
|
283
|
$this->drupalGet('node/' . $node->nid);
|
284
|
$this->assertText($title, 'Make sure the link title/text shows');
|
285
|
$this->assertNoRaw(' title="' . $title . '"', "We should not show the link title as the title attribute?");
|
286
|
$this->assertNoRaw(' title="[' . $field_name . '-title]"');
|
287
|
// $this->fail($this->content);.
|
288
|
}
|
289
|
|
290
|
/**
|
291
|
* Trying to set the url to contain a token.
|
292
|
*/
|
293
|
public function xTestUserTokenLinkCreateInUrl() {
|
294
|
$this->web_user = $this->drupalCreateUser(array(
|
295
|
'administer content types',
|
296
|
'administer fields',
|
297
|
'access content',
|
298
|
'create page content',
|
299
|
));
|
300
|
$this->drupalLogin($this->web_user);
|
301
|
|
302
|
// Create field.
|
303
|
$name = strtolower($this->randomName());
|
304
|
$edit = array(
|
305
|
'_add_new_field[label]' => $name,
|
306
|
'_add_new_field[field_name]' => $name,
|
307
|
'_add_new_field[type]' => 'link',
|
308
|
'_add_new_field[widget_type]' => 'link',
|
309
|
);
|
310
|
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
|
311
|
$this->drupalPost(NULL, array(
|
312
|
'title' => 'required',
|
313
|
'enable_tokens' => 1,
|
314
|
), t('Save field settings'));
|
315
|
|
316
|
// Is field created?
|
317
|
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
|
318
|
|
319
|
// Create page form.
|
320
|
$this->drupalGet('node/add/page');
|
321
|
$field_name = 'field_' . $name;
|
322
|
$this->assertField($field_name . '[0][title]', 'Title found');
|
323
|
$this->assertField($field_name . '[0][url]', 'URL found');
|
324
|
|
325
|
$input = array(
|
326
|
'href' => 'http://example.com/' . $this->randomName(),
|
327
|
'label' => $this->randomName(),
|
328
|
);
|
329
|
|
330
|
$this->drupalLogin($this->web_user);
|
331
|
$this->drupalGet('node/add/page');
|
332
|
|
333
|
$edit = array(
|
334
|
'title' => $input['label'],
|
335
|
$field_name . '[0][title]' => $input['label'],
|
336
|
$field_name . '[0][url]' => $input['href'] . "/[type]",
|
337
|
);
|
338
|
$this->drupalPost(NULL, $edit, t('Save'));
|
339
|
$url = $this->getUrl();
|
340
|
|
341
|
// Change to anonymous user.
|
342
|
$this->drupalLogout();
|
343
|
$this->drupalGet($url);
|
344
|
|
345
|
$this->assertRaw(l($input['label'], $input['href'] . '/page'));
|
346
|
// $this->fail($this->content);.
|
347
|
}
|
348
|
|
349
|
/**
|
350
|
* Trying to set the url to contain a token.
|
351
|
*/
|
352
|
public function xTestUserTokenLinkCreateInUrl2() {
|
353
|
$this->web_user = $this->drupalCreateUser(array(
|
354
|
'administer content types',
|
355
|
'administer fields',
|
356
|
'access content',
|
357
|
'create page content',
|
358
|
));
|
359
|
$this->drupalLogin($this->web_user);
|
360
|
|
361
|
// Create field.
|
362
|
$name = strtolower($this->randomName());
|
363
|
$edit = array(
|
364
|
'_add_new_field[label]' => $name,
|
365
|
'_add_new_field[field_name]' => $name,
|
366
|
'_add_new_field[type]' => 'link',
|
367
|
'_add_new_field[widget_type]' => 'link',
|
368
|
);
|
369
|
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
|
370
|
$this->drupalPost(NULL, array(
|
371
|
'title' => 'required',
|
372
|
'enable_tokens' => 1,
|
373
|
), t('Save field settings'));
|
374
|
|
375
|
// Is field created?
|
376
|
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
|
377
|
|
378
|
// Create page form.
|
379
|
$this->drupalGet('node/add/page');
|
380
|
$field_name = 'field_' . $name;
|
381
|
$this->assertField($field_name . '[0][title]', 'Title found');
|
382
|
$this->assertField($field_name . '[0][url]', 'URL found');
|
383
|
|
384
|
$input = array(
|
385
|
'href' => 'http://example.com/' . $this->randomName(),
|
386
|
'label' => $this->randomName(),
|
387
|
);
|
388
|
|
389
|
$this->drupalLogin($this->web_user);
|
390
|
$this->drupalGet('node/add/page');
|
391
|
|
392
|
$edit = array(
|
393
|
'title' => $input['label'],
|
394
|
$field_name . '[0][title]' => $input['label'],
|
395
|
$field_name . '[0][url]' => $input['href'] . "/[author-uid]",
|
396
|
);
|
397
|
$this->drupalPost(NULL, $edit, t('Save'));
|
398
|
$url = $this->getUrl();
|
399
|
|
400
|
// Change to anonymous user.
|
401
|
$this->drupalLogout();
|
402
|
$this->drupalGet($url);
|
403
|
|
404
|
$this->assertRaw(l($input['label'], $input['href'] . '/' . $this->web_user->uid));
|
405
|
}
|
406
|
|
407
|
/**
|
408
|
* CRUD Title Only Title No Link.
|
409
|
*
|
410
|
* Test that if you have a title and no url on a field which does not have
|
411
|
* tokens enabled, that the title is sanitized once.
|
412
|
*
|
413
|
* @codingStandardsIgnoreStart
|
414
|
*/
|
415
|
public function testCRUDTitleOnlyTitleNoLink2() {
|
416
|
//@codingStandardsIgnoreEnd
|
417
|
|
418
|
$this->web_user = $this->drupalCreateUser(array(
|
419
|
'administer content types',
|
420
|
'administer fields',
|
421
|
'access content',
|
422
|
'create page content',
|
423
|
));
|
424
|
|
425
|
$this->drupalLogin($this->web_user);
|
426
|
|
427
|
// Create field.
|
428
|
$name = strtolower($this->randomName());
|
429
|
$field_name = 'field_' . $name;
|
430
|
$edit = array(
|
431
|
'fields[_add_new_field][label]' => $name,
|
432
|
'fields[_add_new_field][field_name]' => $name,
|
433
|
'fields[_add_new_field][type]' => 'link_field',
|
434
|
'fields[_add_new_field][widget_type]' => 'link_field',
|
435
|
);
|
436
|
$this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
|
437
|
$this->drupalPost(NULL, array(), t('Save field settings'));
|
438
|
$this->drupalPost(NULL, array(
|
439
|
'instance[settings][url]' => 1,
|
440
|
'instance[settings][enable_tokens]' => 0,
|
441
|
), t('Save settings'));
|
442
|
|
443
|
// Is field created?
|
444
|
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
|
445
|
|
446
|
// Create page form.
|
447
|
$this->drupalGet('node/add/page');
|
448
|
$this->assertField($field_name . '[und][0][url]', 'URL found');
|
449
|
|
450
|
$input = array(
|
451
|
'title' => 'This & That',
|
452
|
'href' => '',
|
453
|
);
|
454
|
|
455
|
$edit = array(
|
456
|
'title' => $name,
|
457
|
$field_name . '[und][0][title]' => $input['title'],
|
458
|
$field_name . '[und][0][url]' => $input['href'],
|
459
|
);
|
460
|
$this->drupalPost(NULL, $edit, t('Save'));
|
461
|
|
462
|
$url = $this->getUrl();
|
463
|
|
464
|
// Change to anonymous user.
|
465
|
$this->drupalLogout();
|
466
|
$this->drupalGet($url);
|
467
|
|
468
|
$this->assertRaw('This & That');
|
469
|
}
|
470
|
|
471
|
}
|