You are here

function DomainCreateTest::testDomainValidate in Domain Access 7.3

File

tests/domain.test, line 232
Simpletest for Domain Access.

Class

DomainCreateTest

Code

function testDomainValidate() {
  $tests = array(
    'localhost' => array(),
    // localhost is allowed.
    'localhost:80' => array(),
    // localhost may specify a port.
    'nodotsinstring' => array(
      t('At least one dot (.) is required, except for <em>localhost</em>.'),
    ),
    'example.com:2000:1' => array(
      t('Only one colon (:) is allowed.'),
    ),
    'example.com:foo' => array(
      t('The port protocol must be an integer.'),
    ),
    '.example.com' => array(
      t('The domain must not begin with a dot (.)'),
    ),
    'example.com.' => array(
      t('The domain must not end with a dot (.)'),
    ),
    '$.example.com' => array(
      t('Only alphanumeric characters, dashes, and a colon are allowed.'),
    ),
    'EXAMPLE.com' => array(
      t('Only lower-case characters are allowed.'),
    ),
  );
  foreach ($tests as $subdomain => $error) {
    $return = domain_validate($subdomain);

    // Special handling for localhost. This test needs refactoring.
    if (substr_count($subdomain, 'localhost') > 0 && empty($return)) {
      $return = TRUE;
    }
    $this
      ->assertTrue(!empty($return), t('!message', array(
      '!message' => !empty($error) ? $error[0] : t('%subdomain is an allowed domain string.', array(
        '%subdomain' => $subdomain,
      )),
    )));
  }

  // Test for the non-alphanumeric character override.
  global $conf;
  $conf['domain_allow_non_ascii'] = TRUE;
  $return = domain_validate('$%#!.com');
  $this
    ->assertTrue(empty($return), t('ASCII character override value allowed.'));

  // Test for the www. prefix when 'WWW prefix handling' is disabled.
  $conf['domain_www'] = 0;
  $return = domain_validate('www.example.com');
  $this
    ->assertTrue(empty($return), t('<em>WWW prefix handling</em> disabled: Domains can be registered with the www. prefix.'));

  // Test for the www. prefix when 'WWW prefix handling' is enabled.
  $conf['domain_www'] = 1;
  $return = domain_validate('www.example.com');
  $this
    ->assertTrue(!empty($return), t('<em>WWW prefix handling</em> enabled: Domains must be registered without the www. prefix.'));
}