Projet

Général

Profil

Paste
Télécharger (12,1 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / link / tests / link.token.test @ a5572547

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5
 * Contains simpletests making sure token integration works.
6
 */
7
8
/**
9
 * Testing that tokens can be used in link titles
10
 */
11
class LinkTokenTest extends LinkBaseTestClass {
12
13
  public static function getInfo() {
14
    return array(
15
      'name' => 'Link tokens - browser test',
16
      'description' => 'Tests including tokens in link titles, making sure they appear in node views.',
17
      'group' => 'Link',
18
      'dependencies' => array('token'),
19
    );
20
  }
21
22
  function setUp($modules = array()) {
23
    parent::setUp(array('token'));
24
  }
25
26
  /**
27
   * Creates a link field with a required title enabled for user-entered tokens.
28
   * Creates a node with a token in the link title and checks the value.
29
   */
30
  function testUserTokenLinkCreate() {
31
    // create field
32
    $settings = array(
33
      'instance[settings][enable_tokens]' => 1,
34
    );
35
    $field_name = $this->createLinkField('page',
36
                                        $settings);
37
38
    // create page form
39
    $this->drupalGet('node/add/page');
40
    //$field_name = 'field_' . $name;
41
    $this->assertField($field_name . '[und][0][title]', 'Title found');
42
    $this->assertField($field_name . '[und][0][url]', 'URL found');
43
44
    $input = array(
45
        'href' => 'http://example.com/' . $this->randomName(),
46
        'label' => $this->randomName(),
47
    );
48
49
    //$this->drupalLogin($this->web_user);
50
    $this->drupalGet('node/add/page');
51
52
    $edit = array(
53
      'title' => $input['label'],
54
      $field_name . '[und][0][title]' => $input['label'] . " [node:content-type:machine-name]",
55
      $field_name . '[und][0][url]' => $input['href'],
56
    );
57
    $this->drupalPost(NULL, $edit, t('Save'));
58
    $url = $this->getUrl();
59
60
    // change to anonymous user
61
    $this->drupalLogout();
62
    $this->drupalGet($url);
63
64
    $this->assertRaw(l($input['label'] . ' page', $input['href']));
65
  }
66
67
68
  /**
69
   * Creates a link field with a static title and an admin-entered token.
70
   * Creates a node with a link and checks the title value.
71
   */
72
  function testStaticTokenLinkCreate() {
73
74
    // create field
75
    $name = $this->randomName();
76
    $settings = array(
77
      'instance[settings][title]' => 'value',
78
      'instance[settings][title_value]' => $name .' [node:content-type:machine-name]');
79
    $field_name = $this->createLinkField('page', $settings);
80
81
    // create page form
82
    $this->drupalGet('node/add/page');
83
    $this->assertField($field_name . '[und][0][url]', 'URL found');
84
85
    $input = array(
86
      'href' => 'http://example.com/' . $this->randomName()
87
    );
88
89
    //$this->drupalLogin($this->web_user);
90
    $this->drupalGet('node/add/page');
91
92
    $edit = array(
93
      'title' => $name,
94
      $field_name . '[und][0][url]' => $input['href'],
95
    );
96
    $this->drupalPost(NULL, $edit, t('Save'));
97
98
    $url = $this->getUrl();
99
100
    // change to anonymous user
101
    $this->drupalLogout();
102
    $this->drupalGet($url);
103
104
    $this->assertRaw(l($name . ' page', $input['href']));
105
  }
106
107
  /**
108
   * Creates a link field with a static title and an admin-entered token.
109
   * Creates a node with a link and checks the title value.
110
   *
111
   * Basically, I want to make sure the [title-raw] token works, because it's a
112
   * token that changes from node to node, where [type]'s always going to be the
113
   * same.
114
   */
115
  function testStaticTokenLinkCreate2() {
116
117
    // create field
118
    $name = $this->randomName();
119
    $settings = array(
120
      'instance[settings][title]' => 'value',
121
      'instance[settings][title_value]' => $name .' [node:title]');
122
    $field_name = $this->createLinkField('page', $settings);
123
124
    // create page form
125
    $this->drupalGet('node/add/page');
126
    $this->assertField($field_name . '[und][0][url]', 'URL found');
127
128
    $input = array(
129
      'href' => 'http://example.com/' . $this->randomName()
130
    );
131
132
    //$this->drupalLogin($this->web_user);
133
    $this->drupalGet('node/add/page');
134
135
    $edit = array(
136
      'title' => $name,
137
      $field_name . '[und][0][url]' => $input['href'],
138
    );
139
    $this->drupalPost(NULL, $edit, t('Save'));
140
141
    $url = $this->getUrl();
142
143
    // change to anonymous user
144
    $this->drupalLogout();
145
    $this->drupalGet($url);
146
147
    $this->assertRaw(l($name .' '. $name, $input['href']));
148
  }
149
150
  // This test doesn't seem to actually work, due to lack of 'title' in url.
151
  function _test_Link_With_Title_Attribute_token_url_form() {
152
   /* $this->loginWithPermissions($this->permissions);
153
    $this->acquireContentTypes(1);
154
    $field_settings = array(
155
      'type' => 'link',
156
      'widget_type' => 'link',
157
      'type_name' => $this->content_types[0]->name,
158
      'attributes' => array(
159
        'class' => '',
160
        'target' => 'default',
161
        'rel' => 'nofollow',
162
        'title' => '',
163
      ),
164
    );
165
166
    $field = $this->createField($field_settings, 0);
167
    //$this->fail('<pre>'. print_r($field, TRUE) .'</pre>');
168
    $field_name = $field['field_name'];
169
    $field_db_info = content_database_info($field);
170
    $url_type = str_replace('_', '-', $this->content_types[0]->type);
171
172
    $edit = array('attributes[title]' => '['. $field_name .'-url]',
173
                  'enable_tokens' => TRUE);
174
175
    $this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'],
176
                      $edit, t('Save field settings'));
177
    $this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));*/
178
    $name = $this->randomName();
179
    $settings = array(
180
      'instance[settings][attributes][rel]' => 'nofollow',
181
    );
182
183
    $field_name = $this->createLinkField('page', $settings);
184
185
    // So, having saved this field_name, let's see if it works...
186
    //$this->acquireNodes(1);
187
188
    //$node = node_load($this->nodes[0]->nid);
189
190
    //$this->drupalGet('node/'. $this->nodes[0]->nid);
191
192
    $edit = array();
193
    $test_link_url = 'http://www.example.com/test';
194
    $edit[$field_name .'[und][0][url]'] = $test_link_url;
195
    $title = 'title_'. $this->randomName(20);
196
    $edit[$field_name .'[und][0][title]'] = $title;
197
    $edit['title'] = $name;
198
199
    $this->drupalGet('node/add/page');
200
    $this->drupalPost(NULL, $edit, t('Save'));
201
202
    // Make sure we get a new version!
203
    //$node = node_load($this->nodes[0]->nid, NULL, TRUE);
204
    $this->assertText(t('Basic page @title has been updated.',
205
                        array('@title' => $name)));
206
207
    //$this->drupalGet('node/'. $node->nid);
208
    $this->assertText($title, 'Make sure the link title/text shows');
209
    $this->assertRaw(' title="'. $test_link_url .'"', "Do we show the link url as the title attribute?");
210
    $this->assertNoRaw(' title="['. $field_name .'-url]"');
211
    $this->assertTrue(module_exists('token'), t('Assure that Token Module is enabled.'));
212
    //$this->fail($this->content);
213
  }
214
215
  /**
216
   * If the title of the link is set to the title attribute, then the title
217
   * attribute isn't supposed to show.
218
   */
219
  function _test_Link_With_Title_Attribute_token_title_form() {
220
    $this->loginWithPermissions($this->permissions);
221
    $this->acquireContentTypes(1);
222
    $field_settings = array(
223
      'type' => 'link',
224
      'widget_type' => 'link',
225
      'type_name' => $this->content_types[0]->name,
226
      'attributes' => array(
227
        'class' => '',
228
        'target' => 'default',
229
        'rel' => 'nofollow',
230
        'title' => '',
231
      ),
232
    );
233
234
    $field = $this->createField($field_settings, 0);
235
    $field_name = $field['field_name'];
236
    $field_db_info = content_database_info($field);
237
    $url_type = str_replace('_', '-', $this->content_types[0]->type);
238
239
    $edit = array('attributes[title]' => '['. $field_name .'-title]',
240
                  'enable_tokens' => TRUE);
241
242
    $this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'],
243
                      $edit, t('Save field settings'));
244
    $this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));
245
246
    // So, having saved this field_name, let's see if it works...
247
    $this->acquireNodes(1);
248
249
    $node = node_load($this->nodes[0]->nid);
250
251
    $this->drupalGet('node/'. $this->nodes[0]->nid);
252
253
    $edit = array();
254
    $edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test';
255
    $title = 'title_'. $this->randomName(20);
256
    $edit[$field['field_name'] .'[0][title]'] = $title;
257
258
    $this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save'));
259
260
    // Make sure we get a new version!
261
    $node = node_load($this->nodes[0]->nid, NULL, TRUE);
262
    $this->assertText(t('@type @title has been updated.',
263
                        array('@title' => $node->title,
264
                              '@type' => $this->content_types[0]->name)));
265
266
    $this->drupalGet('node/'. $node->nid);
267
    $this->assertText($title, 'Make sure the link title/text shows');
268
    $this->assertNoRaw(' title="'. $title .'"', "We should not show the link title as the title attribute?");
269
    $this->assertNoRaw(' title="['. $field_name .'-title]"');
270
    //$this->fail($this->content);
271
  }
272
273
  /**
274
   *  Trying to set the url to contain a token.
275
   */
276
  function _testUserTokenLinkCreateInURL() {
277
    $this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
278
    $this->drupalLogin($this->web_user);
279
280
    // create field
281
    $name = strtolower($this->randomName());
282
    $edit = array(
283
      '_add_new_field[label]' => $name,
284
      '_add_new_field[field_name]' => $name,
285
      '_add_new_field[type]' => 'link',
286
      '_add_new_field[widget_type]' => 'link',
287
    );
288
    $this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
289
    $this->drupalPost(NULL, array(
290
      'title' => 'required',
291
      'enable_tokens' => 1), t('Save field settings'));
292
293
    // Is field created?
294
    $this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
295
296
    // create page form
297
    $this->drupalGet('node/add/page');
298
    $field_name = 'field_' . $name;
299
    $this->assertField($field_name . '[0][title]', 'Title found');
300
    $this->assertField($field_name . '[0][url]', 'URL found');
301
302
    $input = array(
303
        'href' => 'http://example.com/' . $this->randomName(),
304
        'label' => $this->randomName(),
305
    );
306
307
    $this->drupalLogin($this->web_user);
308
    $this->drupalGet('node/add/page');
309
310
    $edit = array(
311
      'title' => $input['label'],
312
      $field_name . '[0][title]' => $input['label'],
313
      $field_name . '[0][url]' => $input['href'] . "/[type]",
314
    );
315
    $this->drupalPost(NULL, $edit, t('Save'));
316
    $url = $this->getUrl();
317
318
    // change to anonymous user
319
    $this->drupalLogout();
320
    $this->drupalGet($url);
321
322
    $this->assertRaw(l($input['label'], $input['href'] .'/page'));
323
    //$this->fail($this->content);
324
  }
325
326
  /**
327
   *  Trying to set the url to contain a token.
328
   */
329
  function _testUserTokenLinkCreateInURL2() {
330
    $this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
331
    $this->drupalLogin($this->web_user);
332
333
    // create field
334
    $name = strtolower($this->randomName());
335
    $edit = array(
336
      '_add_new_field[label]' => $name,
337
      '_add_new_field[field_name]' => $name,
338
      '_add_new_field[type]' => 'link',
339
      '_add_new_field[widget_type]' => 'link',
340
    );
341
    $this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
342
    $this->drupalPost(NULL, array(
343
      'title' => 'required',
344
      'enable_tokens' => 1), t('Save field settings'));
345
346
    // Is field created?
347
    $this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
348
349
    // create page form
350
    $this->drupalGet('node/add/page');
351
    $field_name = 'field_' . $name;
352
    $this->assertField($field_name . '[0][title]', 'Title found');
353
    $this->assertField($field_name . '[0][url]', 'URL found');
354
355
    $input = array(
356
        'href' => 'http://example.com/' . $this->randomName(),
357
        'label' => $this->randomName(),
358
    );
359
360
    $this->drupalLogin($this->web_user);
361
    $this->drupalGet('node/add/page');
362
363
    $edit = array(
364
      'title' => $input['label'],
365
      $field_name . '[0][title]' => $input['label'],
366
      $field_name . '[0][url]' => $input['href'] . "/[author-uid]",
367
    );
368
    $this->drupalPost(NULL, $edit, t('Save'));
369
    $url = $this->getUrl();
370
371
    // change to anonymous user
372
    $this->drupalLogout();
373
    $this->drupalGet($url);
374
375
    $this->assertRaw(l($input['label'], $input['href'] .'/'. $this->web_user->uid));
376
  }
377
}