You are here

function LinkValidateUrlLight::testValidateExternalLinks in Link 6.2

File

tests/link.validate.test, line 450
Tests that exercise the validation functions in the link module.

Class

LinkValidateUrlLight
A series of tests of links, only going against the link_validate_url function in link.module.

Code

function testValidateExternalLinks() {
  $links = array(
    'http://localhost:8080/',
    'www.example.com',
    'www.example.com/',
    'http://username:p%40ssw0rd!@www.example.com/',
    'http://@www.example.com/',
    'http://username:@www.example.com/',
    'http://username:password@www.example.com:8080/',
    'http://127.0.0.1:80/',
    'http://127.173.24.255:4723/',
    '127.173.24.255:4723/',
    'http://255.255.255.255:4823/',
    'www.test-site.com',
    'http://example.com/index.php?q=node/123',
    'http://example.com/index.php?page=this\\that',
    'http://example.com/?first_name=Joe Bob&last_name=Smith',
    // Anchors
    'http://www.example.com/index.php#test',
    'http://www.example.com/index.php#this@that.',
    'http://www.example.com/index.php#',
    'http://www.cnn.com/video/#/video/politics/2008/12/09/intv.madeleine.albright.cnn',
    'http://www.archive.org/stream/aesopsfables00aesorich#page/n7/mode/2up',
    'http://www.example.com/blah/#this@that?',
  );

  // Test all of the protocols.
  $allowed_protocols = variable_get('filter_allowed_protocols', array(
    'http',
    'https',
    'ftp',
    'news',
    'nntp',
    'telnet',
    'mailto',
    'irc',
    'ssh',
    'sftp',
    'webcal',
  ));
  foreach ($allowed_protocols as $protocol) {
    if ($protocol !== 'news' && $protocol !== 'mailto') {
      $links[] = $protocol . '://www.example.com';
    }
  }
  foreach ($links as $link) {
    $valid = link_validate_url($link);
    $this
      ->assertEqual(LINK_EXTERNAL, $valid, 'Testing that ' . $link . ' is a valid external link.');
  }
}