Projet

Général

Profil

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

root / drupal7 / sites / all / modules / link / tests / LinkFieldCrudTest.test @ bad4e148

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5 bad4e148 Assos Assos
 * Testing that users can not input bad URLs or labels.
6 85ad3d82 Assos Assos
 */
7
8
/**
9 39a181a4 Assos Assos
 * Testing that users can not input bad URLs or labels.
10 85ad3d82 Assos Assos
 */
11 bad4e148 Assos Assos
class LinkFieldCrudTest extends LinkBaseTestClass {
12 85ad3d82 Assos Assos
13
  /**
14 39a181a4 Assos Assos
   * Link supposed to be good.
15 85ad3d82 Assos Assos
   */
16
  const LINK_INPUT_TYPE_GOOD = 0;
17
18
  /**
19 39a181a4 Assos Assos
   * Link supposed to have a bad title.
20 85ad3d82 Assos Assos
   */
21
  const LINK_INPUT_TYPE_BAD_TITLE = 1;
22
23
  /**
24 39a181a4 Assos Assos
   * Link supposed to have a bad URL.
25 85ad3d82 Assos Assos
   */
26
  const LINK_INPUT_TYPE_BAD_URL = 2;
27
28 39a181a4 Assos Assos
  /**
29
   * Get Info.
30
   */
31 85ad3d82 Assos Assos
  public static function getInfo() {
32
    return array(
33
      'name' => 'Link CRUD - browser test',
34
      'description' => 'Tests the field CRUD (create, read, update, delete) API 2.',
35
      'group' => 'Link',
36
    );
37
  }
38
39 39a181a4 Assos Assos
  /**
40 8e7483ab Assos Assos
   * {@inheritdoc}
41 39a181a4 Assos Assos
   */
42 8e7483ab Assos Assos
  public function setUp(array $modules = array()) {
43
    $modules[] = 'field_ui';
44
    $modules[] = 'link';
45
    parent::setUp($modules);
46 85ad3d82 Assos Assos
  }
47
48
  /**
49
   * Creates a link field for the "page" type and creates a page with a link.
50
   */
51 39a181a4 Assos Assos
  public function testLinkCreate() {
52
    // libxml_use_internal_errors(true);
53 85ad3d82 Assos Assos
    $this->web_user = $this->drupalCreateUser(array(
54
      'administer content types',
55 39a181a4 Assos Assos
      'administer fields',
56 85ad3d82 Assos Assos
      'administer nodes',
57
      'administer filters',
58
      'access content',
59
      'create page content',
60 39a181a4 Assos Assos
      'access administration pages',
61 85ad3d82 Assos Assos
    ));
62
    $this->drupalLogin($this->web_user);
63
64 39a181a4 Assos Assos
    // Create field.
65 85ad3d82 Assos Assos
    $name = strtolower($this->randomName());
66
    $edit = array(
67
      'fields[_add_new_field][label]' => $name,
68
      'fields[_add_new_field][field_name]' => $name,
69
      'fields[_add_new_field][type]' => 'link_field',
70
      'fields[_add_new_field][widget_type]' => 'link_field',
71
    );
72
    $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
73
    $this->drupalPost(NULL, array(), t('Save field settings'));
74
    $this->drupalPost(NULL, array(), t('Save settings'));
75
76
    // Is field created?
77
    $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
78
    node_types_rebuild();
79
    menu_rebuild();
80
81
    $permission = 'create page content';
82
    $this->checkPermissions(array($permission), TRUE);
83
84 39a181a4 Assos Assos
    // Create page form
85
    // $this->drupalGet('node/add');.
86 85ad3d82 Assos Assos
    $this->drupalGet('node/add/page');
87
    $field_name = 'field_' . $name;
88 c8740e19 Assos Assos
    $this->assertField('edit-field-' . $name . '-und-0-title', 'Title found');
89
    $this->assertField('edit-field-' . $name . '-und-0-url', 'URL found');
90 85ad3d82 Assos Assos
91
    $input_test_cases = array(
92
      array(
93
        'href' => 'http://example.com/' . $this->randomName(),
94
        'label' => $this->randomName(),
95
        'msg' => 'Link found',
96 39a181a4 Assos Assos
        'type' => self::LINK_INPUT_TYPE_GOOD,
97 85ad3d82 Assos Assos
      ),
98
      array(
99
        'href' => 'http://example.com/' . $this->randomName(),
100
        'label' => $this->randomName() . '<script>alert("hi");</script>',
101 bad4e148 Assos Assos
        'msg' => 'JS in label',
102 39a181a4 Assos Assos
        'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
103 85ad3d82 Assos Assos
      ),
104
      array(
105
        'href' => 'http://example.com/' . $this->randomName(),
106
        'label' => $this->randomName() . '<script src="http://devil.site.com"></script>',
107 bad4e148 Assos Assos
        'msg' => 'Remote JS in label',
108 39a181a4 Assos Assos
        'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
109 85ad3d82 Assos Assos
      ),
110
      array(
111
        'href' => 'http://example.com/' . $this->randomName(),
112
        'label' => $this->randomName() . '" onmouseover="alert(\'hi\')',
113 bad4e148 Assos Assos
        'msg' => 'JS in label',
114 39a181a4 Assos Assos
        'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
115 85ad3d82 Assos Assos
      ),
116
      array(
117
        'href' => 'http://example.com/' . $this->randomName(),
118
        'label' => $this->randomName() . '\' onmouseover="alert(\'hi\')',
119 bad4e148 Assos Assos
        'msg' => 'Escaped JS in label',
120 39a181a4 Assos Assos
        'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
121 85ad3d82 Assos Assos
      ),
122
      array(
123
        'href' => 'javascript:alert("http://example.com/' . $this->randomName() . '")',
124
        'label' => $this->randomName(),
125 bad4e148 Assos Assos
        'msg' => 'JS in URL',
126 39a181a4 Assos Assos
        'type' => self::LINK_INPUT_TYPE_BAD_URL,
127 85ad3d82 Assos Assos
      ),
128 bad4e148 Assos Assos
      array(
129
        'href' => 'http://example.com?foo=bar&fruit=mango',
130
        'label' => $this->randomName(),
131
        'msg' => 'URL with querystring',
132
        'type' => self::LINK_INPUT_TYPE_GOOD,
133
      ),
134 85ad3d82 Assos Assos
      array(
135
        'href' => 'http://ecs-es.kelkoo.es/ctl/go/sitesearchGo?.ts=1338833010331&.sig=qP9GXeEFH6syBzwmzYkxmsvp1EI-',
136
        'label' => 'http://ecs-es.kelkoo.es/ctl/go/sitesearchGo?.ts=1338833010331&.sig=qP9GXeEFH6syBzwmzYkxmsvp1EI-',
137 bad4e148 Assos Assos
        'msg' => 'URL with . in querystring',
138 85ad3d82 Assos Assos
        'type' => self::LINK_INPUT_TYPE_GOOD,
139
      ),
140
    );
141
    $test_case = array(
142 c8740e19 Assos Assos
      'href' => 'www.example.com/' . $this->randomName(),
143 85ad3d82 Assos Assos
      'label' => $this->randomName(),
144
      'msg' => 'Link found',
145
      'type' => self::LINK_INPUT_TYPE_GOOD,
146
    );
147 c8740e19 Assos Assos
    $test_case['expected_href'] = 'http://' . $test_case['href'];
148 85ad3d82 Assos Assos
    $input_test_cases[] = $test_case;
149
150
    foreach ($input_test_cases as $input) {
151
      $this->drupalLogin($this->web_user);
152
      $this->drupalGet('node/add/page');
153
154
      $edit = array(
155
        'title' => $input['label'],
156
        $field_name . '[und][0][title]' => $input['label'],
157
        $field_name . '[und][0][url]' => $input['href'],
158
      );
159
      $this->drupalPost(NULL, $edit, t('Save'));
160
      if ($input['type'] == self::LINK_INPUT_TYPE_BAD_URL) {
161 39a181a4 Assos Assos
        $this->assertRaw(t('The value %value provided for %field is not a valid URL.', array(
162
          '%field' => $name,
163
          '%value' => trim($input['href']),
164
        )), 'Not a valid URL: ' . $input['href']);
165 85ad3d82 Assos Assos
        continue;
166
      }
167
      else {
168 c8740e19 Assos Assos
        $this->assertRaw(' ' . t('has been created.',
169 39a181a4 Assos Assos
            array('@type' => 'Basic Page', '%title' => $edit['title'])),
170
          'Page created: ' . $input['href']);
171 85ad3d82 Assos Assos
      }
172
      $url = $this->getUrl();
173
174 39a181a4 Assos Assos
      // Change to Anonymous user.
175 85ad3d82 Assos Assos
      $this->drupalLogout();
176
177
      $this->drupalGet($url);
178 39a181a4 Assos Assos
      // debug($this);
179
      // If simpletest starts using something to override the error system, this
180
      // will flag us and let us know it's broken.
181 85ad3d82 Assos Assos
      $this->assertFalse(libxml_use_internal_errors(TRUE));
182 bad4e148 Assos Assos
      $expected_href = $input['href'];
183 85ad3d82 Assos Assos
      if (isset($input['expected_href'])) {
184 bad4e148 Assos Assos
        $expected_href = $input['expected_href'];
185 85ad3d82 Assos Assos
      }
186 bad4e148 Assos Assos
      $elements = $this->xpath('//a[@href="' . $expected_href . '" and text()="' . $input['label'] . '"]');
187 85ad3d82 Assos Assos
      libxml_use_internal_errors(FALSE);
188
      $this->assertIdentical(isset($elements[0]), $input['type'] == self::LINK_INPUT_TYPE_GOOD, $input['msg']);
189
    }
190 39a181a4 Assos Assos
    // libxml_use_internal_errors(FALSE);
191 85ad3d82 Assos Assos
  }
192
193
  /**
194 39a181a4 Assos Assos
   * Static Link Create.
195
   *
196 85ad3d82 Assos Assos
   * Testing that if you use <strong> in a static title for your link, that the
197
   * title actually displays <strong>.
198
   */
199 39a181a4 Assos Assos
  public function testStaticLinkCreate() {
200
    $this->web_user = $this->drupalCreateUser(array(
201
      'administer content types',
202
      'administer fields',
203
      'access content',
204
      'create page content',
205
    ));
206
207 85ad3d82 Assos Assos
    $this->drupalLogin($this->web_user);
208
209 39a181a4 Assos Assos
    // Create field.
210 85ad3d82 Assos Assos
    $name = strtolower($this->randomName());
211 c8740e19 Assos Assos
    $field_name = 'field_' . $name;
212 85ad3d82 Assos Assos
    $edit = array(
213
      'fields[_add_new_field][label]' => $name,
214
      'fields[_add_new_field][field_name]' => $name,
215
      'fields[_add_new_field][type]' => 'link_field',
216
      'fields[_add_new_field][widget_type]' => 'link_field',
217
    );
218
    $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
219
    $this->drupalPost(NULL, array(), t('Save field settings'));
220
    $this->drupalPost(NULL, array(
221
      'instance[settings][title]' => 'value',
222 39a181a4 Assos Assos
      'instance[settings][title_value]' => '<strong>' . $name . '</strong>',
223
    ), t('Save settings'));
224 85ad3d82 Assos Assos
225
    // Is field created?
226
    $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
227
228 39a181a4 Assos Assos
    // Create page form.
229 85ad3d82 Assos Assos
    $this->drupalGet('node/add/page');
230
    $this->assertField($field_name . '[und][0][url]', 'URL found');
231
232
    $input = array(
233 39a181a4 Assos Assos
      'href' => 'http://example.com/' . $this->randomName(),
234 85ad3d82 Assos Assos
    );
235
236
    $edit = array(
237
      'title' => $name,
238
      $field_name . '[und][0][url]' => $input['href'],
239
    );
240
    $this->drupalPost(NULL, $edit, t('Save'));
241
242
    $url = $this->getUrl();
243
244 39a181a4 Assos Assos
    // Change to anonymous user.
245 85ad3d82 Assos Assos
    $this->drupalLogout();
246
    $this->drupalGet($url);
247
248 c8740e19 Assos Assos
    $this->assertRaw(l('<strong>' . $name . '</strong>', $input['href'], array('html' => TRUE)));
249
  }
250 39a181a4 Assos Assos
251 c8740e19 Assos Assos
  /**
252 39a181a4 Assos Assos
   * CRUD Title Only Title No Link.
253
   *
254
   * Testing that if you have the title but no url, the title is not sanitized
255
   * twice.
256 c8740e19 Assos Assos
   */
257 8e7483ab Assos Assos
  public function testCrudTitleOnlyTitleNoLink() {
258 39a181a4 Assos Assos
    $this->web_user = $this->drupalCreateUser(array(
259
      'administer content types',
260
      'administer fields',
261
      'access content',
262
      'create page content',
263
    ));
264 c8740e19 Assos Assos
    $this->drupalLogin($this->web_user);
265
266 39a181a4 Assos Assos
    // Create field.
267 c8740e19 Assos Assos
    $name = strtolower($this->randomName());
268
    $field_name = 'field_' . $name;
269
    $edit = array(
270
      'fields[_add_new_field][label]' => $name,
271
      'fields[_add_new_field][field_name]' => $name,
272
      'fields[_add_new_field][type]' => 'link_field',
273
      'fields[_add_new_field][widget_type]' => 'link_field',
274
    );
275
    $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
276
    $this->drupalPost(NULL, array(), t('Save field settings'));
277
    $this->drupalPost(NULL, array(
278
      'instance[settings][url]' => 1,
279
    ), t('Save settings'));
280
281
    // Is field created?
282
    $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
283 39a181a4 Assos Assos
284
    // Create page form.
285 c8740e19 Assos Assos
    $this->drupalGet('node/add/page');
286
    $this->assertField($field_name . '[und][0][url]', 'URL found');
287
288
    $input = array(
289
      'title' => 'This & That',
290
      'href' => '',
291
    );
292
293
    $edit = array(
294
      'title' => $name,
295
      $field_name . '[und][0][title]' => $input['title'],
296
      $field_name . '[und][0][url]' => $input['href'],
297
    );
298
    $this->drupalPost(NULL, $edit, t('Save'));
299
300
    $url = $this->getUrl();
301 39a181a4 Assos Assos
302
    // Change to anonymous user.
303 c8740e19 Assos Assos
    $this->drupalLogout();
304
    $this->drupalGet($url);
305
306
    $this->assertRaw('This &amp; That');
307 85ad3d82 Assos Assos
  }
308
309
  /**
310 39a181a4 Assos Assos
   * CRUD Create Field Defaults.
311
   *
312
   * If we're creating a new field and just hit 'save' on the default options,
313
   * we want to make sure they are set to the expected results.
314 85ad3d82 Assos Assos
   */
315 8e7483ab Assos Assos
  public function testCrudCreateFieldDefaults() {
316 39a181a4 Assos Assos
    $this->web_user = $this->drupalCreateUser(array(
317
      'administer content types',
318
      'administer fields',
319
      'access content',
320
      'create page content',
321
    ));
322
323 85ad3d82 Assos Assos
    $this->drupalLogin($this->web_user);
324
325 39a181a4 Assos Assos
    // Create field.
326 85ad3d82 Assos Assos
    $name = strtolower($this->randomName());
327
    $edit = array(
328
      'fields[_add_new_field][label]' => $name,
329
      'fields[_add_new_field][field_name]' => $name,
330
      'fields[_add_new_field][type]' => 'link_field',
331
      'fields[_add_new_field][widget_type]' => 'link_field',
332
    );
333
    $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
334
    $this->drupalPost(NULL, array(), t('Save field settings'));
335
    $this->drupalPost(NULL, array(), t('Save settings'));
336
337
    // Is field created?
338
    $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
339
    node_types_rebuild();
340
    menu_rebuild();
341 c8740e19 Assos Assos
342 85ad3d82 Assos Assos
    _field_info_collate_fields(TRUE);
343
    $instances = field_info_instances('node', 'page');
344 c8740e19 Assos Assos
345
    $instance = $instances['field_' . $name];
346 85ad3d82 Assos Assos
    $this->assertFalse($instance['required'], 'Make sure field is not required.');
347
    $this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.');
348 c8740e19 Assos Assos
    $this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.');
349
    $this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.');
350 85ad3d82 Assos Assos
    $this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.');
351
    $this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"');
352
    $this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.');
353
    $this->assertFalse($instance['settings']['attributes']['class'], 'By default, no class should be set.');
354
    $this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
355
  }
356 39a181a4 Assos Assos
357 7fe061e8 Assos Assos
  /**
358 39a181a4 Assos Assos
   * CRUD Create Field With Class.
359
   *
360
   * If we're creating a new field and just hit 'save' on the default options,
361
   * we want to make sure they are set to the expected results.
362 7fe061e8 Assos Assos
   */
363 8e7483ab Assos Assos
  public function testCrudCreateFieldWithClass() {
364 39a181a4 Assos Assos
    $this->web_user = $this->drupalCreateUser(array(
365
      'administer content types',
366
      'administer fields',
367
      'access content',
368
      'create page content',
369
    ));
370 7fe061e8 Assos Assos
    $this->drupalLogin($this->web_user);
371
372 39a181a4 Assos Assos
    // Create field.
373 7fe061e8 Assos Assos
    $name = strtolower($this->randomName());
374
    $edit = array(
375
      'fields[_add_new_field][label]' => $name,
376
      'fields[_add_new_field][field_name]' => $name,
377
      'fields[_add_new_field][type]' => 'link_field',
378
      'fields[_add_new_field][widget_type]' => 'link_field',
379
    );
380
    $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
381
382
    $this->drupalPost(NULL, array(), t('Save field settings'));
383
    $link_class_name = 'basic-link-' . strtolower($this->randomName());
384
    $edit = array(
385
      'instance[settings][attributes][class]' => $link_class_name,
386
    );
387
    $this->drupalPost(NULL, $edit, t('Save settings'));
388
389
    // Is field created?
390
    $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
391
    node_types_rebuild();
392
    menu_rebuild();
393
394
    _field_info_collate_fields(TRUE);
395
    $instances = field_info_instances('node', 'page');
396
397
    $instance = $instances['field_' . $name];
398
    $this->assertFalse($instance['required'], 'Make sure field is not required.');
399
    $this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.');
400
    $this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.');
401
    $this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.');
402
    $this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.');
403
    $this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"');
404
    $this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.');
405
    $this->assertEqual($instance['settings']['attributes']['class'], $link_class_name, 'One class should be set.');
406
    $this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
407 39a181a4 Assos Assos
408 7fe061e8 Assos Assos
    // Now, let's create a node with this field and make sure the link shows up:
409 39a181a4 Assos Assos
    // create page form.
410 7fe061e8 Assos Assos
    $field_name = 'field_' . $name;
411
    $this->drupalGet('node/add/page');
412
    $this->assertField($field_name . '[und][0][url]', 'URL found');
413
414
    $input = array(
415
      'title' => 'This & That',
416
      'href' => 'http://www.example.com/',
417
    );
418
419
    $edit = array(
420
      'title' => $field_name,
421
      $field_name . '[und][0][title]' => $input['title'],
422
      $field_name . '[und][0][url]' => $input['href'],
423
    );
424
    $this->drupalPost(NULL, $edit, t('Save'));
425
426
    $url = $this->getUrl();
427 39a181a4 Assos Assos
428
    // Change to anonymous user.
429 7fe061e8 Assos Assos
    $this->drupalLogout();
430
    $this->drupalGet($url);
431
432
    $this->assertRaw('This &amp; That');
433
    $this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Class $link_class_name exists on page.");
434
  }
435
436 39a181a4 Assos Assos
  /**
437
   * CRUD Create Field With Two Classes.
438
   *
439
   * If we're creating a new field and just hit 'save' on the default options,
440
   * we want to make sure they are set to the expected results.
441 7fe061e8 Assos Assos
   */
442 8e7483ab Assos Assos
  public function testCrudCreateFieldWithTwoClasses() {
443 39a181a4 Assos Assos
    $this->web_user = $this->drupalCreateUser(array(
444
      'administer content types',
445
      'administer fields',
446
      'access content',
447
      'create page content',
448
    ));
449 7fe061e8 Assos Assos
    $this->drupalLogin($this->web_user);
450
451 39a181a4 Assos Assos
    // Create field.
452 7fe061e8 Assos Assos
    $name = strtolower($this->randomName());
453
    $edit = array(
454
      'fields[_add_new_field][label]' => $name,
455
      'fields[_add_new_field][field_name]' => $name,
456
      'fields[_add_new_field][type]' => 'link_field',
457
      'fields[_add_new_field][widget_type]' => 'link_field',
458
    );
459
    $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
460
461
    $this->drupalPost(NULL, array(), t('Save field settings'));
462
    $link_class_name = 'basic-link ' . strtoupper($this->randomName());
463
    $edit = array(
464
      'instance[settings][attributes][class]' => $link_class_name,
465
    );
466
    $this->drupalPost(NULL, $edit, t('Save settings'));
467
468
    // Is field created?
469
    $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
470
    node_types_rebuild();
471
    menu_rebuild();
472
473
    _field_info_collate_fields(TRUE);
474
    $instances = field_info_instances('node', 'page');
475
476
    $instance = $instances['field_' . $name];
477
    $this->assertFalse($instance['required'], 'Make sure field is not required.');
478
    $this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.');
479
    $this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.');
480
    $this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.');
481
    $this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.');
482
    $this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"');
483
    $this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.');
484
    $this->assertEqual($instance['settings']['attributes']['class'], $link_class_name, 'Two classes should be set.');
485
    $this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
486 39a181a4 Assos Assos
487 7fe061e8 Assos Assos
    // Now, let's create a node with this field and make sure the link shows up:
488 39a181a4 Assos Assos
    // create page form.
489 7fe061e8 Assos Assos
    $field_name = 'field_' . $name;
490
    $this->drupalGet('node/add/page');
491
    $this->assertField($field_name . '[und][0][url]', 'URL found');
492
493
    $input = array(
494
      'title' => 'This & That',
495
      'href' => 'http://www.example.com/',
496
    );
497
498
    $edit = array(
499
      'title' => $field_name,
500
      $field_name . '[und][0][title]' => $input['title'],
501
      $field_name . '[und][0][url]' => $input['href'],
502
    );
503
    $this->drupalPost(NULL, $edit, t('Save'));
504
505
    $url = $this->getUrl();
506 39a181a4 Assos Assos
507
    // Change to anonymous user.
508 7fe061e8 Assos Assos
    $this->drupalLogout();
509
    $this->drupalGet($url);
510
511
    $this->assertRaw('This &amp; That');
512
    $this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Classes $link_class_name exist on page.");
513
  }
514 39a181a4 Assos Assos
515 bad4e148 Assos Assos
  /**
516
   * Tests that link titles properly preserve the query params.
517
   */
518
  public function testLinkTitlePreservesQueryParams() {
519
    // Create field.
520
    $field_name = $this->createLinkField();
521
522
    // Create page form.
523
    $this->drupalGet('node/add/page');
524
    $this->assertField($field_name . '[und][0][title]', 'Title found');
525
    $this->assertField($field_name . '[und][0][url]', 'URL found');
526
527
    $link_title_tests = array(
528
      array(
529
        'href' => 'http://example.com/' . $this->randomName(),
530
      ),
531
      array(
532
        'href' => 'http://example.com/' . $this->randomName() . '?property=value',
533
      ),
534
      array(
535
        'href' => 'http://example.com/' . $this->randomName() . '#position',
536
      ),
537
      array(
538
        'href' => 'http://example.com/' . $this->randomName() . '#lower?property=value2',
539
      ),
540
      array(
541
        'href' => 'http://example.com/' . $this->randomName() . '?property=value2#lower',
542
      ),
543
    );
544
545
    foreach ($link_title_tests as &$input) {
546
      $this->drupalGet('node/add/page');
547
      $this->assertResponse(200);
548
549
      // Intentionally set empty title, to force using the url as the title.
550
      $edit = array(
551
        'title' => 'Some node title',
552
        $field_name . '[und][0][title]' => '',
553
        $field_name . '[und][0][url]' => $input['href'],
554
      );
555
      $this->drupalPost(NULL, $edit, t('Save'));
556
      // Confirm the node saved correctly.
557
      $this->assertResponse(200);
558
      $this->assertText($edit['title']);
559
      $input['url'] = $this->getUrl();
560
    }
561
562
    // Change to anonymous user.
563
    $this->drupalLogout();
564
565
    // Loop over the nodes, confirm each URL is rendered correctly.
566
    foreach ($link_title_tests as $input) {
567
      $this->drupalGet($input['url']);
568
      $this->assertRaw(l($input['href'], $input['href']), "Test that the link title has been set to " . $input['href']);
569
    }
570
  }
571
572 85ad3d82 Assos Assos
}