Tests url() when separate domains are used for multiple languages.
function testLanguageDomain() {
// Add the Italian language.
$langcode = 'it';
$language = new Language(array(
'langcode' => $langcode,
));
language_save($language);
$languages = language_list();
// Enable browser and URL language detection.
$edit = array(
'language_interface[enabled][language-url]' => TRUE,
'language_interface[weight][language-url]' => -10,
);
$this
->drupalPost('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
->drupalPost('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
// Build the link we're going to test.
$link = 'it.example.com/admin';
global $is_https;
// Test URL in another language: http://it.example.com/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'],
'script' => '',
));
$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,
)));
// Test HTTPS via options.
variable_set('https', TRUE);
$italian_url = url('admin', array(
'https' => TRUE,
'language' => $languages['it'],
'script' => '',
));
$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,
)));
variable_set('https', FALSE);
// Test HTTPS via current URL scheme.
$temp_https = $is_https;
$is_https = TRUE;
$italian_url = url('admin', array(
'language' => $languages['it'],
'script' => '',
));
$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,
)));
$is_https = $temp_https;
}