You are here

function DomainFilterTest::testDomainURLFilters in Domain Access 7.3

File

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

Class

DomainFilterTest

Code

function testDomainURLFilters() {

  // Create domains.
  $domains = $this
    ->domainCreateDomains();

  // Remove nodes from 'all affiliates'.
  db_delete('domain_access')
    ->condition('realm', 'domain_site')
    ->execute();

  // Fetch the existing node ids.
  $node_ids = array_keys(db_query("SELECT nid FROM {node}")
    ->FetchAllAssoc('nid'));

  // On node load, these should all be assigned to domain_id = 1.
  $nodes = node_load_multiple($node_ids);

  // Cycle through the domains and test a new node for each one, since
  // the url rewrites are cached.
  foreach (domain_domains(TRUE) as $key => $domain) {
    $node = $nodes[$key];
    $path = "node/{$node->nid}";
    $this
      ->assertTrue($path != "node/", t('Fetched a node path.'));
    domain_set_domain($key);
    $_domain = domain_get_domain();

    // Set the $base_url value to the current domain.
    $this
      ->domainSetBaseUrl($domain);
    $text = $this
      ->randomString(255);
    $filtertext = "---[canonical-url:{$path}]---";
    $text .= $filtertext;
    $text .= $this
      ->randomString(255);
    $this
      ->assertTrue(substr_count($text, $filtertext) > 0, t('Sample text contains domain url: @url.', array(
      '@url' => $filtertext,
    )));
    $newtext = domain_url_filter_process($text, NULL, NULL, NULL, NULL, NULL);
    $this
      ->assertTrue(substr_count($newtext, $filtertext) == 0, t('Sample text does not contain domain url: @url.', array(
      '@url' => $filtertext,
    )));

    // These should be returning absolute URLs for all domains but the first.
    $url = url($path);
    $this
      ->assertTrue(substr_count($newtext, $url) > 0, t('Sample text contains proper url: @url.', array(
      '@url' => $url,
    )));
  }
}