function ValidUrlTestCase::testValidAbsolute

Test valid absolute URLs.

File

modules/simpletest/tests/common.test, line 2509

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.