Issue #1250800 by attiks, Jelle_S, dawehner, xjm, Gábor Hojtsy: Fixed Language domain should work regardless of ports or protocols.

merge-requests/26/head
webchick 2012-03-26 22:37:30 -07:00
parent 0932803a2c
commit 796df03557
2 changed files with 70 additions and 1 deletions

View File

@ -430,8 +430,27 @@ function locale_language_url_rewrite_url(&$path, &$options) {
case LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN:
if ($options['language']->domain) {
// Ask for an absolute URL with our modified base_url.
global $is_https;
$url_scheme = ($is_https) ? 'https://' : 'http://';
$options['absolute'] = TRUE;
$options['base_url'] = $options['language']->domain;
// Take the domain without ports or protocols so we can apply the
// protocol needed. The setting might include a protocol.
// This is changed in Drupal 8 but we need to keep backwards
// compatibility for Drupal 7.
$host = 'http://' . str_replace(array('http://', 'https://'), '', $options['language']->domain);
$host = parse_url($host, PHP_URL_HOST);
// Apply the appropriate protocol to the URL.
$options['base_url'] = $url_scheme . $host;
if (isset($options['https']) && variable_get('https', FALSE)) {
if ($options['https'] === TRUE) {
$options['base_url'] = str_replace('http://', 'https://', $options['base_url']);
}
elseif ($options['https'] === FALSE) {
$options['base_url'] = str_replace('https://', 'http://', $options['base_url']);
}
}
}
break;

View File

@ -2449,6 +2449,56 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
$fields = $this->xpath('//div[@id="site-name"]//a[@rel="home" and @href=:url]//span', $args);
$this->assertTrue($fields[0] == 'Drupal', t('URLs are rewritten using the browser language.'));
}
/**
* Tests url() when separate domains are used for multiple languages.
*/
function testLanguageDomain() {
// Add the Italian language, without protocol.
$langcode = 'it';
locale_add_language($langcode, 'Italian', 'Italian', LANGUAGE_LTR, 'it.example.com', '', TRUE, FALSE);
// Add the French language, with protocol.
$langcode = 'fr';
locale_add_language($langcode, 'French', 'French', LANGUAGE_LTR, 'http://fr.example.com', '', TRUE, FALSE);
// Enable language URL detection.
$negotiation = array_flip(array(LOCALE_LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_DEFAULT));
language_negotiation_set(LANGUAGE_TYPE_INTERFACE, $negotiation);
variable_set('locale_language_negotiation_url_part', 1);
global $is_https;
$languages = language_list();
foreach (array('it', 'fr') as $langcode) {
// Build the link we're going to test based on the clean url setting.
$link = (!empty($GLOBALS['conf']['clean_url'])) ? $langcode . '.example.com/admin' : $langcode . '.example.com/?q=admin';
// Test URL in another language.
// Base path gives problems on the testbot, so $correct_link is hard-coded.
// @see UrlAlterFunctionalTest::assertUrlOutboundAlter (path.test).
$url = url('admin', array('language' => $languages[$langcode]));
$url_scheme = ($is_https) ? 'https://' : 'http://';
$correct_link = $url_scheme . $link;
$this->assertTrue($url == $correct_link, t('The url() function returns the right url (@url) in accordance with the chosen language', array('@url' => $url . " == " . $correct_link)));
// Test https via options.
variable_set('https', TRUE);
$url = url('admin', array('https' => TRUE, 'language' => $languages[$langcode]));
$correct_link = 'https://' . $link;
$this->assertTrue($url == $correct_link, t('The url() function returns the right https url (via options) (@url) in accordance with the chosen language', array('@url' => $url . " == " . $correct_link)));
variable_set('https', FALSE);
// Test https via current url scheme.
$temp_https = $is_https;
$is_https = TRUE;
$url = url('admin', array('language' => $languages[$langcode]));
$correct_link = 'https://' . $link;
$this->assertTrue($url == $correct_link, t('The url() function returns the right url (via current url scheme) (@url) in accordance with the chosen language', array('@url' => $url . " == " . $correct_link)));
$is_https = $temp_https;
}
}
}
/**