function LanguageUrlRewritingTest::testDomainNameNegotiationPort

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

File

drupal/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php, line 101
Definition of Drupal\language\Tests\LanguageUrlRewritingTest.

Class

LanguageUrlRewritingTest
Test that URL rewriting works as expected.

Namespace

Drupal\language\Tests

Code

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

  // Enable domain configuration.
  config('language.negotiation')
    ->set('url.source', LANGUAGE_NEGOTIATION_URL_DOMAIN)
    ->save();

  // Reset static caching.
  drupal_static_reset('language_list');
  drupal_static_reset('language_url_outbound_alter');
  drupal_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.
  $language = language_load('fr');
  $url = url('', array(
    'absolute' => TRUE,
    'language' => $language,
  ));
  $expected = $index_php ? 'http://example.fr:88/index.php/' : 'http://example.fr:88/';
  $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 = $index_php ? 'http://example.fr:90/index.php/' : 'http://example.fr:90/';
  $this
    ->assertEqual($url, $expected, 'A given port is not overriden.');

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