1 common.test CommonValidUrlUnitTestCase::testValidAbsolute()

Test valid absolute URLs.

File

core/modules/simpletest/tests/common.test, line 2369
Tests for common.inc functionality.

Class

CommonValidUrlUnitTestCase
Tests URL validation by valid_url().

Code

function testValidAbsolute() {
  $url_schemes = array('http', 'https', 'ftp');
  $valid_absolute_urls = array(
    // cspell:disable
    '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',
    // cspell:enable
  );

  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, format_string('@url is a valid url.', array('@url' => $test_url)));
    }
  }
}