Projet

Général

Profil

Révision 39a181a4

Ajouté par Assos Assos il y a environ 6 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/link/tests/link.validate.test
5 5
 * Tests that exercise the validation functions in the link module.
6 6
 */
7 7

  
8
/**
9
 * Validate Test Case.
10
 */
8 11
class LinkValidateTestCase extends LinkBaseTestClass {
9 12

  
13
  /**
14
   * Create Link.
15
   */
10 16
  protected function createLink($url, $title, $attributes = array()) {
11 17
    return array(
12 18
      'url' => $url,
......
17 23

  
18 24
  /**
19 25
   * Takes a url, and sees if it can validate that the url is valid.
26
   *
27
   * @codingStandardsIgnoreStart
20 28
   */
21 29
  protected function link_test_validate_url($url) {
30
    // @codingStandardsIgnoreEnd
22 31

  
23 32
    $field_name = $this->createLinkField();
24 33

  
......
26 35
    $settings = array(
27 36
      'title' => $label,
28 37
      $field_name => array(
29
        LANGUAGE_NONE=> array(
38
        LANGUAGE_NONE => array(
30 39
          array(
31 40
            'title' => $label,
32 41
            'url' => $url,
33
          )
42
          ),
34 43
        ),
35 44
      ),
36 45
    );
......
41 50

  
42 51
    $this->assertEqual($url, $node->{$field_name}[LANGUAGE_NONE][0]['url']);
43 52
  }
53

  
44 54
}
45 55

  
56
/**
57
 * Class for Validate Test.
58
 */
46 59
class LinkValidateTest extends LinkValidateTestCase {
47 60

  
61
  /**
62
   * Get Info.
63
   */
48 64
  public static function getInfo() {
49 65
    return array(
50 66
      'name' => 'Link Validation Tests',
......
53 69
    );
54 70
  }
55 71

  
56
  function test_link_validate_basic_url() {
72
  /**
73
   * Validate basic URL.
74
   *
75
   * @codingStandardsIgnoreStart
76
   */
77
  public function test_link_validate_basic_url() {
78
    // @codingStandardsIgnoreEnd
57 79
    $this->link_test_validate_url('http://www.example.com');
58 80
  }
59 81

  
60 82
  /**
61 83
   * Test if we're stopped from posting a bad url on default validation.
84
   *
85
   * @codingStandardsIgnoreStart
62 86
   */
63
  function test_link_validate_bad_url_validate_default() {
64
    $this->web_user = $this->drupalCreateUser(array('administer content types',
65
                                             'administer nodes',
66
                                             'administer filters',
67
                                             'access content',
68
                                             'create page content',
69
                                             'access administration pages'));
87
  public function test_link_validate_bad_url_validate_default() {
88
    // @codingStandardsIgnoreEnd
89
    $this->web_user = $this->drupalCreateUser(array(
90
      'administer content types',
91
      'administer fields',
92
      'administer nodes',
93
      'administer filters',
94
      'access content',
95
      'create page content',
96
      'access administration pages',
97
    ));
70 98
    $this->drupalLogin($this->web_user);
71 99

  
72
    // create field
100
    // Create field.
73 101
    $name = strtolower($this->randomName());
74 102
    $edit = array(
75 103
      'fields[_add_new_field][label]' => $name,
......
86 114
    node_types_rebuild();
87 115
    menu_rebuild();
88 116

  
89
    // create page form
117
    // Create page form.
90 118
    $this->drupalGet('node/add/page');
91 119
    $field_name = 'field_' . $name;
92 120
    $this->assertField('edit-field-' . $name . '-und-0-title', 'Title found');
93 121
    $this->assertField('edit-field-' . $name . '-und-0-url', 'URL found');
94 122

  
95

  
96 123
    $edit = array(
97 124
      'title' => 'Simple Title',
98 125
      $field_name . '[und][0][url]' => 'edik:naw',
99 126
    );
100 127

  
101 128
    $this->drupalPost(NULL, $edit, t('Save'));
102
    $this->assertText(t('The value @value provided for @field is not a valid URL.', array('@value' => 'edik:naw', '@field' => $name)));
129
    $this->assertText(t('The value @value provided for @field is not a valid URL.', array(
130
      '@value' => 'edik:naw',
131
      '@field' => $name,
132
    )));
103 133
  }
104 134

  
105 135
  /**
106 136
   * Test if we're stopped from posting a bad url with validation on.
137
   *
138
   * @codingStandardsIgnoreStart
107 139
   */
108
  function test_link_validate_bad_url_validate_on() {
109
    $this->web_user = $this->drupalCreateUser(array('administer content types',
110
                                             'administer nodes',
111
                                             'administer filters',
112
                                             'access content',
113
                                             'create page content',
114
                                             'access administration pages'));
140
  public function test_link_validate_bad_url_validate_on() {
141
    // @codingStandardsIgnoreEnd
142
    $this->web_user = $this->drupalCreateUser(array(
143
      'administer content types',
144
      'administer fields',
145
      'administer nodes',
146
      'administer filters',
147
      'access content',
148
      'create page content',
149
      'access administration pages',
150
    ));
115 151
    $this->drupalLogin($this->web_user);
116 152

  
117
    // create field
153
    // Create field.
118 154
    $name = strtolower($this->randomName());
119 155
    $edit = array(
120 156
      'fields[_add_new_field][label]' => $name,
......
131 167
    node_types_rebuild();
132 168
    menu_rebuild();
133 169

  
134
    // create page form
170
    // Create page form.
135 171
    $this->drupalGet('node/add/page');
136 172
    $field_name = 'field_' . $name;
137 173
    $this->assertField('edit-field-' . $name . '-und-0-title', 'Title found');
138 174
    $this->assertField('edit-field-' . $name . '-und-0-url', 'URL found');
139 175

  
140

  
141 176
    $edit = array(
142 177
      'title' => 'Simple Title',
143 178
      $field_name . '[und][0][url]' => 'edik:naw',
144 179
    );
145 180

  
146 181
    $this->drupalPost(NULL, $edit, t('Save'));
147
    $this->assertText(t('The value @value provided for @field is not a valid URL.', array('@field' => $name, '@value' => 'edik:naw')));
182
    $this->assertText(t('The value @value provided for @field is not a valid URL.', array(
183
      '@field' => $name,
184
      '@value' => 'edik:naw',
185
    )));
148 186

  
149 187
  }
150 188

  
151 189
  /**
152 190
   * Test if we can post a bad url if the validation is expressly turned off.
191
   *
192
   * @codingStandardsIgnoreStart
153 193
   */
154
  function test_link_validate_bad_url_validate_off() {
155
    $this->web_user = $this->drupalCreateUser(array('administer content types',
156
                                             'administer nodes',
157
                                             'administer filters',
158
                                             'access content',
159
                                             'create page content',
160
                                             'access administration pages'));
194
  public function test_link_validate_bad_url_validate_off() {
195
    // @codingStandardsIgnoreEnd
196
    $this->web_user = $this->drupalCreateUser(array(
197
      'administer content types',
198
      'administer fields',
199
      'administer nodes',
200
      'administer filters',
201
      'access content',
202
      'create page content',
203
      'access administration pages',
204
    ));
161 205
    $this->drupalLogin($this->web_user);
162 206

  
163
    // create field
207
    // Create field.
164 208
    $name = strtolower($this->randomName());
165 209
    $edit = array(
166 210
      'fields[_add_new_field][label]' => $name,
......
172 216
    $this->drupalPost(NULL, array(), t('Save field settings'));
173 217
    $this->drupalPost(NULL, array('instance[settings][validate_url]' => FALSE), t('Save settings'));
174 218

  
219
    // @codingStandardsIgnoreLine
175 220
    /*$instance_details = db_query("SELECT * FROM {field_config_instance} WHERE field_name = :field_name AND bundle = 'page'", array(':field_name' => 'field_'. $name))->fetchObject();
176 221
    $this->fail('<pre>'. print_r($instance_details, TRUE) .'</pre>');
177 222
    $this->fail('<pre>'. print_r(unserialize($instance_details->data), TRUE) .'</pre>');*/
......
181 226
    node_types_rebuild();
182 227
    menu_rebuild();
183 228

  
184
    // create page form
229
    // Create page form.
185 230
    $this->drupalGet('node/add/page');
186 231
    $field_name = 'field_' . $name;
187 232
    $this->assertField('edit-field-' . $name . '-und-0-title', 'Title found');
188 233
    $this->assertField('edit-field-' . $name . '-und-0-url', 'URL found');
189 234

  
190

  
191 235
    $edit = array(
192 236
      'title' => 'Simple Title',
193 237
      $field_name . '[und][0][url]' => 'edik:naw',
194 238
    );
195 239

  
196 240
    $this->drupalPost(NULL, $edit, t('Save'));
197
    $this->assertNoText(t('The value %value provided for %field is not a valid URL.', array('%field' => $name, '%value' => 'edik:naw')));
241
    $this->assertNoText(t('The value %value provided for %field is not a valid URL.', array(
242
      '%field' => $name,
243
      '%value' => 'edik:naw',
244
    )));
198 245
  }
199 246

  
200 247
  /**
201
   * Test if a bad url can sneak through un-filtered if we play with the validation...
248
   * Validate switching between validation status.
249
   *
250
   * Test if a bad url can sneak through un-filtered if we play with the
251
   * validation...
252
   *
253
   * @codingStandardsIgnoreStart
202 254
   */
203
  function x_test_link_validate_switching_between_validation_status() {
255
  public function x_test_link_validate_switching_between_validation_status() {
256
    // @codingStandardsIgnoreEnd
204 257
    $this->acquireContentTypes(1);
205
    $this->web_user = $this->drupalCreateUser(array('administer content types',
206
                                             'administer nodes',
207
                                             'access administration pages',
208
                                             'access content',
209
                                             'create ' . $this->content_types[0]->type . ' content',
210
                                             'edit any ' . $this->content_types[0]->type . ' content'));
258
    $this->web_user = $this->drupalCreateUser(array(
259
      'administer content types',
260
      'administer fields',
261
      'administer nodes',
262
      'access administration pages',
263
      'access content',
264
      'create ' . $this->content_types[0]->type . ' content',
265
      'edit any ' . $this->content_types[0]->type . ' content',
266
    ));
211 267
    $this->drupalLogin($this->web_user);
212
    variable_set('node_options_' . $this->content_types[0]->name, array('status', 'promote'));
268
    variable_set('node_options_' . $this->content_types[0]->name, array(
269
      'status',
270
      'promote',
271
    ));
213 272
    $field_settings = array(
214 273
      'type' => 'link',
215 274
      'widget_type' => 'link',
216 275
      'type_name' => $this->content_types[0]->name,
217
      'attributes' => array(), // <-- This is needed or we have an error
276
      // <-- This is needed or we have an error.
277
      'attributes' => array(),
218 278
      'validate_url' => 0,
219 279
    );
220 280

  
221 281
    $field = $this->createField($field_settings, 0);
222
    //$this->fail('<pre>'. print_r($field, TRUE) .'</pre>');
223
    $field_db_info = content_database_info($field);
224 282

  
225 283
    $this->acquireNodes(2);
226 284

  
227
    $node = node_load($this->nodes[0]->nid);
228

  
229 285
    $this->drupalGet('node/' . $this->nodes[0]->nid);
230 286

  
231 287
    $edit = array();
......
235 291
    $edit[$field['field_name'] . '[0][title]'] = $title;
236 292

  
237 293
    $this->drupalPost('node/' . $this->nodes[0]->nid . '/edit', $edit, t('Save'));
238
    //$this->pass($this->content);
239
    $this->assertNoText(t('The value %value provided for %field is not a valid URL.', array('%field' => $name, '%value' => trim($url))));
294
    // $this->pass($this->content);.
295
    // @codingStandardsIgnoreLine
296
    $this->assertNoText(t('The value %value provided for %field is not a valid URL.', array(
297
      '%field' => $name,
298
      '%value' => trim($url),
299
    )));
240 300

  
241 301
    // Make sure we get a new version!
242 302
    $node = node_load($this->nodes[0]->nid, NULL, TRUE);
......
248 308
    // Turn the array validation back _on_.
249 309
    $edit = array('validate_url' => TRUE);
250 310
    $node_type_link = str_replace('_', '-', $node->type);
251
    //$this->drupalGet('admin/content/node-type/'. $node_type_link .'/fields'); ///'. $field['field_name']);
252
    //$this->fail($this->content);
311
    // @codingStandardsIgnoreLine
312
    // $this->drupalGet('admin/content/node-type/'. $node_type_link .'/fields'); ///'. $field['field_name']);
313
    // $this->fail($this->content);.
253 314
    $this->drupalPost('admin/content/node-type/' . $node_type_link . '/fields/' . $field['field_name'], $edit, t('Save field settings'));
254 315

  
255 316
    $this->drupalGet('node/' . $node->nid);
......
257 318
    // url() function.  But we should have a test that makes sure it continues
258 319
    // to work.
259 320
    $this->assertNoRaw($url, 'Make sure Javascript does not display.');
260
    //$this->fail($this->content);
261

  
321
    // $this->fail($this->content);.
262 322
  }
263 323

  
264
  // Validate that '<front>' is a valid url.
265
  function test_link_front_url() {
324
  /**
325
   * Validate that '<front>' is a valid url.
326
   *
327
   * @codingStandardsIgnoreStart
328
   */
329
  public function test_link_front_url() {
330
    // @codingStandardsIgnoreEnd
266 331
    $this->link_test_validate_url('<front>');
267 332
  }
268 333

  
269
  // Validate that an internal url would be accepted.
270
  function test_link_internal_url() {
334
  /**
335
   * Validate that an internal url would be accepted.
336
   *
337
   * @codingStandardsIgnoreStart
338
   */
339
  public function test_link_internal_url() {
340
    // @codingStandardsIgnoreEnd
271 341
    // Create the content first.
272 342
    $node = $this->drupalCreateNode();
273 343

  
......
277 347
    $this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.');
278 348
  }
279 349

  
280
  // Validate a simple mailto.
281
  function test_link_mailto() {
350
  /**
351
   * Validate a simple mailto.
352
   *
353
   * @codingStandardsIgnoreStart
354
   */
355
  public function test_link_mailto() {
356
    // @codingStandardsIgnoreEnd
282 357
    $this->link_test_validate_url('mailto:jcfiala@gmail.com');
283 358
  }
284 359

  
285
  function test_link_external_https() {
360
  /**
361
   * Check link external https.
362
   *
363
   * @codingStandardsIgnoreStart
364
   */
365
  public function test_link_external_https() {
366
    // @codingStandardsIgnoreEnd
286 367
    $this->link_test_validate_url('https://www.example.com/');
287 368
  }
288 369

  
289
  function test_link_ftp() {
370
  /**
371
   * Check link FTP.
372
   *
373
   * @codingStandardsIgnoreStart
374
   */
375
  public function test_link_ftp() {
376
    // @codingStandardsIgnoreEnd
290 377
    $this->link_test_validate_url('ftp://www.example.com/');
291 378
  }
379

  
292 380
}
293 381

  
382
/**
383
 * Validate Test News.
384
 */
294 385
class LinkValidateTestNews extends LinkValidateTestCase {
295 386

  
387
  /**
388
   * Get Info.
389
   */
296 390
  public static function getInfo() {
297 391
    return array(
298 392
      'name' => 'Link News Validation Tests',
......
301 395
    );
302 396
  }
303 397

  
304
  // Validate a news link to a message group
305
  function test_link_news() {
398
  /**
399
   * Validate a news link to a message group.
400
   *
401
   * @codingStandardsIgnoreStart
402
   */
403
  public function test_link_news() {
404
    // @codingStandardsIgnoreEnd
306 405
    $this->link_test_validate_url('news:comp.infosystems.www.misc');
307 406
  }
308 407

  
309
  // Validate a news link to a message id.  Said ID copied off of google groups.
310
  function test_link_news_message() {
408
  /**
409
   * Validate a news link to a message id.  Said ID copied off of google groups.
410
   *
411
   * @codingStandardsIgnoreStart
412
   */
413
  public function test_link_news_message() {
414
    // @codingStandardsIgnoreEnd
311 415
    $this->link_test_validate_url('news:hj0db8$vrm$1@news.eternal-september.org');
312 416
  }
417

  
313 418
}
314 419

  
420
/**
421
 * Validate Specific URL.
422
 */
315 423
class LinkValidateSpecificURL extends LinkValidateTestCase {
424

  
425
  /**
426
   * Get Info.
427
   */
316 428
  public static function getInfo() {
317 429
    return array(
318 430
      'name' => 'Link Specific URL Validation Tests',
......
321 433
    );
322 434
  }
323 435

  
324
  // Lets throw in a lot of umlouts for testing!
325
  function test_umlout_url() {
436
  /**
437
   * Lets throw in a lot of umlouts for testing!
438
   *
439
   * @codingStandardsIgnoreStart
440
   */
441
  public function test_umlout_url() {
442
    // @codingStandardsIgnoreEnd
326 443
    $this->link_test_validate_url('http://üÜü.exämple.com/nöde');
327 444
  }
328 445

  
329
  function test_umlout_mailto() {
446
  /**
447
   * Check umlout mailto.
448
   *
449
   * @codingStandardsIgnoreStart
450
   */
451
  public function test_umlout_mailto() {
452
    // @codingStandardsIgnoreEnd
330 453
    $this->link_test_validate_url('mailto:Üser@exÅmple.com');
331 454
  }
332 455

  
333
  function test_german_b_url() {
456
  /**
457
   * Check german b in url.
458
   *
459
   * @codingStandardsIgnoreStart
460
   */
461
  public function test_german_b_url() {
462
    // @codingStandardsIgnoreEnd
334 463
    $this->link_test_validate_url('http://www.test.com/ßstuff');
335 464
  }
336 465

  
337
  function test_special_n_url() {
466
  /**
467
   * Check Special in url.
468
   *
469
   * @codingStandardsIgnoreStart
470
   */
471
  public function test_special_n_url() {
472
    // @codingStandardsIgnoreEnd
338 473
    $this->link_test_validate_url('http://www.testÑñ.com/');
339 474
  }
340 475

  
341
  function test_curly_brackets_in_query() {
476
  /**
477
   * Curly Brackets in query.
478
   *
479
   * @codingStandardsIgnoreStart
480
   */
481
  public function test_curly_brackets_in_query() {
482
    // @codingStandardsIgnoreEnd
342 483
    $this->link_test_validate_url('http://www.healthyteennetwork.org/index.asp?Type=B_PR&SEC={2AE1D600-4FC6-4B4D-8822-F1D5F072ED7B}&DE={235FD1E7-208D-4363-9854-4E6775EB8A4C}');
343 484
  }
344 485

  
......
346 487
   * Here, we're testing that a very long url is stored properly in the db.
347 488
   *
348 489
   * Basically, trying to test http://drupal.org/node/376818
490
   *
491
   * @codingStandardsIgnoreStart
349 492
   */
350
  function testLinkURLFieldIsBig() {
493
  public function testLinkURLFieldIsBig() {
494
    // @codingStandardsIgnoreEnd
351 495
    $long_url = 'http://th.wikipedia.org/wiki/%E0%B9%82%E0%B8%A3%E0%B8%87%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%80%E0%B8%9A%E0%B8%8D%E0%B8%88%E0%B8%A1%E0%B8%A3%E0%B8%B2%E0%B8%8A%E0%B8%B9%E0%B8%97%E0%B8%B4%E0%B8%A8_%E0%B8%99%E0%B8%84%E0%B8%A3%E0%B8%A8%E0%B8%A3%E0%B8%B5%E0%B8%98%E0%B8%A3%E0%B8%A3%E0%B8%A1%E0%B8%A3%E0%B8%B2%E0%B8%8A';
352 496
    $this->link_test_validate_url($long_url);
353 497
  }
......
355 499
}
356 500

  
357 501
/**
358
 * A series of tests of links, only going against the link_validate_url function in link.module.
502
 * Validate Url Light.
503
 *
504
 * A series of tests of links, only going against the link_validate_url function
505
 * in link.module.
359 506
 *
360 507
 * Validation is guided by the rules in http://tools.ietf.org/html/rfc1738 !
361 508
 */
362 509
class LinkValidateUrlLight extends DrupalWebTestCase {
363 510

  
511
  /**
512
   * Get Info.
513
   */
364 514
  public static function getInfo() {
365 515
    return array(
366 516
      'name' => 'Link Light Validation Tests',
......
368 518
      'group' => 'Link',
369 519
    );
370 520
  }
371
  
372
  function setUp() {
521

  
522
  /**
523
   * Setup.
524
   */
525
  public function setUp() {
373 526
    parent::setUp('link');
374 527
  }
375 528

  
376 529
  /**
377
   * Translates the LINK type constants to english for display and debugging of tests
530
   * Name Link Type.
531
   *
532
   * Translates the LINK type constants to english for display and debugging of
533
   * tests.
534
   *
535
   * @codingStandardsIgnoreStart
378 536
   */
379
  function name_Link_Type($type) {
537
  public function name_Link_Type($type) {
538
    // @codingStandardsIgnoreEnd
380 539
    switch ($type) {
381 540
      case LINK_FRONT:
382 541
        return "Front";
542

  
383 543
      case LINK_EMAIL:
384 544
        return "Email";
545

  
385 546
      case LINK_NEWS:
386 547
        return "Newsgroup";
548

  
387 549
      case LINK_INTERNAL:
388 550
        return "Internal Link";
551

  
389 552
      case LINK_EXTERNAL:
390 553
        return "External Link";
554

  
391 555
      case FALSE:
392 556
        return "Invalid Link";
557

  
393 558
      default:
394 559
        return "Bad Value:" . $type;
395 560
    }
396 561
  }
397 562

  
398
  // Make sure that a link labeled <front> works.
399
  function testValidateFrontLink() {
563
  /**
564
   * Make sure that a link labeled <front> works.
565
   */
566
  public function testValidateFrontLink() {
400 567
    $valid = link_validate_url('<front>');
401 568
    $this->assertEqual(LINK_FRONT, $valid, 'Make sure that front link is verified and identified');
402 569
  }
403 570

  
404
  function testValidateEmailLink() {
571
  /**
572
   * Validate Email Link.
573
   */
574
  public function testValidateEmailLink() {
405 575
    $valid = link_validate_url('mailto:bob@example.com');
406 576
    $this->assertEqual(LINK_EMAIL, $valid, "Make sure a basic mailto is verified and identified");
407 577
  }
408 578

  
409
  function testValidateEmailLinkBad() {
579
  /**
580
   * Validate Email Link Bad.
581
   */
582
  public function testValidateEmailLinkBad() {
410 583
    $valid = link_validate_url(':bob@example.com');
411 584
    $this->assertEqual(FALSE, $valid, 'Make sure just a bad address is correctly failed');
412 585
  }
413 586

  
414
  function testValidateNewsgroupLink() {
587
  /**
588
   * Validate Newsgroup Link.
589
   */
590
  public function testValidateNewsgroupLink() {
415 591
    $valid = link_validate_url('news:comp.infosystems.www.misc');
416 592
    $this->assertEqual(LINK_NEWS, $valid, 'Make sure link to newsgroup validates as news.');
417 593
  }
418 594

  
419
  function testValidateNewsArticleLink() {
595
  /**
596
   * Validate News Article Link.
597
   */
598
  public function testValidateNewsArticleLink() {
420 599
    $valid = link_validate_url('news:hj0db8$vrm$1@news.eternal-september.org');
421 600
    $this->assertEqual(LINK_NEWS, $valid, 'Make sure link to specific article validates as news.');
422 601
  }
423 602

  
424
  function testValidateBadNewsgroupLink() {
603
  /**
604
   * Validate Bad Newsgroup Link.
605
   */
606
  public function testValidateBadNewsgroupLink() {
425 607
    $valid = link_validate_url('news:comp.bad_name.misc');
426 608
    $this->assertEqual(FALSE, $valid, 'newsgroup names can\'t contain underscores, so it should come back as invalid.');
427 609
  }
428 610

  
429
  function testValidateInternalLinks() {
611
  /**
612
   * Validate Internal Links.
613
   */
614
  public function testValidateInternalLinks() {
430 615
    $tempfile = drupal_tempnam('public://files', 'test');
431 616
    $links = array(
432 617
      'rss.xml',
433 618
      file_uri_target($tempfile),
434 619
      drupal_realpath($tempfile),
435 620
    );
436
    
621

  
437 622
    foreach ($links as $link) {
438 623
      $type = link_url_type($link);
439 624
      $this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.');
......
442 627
    }
443 628
  }
444 629

  
445
  function testValidateExternalLinks() {
630
  /**
631
   * Validate External Links.
632
   */
633
  public function testValidateExternalLinks() {
446 634
    $links = array(
447 635
      'http://localhost:8080/',
448 636
      'www.example.com',
......
458 646
      'www.test-site.com',
459 647
      'http://example.com/index.php?q=node/123',
460 648
      'http://example.com/?first_name=Joe Bob&last_name=Smith',
461
      // Anchors
649
      // Anchors.
462 650
      'http://www.example.com/index.php#test',
463 651
      'http://www.example.com/index.php#this@that.',
464 652
      'http://www.example.com/index.php#',
......
466 654
      'http://www.archive.org/stream/aesopsfables00aesorich#page/n7/mode/2up',
467 655
      'http://www.example.com/blah/#this@that?',
468 656
    );
657

  
469 658
    // Test all of the protocols.
470
    $allowed_protocols = variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal'));
659
    $allowed_protocols = variable_get('filter_allowed_protocols', array(
660
      'http',
661
      'https',
662
      'ftp',
663
      'news',
664
      'nntp',
665
      'telnet',
666
      'mailto',
667
      'irc',
668
      'ssh',
669
      'sftp',
670
      'webcal',
671
    ));
672

  
471 673
    foreach ($allowed_protocols as $protocol) {
472 674
      if ($protocol !== 'news' && $protocol !== 'mailto') {
473 675
        $links[] = $protocol . '://www.example.com';
......
478 680
      $this->assertEqual(LINK_EXTERNAL, $type, 'Testing that ' . $link . ' is an external link.');
479 681
      $valid = link_validate_url($link);
480 682
      $this->assertTrue($valid, 'Test ' . $link . ' is valid external link.');
481
      // The following two lines are commented out and only used for comparisons.
482
      //$valid2 = valid_url($link, TRUE);
483
      //$this->assertEqual(TRUE, $valid2, "Using valid_url() on $link.");
683
      // The following two lines are commented out and only used for
684
      // comparisons.
685
      // $valid2 = valid_url($link, TRUE);
686
      // $this->assertEqual(TRUE, $valid2, "Using valid_url() on $link.");.
484 687
    }
485
    // Test if we can make a tld valid:
486
    variable_set('link_extra_domains', array('frog'));
487
    $valid = link_validate_url('http://www.example.frog');
488
    $this->assertEqual(LINK_EXTERNAL, $valid, "Testing that http://www.example.frog is a valid external link if we've added 'frog' to the list of valid domains.");
489 688
  }
490 689

  
491
  function testInvalidExternalLinks() {
690
  /**
691
   * Check Invalid External Links.
692
   */
693
  public function testInvalidExternalLinks() {
492 694
    $links = array(
493 695
      'http://www.ex ample.com/',
494
      'http://25.0.0/', // bad ip!
696
      // Bad ip!
697
      'http://25.0.0/',
495 698
      'http://4827.0.0.2/',
496
      '//www.example.com/',
497
      'http://www.testß.com/', // ß not allowed in domain names!
498
      'http://www.example.frog/', // Bad TLD
499
      //'http://www.-fudge.com/', // domains can't have sections starting with a dash.
699
      // ß not allowed in domain names!
700
      'http://www.testß.com/',
701
      // Bad TLD.
702
      'http://.www.foo.bar./',
703
      // Domains can't have sections starting with a dash.
704
      // 'http://www.-fudge.com/',
500 705
      'http://example.com/index.php?page=this\that',
501 706
      'example@example.com',
502 707
    );
......
505 710
      $this->assertEqual(FALSE, $valid, 'Testing that ' . $link . ' is not a valid link.');
506 711
    }
507 712
  }
713

  
508 714
}

Formats disponibles : Unified diff