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 105
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'));

  // Rebuild the container so that the new language gets picked up by services
  // that hold the list of languages.
  $this
    ->rebuildContainer();

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

  // Reset static caching.
  drupal_static_reset('language_list');

  // 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;
  $request = $this
    ->prepareRequestForGenerator(TRUE, array(
    'SERVER_PORT' => '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') . rtrim(base_path(), '/') . '/';
  $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' => $request
      ->getBaseUrl() . ':90',
  ));
  $expected = $index_php ? 'http://example.fr:90/index.php' : 'http://example.fr:90' . rtrim(base_path(), '/') . '/';
  $this
    ->assertEqual($url, $expected, 'A given port is not overriden.');
}