1 locale.test LocaleUrlRewritingTest::testDomainNameNegotiationPort()

Check URL rewriting when using a domain name and a non-standard port.

File

core/modules/locale/tests/locale.test, line 2430
Tests for locale.module.

Class

LocaleUrlRewritingTest
Test that URL rewriting works as expected.

Code

function testDomainNameNegotiationPort() {
  $edit = array(
    // Enable domain configuration.
    'language_negotiation_url_part' => LANGUAGE_NEGOTIATION_URL_DOMAIN,
    'prefix[fr]' => '',
    'domain[fr]' => 'example.fr',
  );
  $this->backdropPost('admin/config/regional/language/detection/url', $edit, t('Save configuration'));

  // Reset static caching.
  backdrop_static_reset('language_list');
  backdrop_static_reset('language_url_outbound_alter');
  backdrop_static_reset('language_url_rewrite_url');

  // In case index.php is part of the URLs, we need to adapt the asserted
  // URLs as well.
  $index_php = strpos(url('', array('absolute' => TRUE)), 'index.php') !== FALSE;

  // Remember current HTTP_HOST.
  $http_host = $_SERVER['HTTP_HOST'];

  // Fake a different port.
  $_SERVER['HTTP_HOST'] .= ':88';

  // Create an absolute French link.
  $languages = language_list();
  $language = $languages['fr'];
  $url = url('', array(
    'absolute' => TRUE,
    'language' => $language
  ));

  $expected = 'http://example.fr:88/';
  $expected .= $index_php ? 'index.php/' : '';

  $this->assertEqual($url, $expected, 'The right port is used.');

  // If we set the port explicitly in url(), it should not be overriden.
  $url = url('', array(
    'absolute' => TRUE,
    'language' => $language,
    'base_url' => $GLOBALS['base_url'] . ':90',
  ));

  $expected = 'http://example.fr:90/';
  $expected .= $index_php ? 'index.php/' : '';

  $this->assertEqual($url, $expected, 'A given port is not overriden.');

  // Restore HTTP_HOST.
  $_SERVER['HTTP_HOST'] = $http_host;
}