Projet

Général

Profil

Révision 8e7483ab

Ajouté par Assos Assos il y a plus de 4 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/link/tests/link.validate.test
22 22
  }
23 23

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

  
27
  protected function linkTestValidateUrl($url) {
32 28
    $field_name = $this->createLinkField();
33 29

  
34 30
    $label = $this->randomName();
......
71 67

  
72 68
  /**
73 69
   * Validate basic URL.
74
   *
75
   * @codingStandardsIgnoreStart
76 70
   */
77
  public function test_link_validate_basic_url() {
78
    // @codingStandardsIgnoreEnd
79
    $this->link_test_validate_url('http://www.example.com');
71
  public function testLinkValidateBasicUrl() {
72
    $this->linkTestValidateUrl('http://www.example.com');
80 73
  }
81 74

  
82 75
  /**
83 76
   * Test if we're stopped from posting a bad url on default validation.
84
   *
85
   * @codingStandardsIgnoreStart
86 77
   */
87
  public function test_link_validate_bad_url_validate_default() {
88
    // @codingStandardsIgnoreEnd
78
  public function testLinkValidateBadUrlValidateDefault() {
89 79
    $this->web_user = $this->drupalCreateUser(array(
90 80
      'administer content types',
91 81
      'administer fields',
......
134 124

  
135 125
  /**
136 126
   * Test if we're stopped from posting a bad url with validation on.
137
   *
138
   * @codingStandardsIgnoreStart
139 127
   */
140
  public function test_link_validate_bad_url_validate_on() {
141
    // @codingStandardsIgnoreEnd
128
  public function testLinkValidateBadUrlValidateOn() {
142 129
    $this->web_user = $this->drupalCreateUser(array(
143 130
      'administer content types',
144 131
      'administer fields',
......
188 175

  
189 176
  /**
190 177
   * Test if we can post a bad url if the validation is expressly turned off.
191
   *
192
   * @codingStandardsIgnoreStart
193 178
   */
194
  public function test_link_validate_bad_url_validate_off() {
195
    // @codingStandardsIgnoreEnd
179
  public function testLinkValidateBadUrlValidateOff() {
196 180
    $this->web_user = $this->drupalCreateUser(array(
197 181
      'administer content types',
198 182
      'administer fields',
......
249 233
   *
250 234
   * Test if a bad url can sneak through un-filtered if we play with the
251 235
   * validation...
252
   *
253
   * @codingStandardsIgnoreStart
254 236
   */
255
  public function x_test_link_validate_switching_between_validation_status() {
256
    // @codingStandardsIgnoreEnd
237
  public function xTestLinkValidateSwitchingBetweenValidationStatus() {
257 238
    $this->acquireContentTypes(1);
258 239
    $this->web_user = $this->drupalCreateUser(array(
259 240
      'administer content types',
......
294 275
    // $this->pass($this->content);.
295 276
    // @codingStandardsIgnoreLine
296 277
    $this->assertNoText(t('The value %value provided for %field is not a valid URL.', array(
278
      // @codingStandardsIgnoreLine
297 279
      '%field' => $name,
298 280
      '%value' => trim($url),
299 281
    )));
......
323 305

  
324 306
  /**
325 307
   * Validate that '<front>' is a valid url.
326
   *
327
   * @codingStandardsIgnoreStart
328 308
   */
329
  public function test_link_front_url() {
330
    // @codingStandardsIgnoreEnd
331
    $this->link_test_validate_url('<front>');
309
  public function testLinkFrontUrl() {
310
    $this->linkTestValidateUrl('<front>');
332 311
  }
333 312

  
334 313
  /**
335 314
   * Validate that an internal url would be accepted.
336
   *
337
   * @codingStandardsIgnoreStart
338 315
   */
339
  public function test_link_internal_url() {
340
    // @codingStandardsIgnoreEnd
316
  public function testLinkInternalUrl() {
341 317
    // Create the content first.
342 318
    $node = $this->drupalCreateNode();
343 319

  
344 320
    $link = 'node/' . $node->nid;
345
    $this->link_test_validate_url($link);
321
    $this->linkTestValidateUrl($link);
346 322
    $type = link_url_type($link);
347 323
    $this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.');
348 324
  }
349 325

  
350 326
  /**
351 327
   * Validate a simple mailto.
352
   *
353
   * @codingStandardsIgnoreStart
354 328
   */
355
  public function test_link_mailto() {
356
    // @codingStandardsIgnoreEnd
357
    $this->link_test_validate_url('mailto:jcfiala@gmail.com');
329
  public function testLinkMailto() {
330
    $this->linkTestValidateUrl('mailto:jcfiala@gmail.com');
358 331
  }
359 332

  
360 333
  /**
361 334
   * Check link external https.
362
   *
363
   * @codingStandardsIgnoreStart
364 335
   */
365
  public function test_link_external_https() {
366
    // @codingStandardsIgnoreEnd
367
    $this->link_test_validate_url('https://www.example.com/');
336
  public function testLinkExternalHttps() {
337
    $this->linkTestValidateUrl('https://www.example.com/');
368 338
  }
369 339

  
370 340
  /**
371 341
   * Check link FTP.
372
   *
373
   * @codingStandardsIgnoreStart
374 342
   */
375
  public function test_link_ftp() {
376
    // @codingStandardsIgnoreEnd
377
    $this->link_test_validate_url('ftp://www.example.com/');
343
  public function testLinkFtp() {
344
    $this->linkTestValidateUrl('ftp://www.example.com/');
378 345
  }
379 346

  
380 347
}
......
397 364

  
398 365
  /**
399 366
   * Validate a news link to a message group.
400
   *
401
   * @codingStandardsIgnoreStart
402 367
   */
403
  public function test_link_news() {
404
    // @codingStandardsIgnoreEnd
405
    $this->link_test_validate_url('news:comp.infosystems.www.misc');
368
  public function testLinkNews() {
369
    $this->linkTestValidateUrl('news:comp.infosystems.www.misc');
406 370
  }
407 371

  
408 372
  /**
409 373
   * Validate a news link to a message id.  Said ID copied off of google groups.
410
   *
411
   * @codingStandardsIgnoreStart
412 374
   */
413
  public function test_link_news_message() {
414
    // @codingStandardsIgnoreEnd
415
    $this->link_test_validate_url('news:hj0db8$vrm$1@news.eternal-september.org');
375
  public function testLinkNewsMessage() {
376
    $this->linkTestValidateUrl('news:hj0db8$vrm$1@news.eternal-september.org');
416 377
  }
417 378

  
418 379
}
......
435 396

  
436 397
  /**
437 398
   * Lets throw in a lot of umlouts for testing!
438
   *
439
   * @codingStandardsIgnoreStart
440 399
   */
441
  public function test_umlout_url() {
442
    // @codingStandardsIgnoreEnd
443
    $this->link_test_validate_url('http://üÜü.exämple.com/nöde');
400
  public function testUmloutUrl() {
401
    $this->linkTestValidateUrl('http://üÜü.exämple.com/nöde');
444 402
  }
445 403

  
446 404
  /**
447 405
   * Check umlout mailto.
448
   *
449
   * @codingStandardsIgnoreStart
450 406
   */
451
  public function test_umlout_mailto() {
452
    // @codingStandardsIgnoreEnd
453
    $this->link_test_validate_url('mailto:Üser@exÅmple.com');
407
  public function testUmloutMailto() {
408
    $this->linkTestValidateUrl('mailto:Üser@exÅmple.com');
454 409
  }
455 410

  
456 411
  /**
457
   * Check german b in url.
458
   *
459
   * @codingStandardsIgnoreStart
412
   * Check German b in URL, aka Eszett.
460 413
   */
461
  public function test_german_b_url() {
462
    // @codingStandardsIgnoreEnd
463
    $this->link_test_validate_url('http://www.test.com/ßstuff');
414
  public function testGermanEszettUrl() {
415
    $this->linkTestValidateUrl('http://www.test.com/ßstuff');
464 416
  }
465 417

  
466 418
  /**
467
   * Check Special in url.
468
   *
469
   * @codingStandardsIgnoreStart
419
   * Check Spanish ñ in URL.
470 420
   */
471
  public function test_special_n_url() {
472
    // @codingStandardsIgnoreEnd
473
    $this->link_test_validate_url('http://www.testÑñ.com/');
421
  public function testSpecialEneUrl() {
422
    $this->linkTestValidateUrl('http://www.testÑñ.com/');
474 423
  }
475 424

  
476 425
  /**
477
   * Curly Brackets in query.
478
   *
479
   * @codingStandardsIgnoreStart
426
   * Curly brackets in query.
480 427
   */
481
  public function test_curly_brackets_in_query() {
482
    // @codingStandardsIgnoreEnd
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}');
428
  public function testCurlyBracketsInQuery() {
429
    $this->linkTestValidateUrl('http://www.healthyteennetwork.org/index.asp?Type=B_PR&SEC={2AE1D600-4FC6-4B4D-8822-F1D5F072ED7B}&DE={235FD1E7-208D-4363-9854-4E6775EB8A4C}');
484 430
  }
485 431

  
486 432
  /**
487 433
   * Here, we're testing that a very long url is stored properly in the db.
488 434
   *
489 435
   * Basically, trying to test http://drupal.org/node/376818
490
   *
491
   * @codingStandardsIgnoreStart
492 436
   */
493
  public function testLinkURLFieldIsBig() {
494
    // @codingStandardsIgnoreEnd
437
  public function testLinkUrlFieldIsBig() {
495 438
    $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';
496
    $this->link_test_validate_url($long_url);
439
    $this->linkTestValidateUrl($long_url);
497 440
  }
498 441

  
499 442
}
......
520 463
  }
521 464

  
522 465
  /**
523
   * Setup.
466
   * {@inheritdoc}
524 467
   */
525
  public function setUp() {
526
    parent::setUp('link');
468
  public function setUp(array $modules = array()) {
469
    $modules[] = 'link';
470
    parent::setUp($modules);
527 471
  }
528 472

  
529 473
  /**
......
543 487
      case LINK_EMAIL:
544 488
        return "Email";
545 489

  
490
      case LINK_TEL:
491
        return "Telephone";
492

  
546 493
      case LINK_NEWS:
547 494
        return "Newsgroup";
548 495

  
......
584 531
    $this->assertEqual(FALSE, $valid, 'Make sure just a bad address is correctly failed');
585 532
  }
586 533

  
534
  /**
535
   * Confirm that valid tel: links work as expected.
536
   */
537
  public function testValidateTelLinks() {
538
    $links = array(
539
      'tel:01',
540
      'tel:123456789012345',
541
      'tel:+123456789012345',
542
    );
543
    foreach ($links as $link) {
544
      $type = link_url_type($link);
545
      $this->assertEqual(LINK_TEL, $type, 'Test ' . $link . ' is a tel link.');
546
      $valid = link_validate_url($link);
547
      $this->assertTrue($valid, 'Test ' . $link . ' is valid tel link.');
548
    }
549
  }
550

  
551
  /**
552
   * Confirm that invalid tel: links work as expected.
553
   */
554
  public function testValidateTelLinksBad() {
555
    $links = array(
556
      'tel:0',
557
      'tel:1234567890123456',
558
      'tel:+1',
559
      'tel:+0123456789',
560
      'tel:+1234567890123456',
561
      ':12345678',
562
    );
563
    foreach ($links as $link) {
564
      $type = link_url_type($link);
565
      $this->assertFalse($type, 'Test ' . $link . ' is not a tel link.');
566
      $valid = link_validate_url($link);
567
      $this->assertFalse($valid, 'Test ' . $link . ' is not a valid tel link.');
568
    }
569
  }
570

  
587 571
  /**
588 572
   * Validate Newsgroup Link.
589 573
   */
......
615 599
    $tempfile = drupal_tempnam('public://files', 'test');
616 600
    $links = array(
617 601
      'rss.xml',
602
      'foo#bar',
618 603
      file_uri_target($tempfile),
619 604
      drupal_realpath($tempfile),
620 605
    );

Formats disponibles : Unified diff