You are here

function ValidUrlTestCase::testValidAbsolute in SimpleTest 7

Test valid absolute urls.

File

tests/common.test, line 1309
Tests for common.inc functionality.

Class

ValidUrlTestCase
Test for valid_url().

Code

function testValidAbsolute() {
  $url_schemes = array(
    'http',
    'https',
    'ftp',
  );
  $valid_absolute_urls = array(
    'example.com',
    'www.example.com',
    'ex-ample.com',
    '3xampl3.com',
    'example.com/paren(the)sis',
    'example.com/index.html#pagetop',
    'example.com:8080',
    'subdomain.example.com',
    'example.com/index.php?q=node',
    'example.com/index.php?q=node&param=false',
    'user@www.example.com',
    'user:pass@www.example.com:8080/login.php?do=login&style=%23#pagetop',
    '127.0.0.1',
    'example.org?',
    'john%20doe:secret:foo@example.org/',
    'example.org/~,$\'*;',
    'caf%C3%A9.example.org',
    '[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html',
  );
  foreach ($url_schemes as $scheme) {
    foreach ($valid_absolute_urls as $url) {
      $test_url = $scheme . '://' . $url;
      $valid_url = valid_url($test_url, TRUE);
      $this
        ->assertTrue($valid_url, t('@url is a valid url.', array(
        '@url' => $test_url,
      )));
    }
  }
}