1 locale.test LocaleUILanguageNegotiationTest::testLanguageDomain()

Tests url() when separate domains are used for multiple languages.

File

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

Class

LocaleUILanguageNegotiationTest
Test UI language negotiation

Code

function testLanguageDomain() {
  // Add the Italian language.
  $langcode = 'it';
  $language = (object) array(
    'langcode' => $langcode,
  );
  language_save($language);
  $languages = language_list();

  // Enable browser and URL language detection.
  $edit = array(
    'language[locale-url][enabled]' => TRUE,
    'language[locale-url][weight]' => -10,
  );
  $this->backdropPost('admin/config/regional/language/detection', $edit, t('Save settings'));

  // Change the domain for the Italian language.
  $edit = array(
    'language_negotiation_url_part' => LANGUAGE_NEGOTIATION_URL_DOMAIN,
    'domain[it]' => 'it.example.com',
  );
  $this->backdropPost('admin/config/regional/language/detection/url', $edit, t('Save configuration'));

  // Build the link we're going to test based on the clean URL setting.
  $link = (config_get('system.core', 'clean_url')) ? 'it.example.com/admin' : 'it.example.com/?q=admin';

  global $is_https;
  // Test URL in another language: http://it.example.com/?q=admin.
  // Base path gives problems on the testbot, so $correct_link is hard-coded.
  // @see UrlAlterFunctionalTest::assertUrlOutboundAlter (path.test).
  $italian_url = url('admin', array('language' => $languages['it']));
  $url_scheme = ($is_https) ? 'https://' : 'http://';
  $correct_link = $url_scheme . $link;
  $this->assertTrue($italian_url == $correct_link, format_string('The url() function returns the right url (@url) in accordance with the chosen language', array('@url' => $italian_url . " == " . $correct_link)));

  // Test HTTPS via options.
  $GLOBALS['settings']['https'] = TRUE;
  $italian_url = url('admin', array('https' => TRUE, 'language' => $languages['it']));
  $correct_link = 'https://' . $link;
  $this->assertTrue($italian_url == $correct_link, format_string('The url() function returns the right https url (via options) (@url) in accordance with the chosen language', array('@url' => $italian_url . " == " . $correct_link)));
  unset($GLOBALS['settings']['https']);

  // Test HTTPS via current URL scheme.
  $temp_https = $is_https;
  $is_https = TRUE;
  $italian_url = url('admin', array('language' => $languages['it']));
  $correct_link = 'https://' . $link;
  $this->assertTrue($italian_url == $correct_link, format_string('The url() function returns the right url (via current url scheme) (@url) in accordance with the chosen language', array('@url' => $italian_url . " == " . $correct_link)));
  $is_https = $temp_https;
}