summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcatch2012-02-11 05:17:56 (GMT)
committer catch2012-02-11 05:17:56 (GMT)
commit055900b3388358bb24fc59b7c1f00977fcc089aa (patch)
treeed08558695fdc780d258c897f3f7ba9bb25da0b1
parent57019c74c71b08f779095d67008d4cce12a24ce5 (diff)
Issue #1250800 by attiks, Jelle_S, dereine: Fixed Language domain should work regardless of ports or protocols.
-rw-r--r--core/includes/locale.inc12
-rw-r--r--core/modules/locale/locale.test54
2 files changed, 65 insertions, 1 deletions
diff --git a/core/includes/locale.inc b/core/includes/locale.inc
index c429872..ab11d31 100644
--- a/core/includes/locale.inc
+++ b/core/includes/locale.inc
@@ -438,8 +438,18 @@ function locale_language_url_rewrite_url(&$path, &$options) {
$domains = locale_language_negotiation_url_domains();
if (!empty($domains[$options['language']->langcode])) {
// 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'] = $domains[$options['language']->langcode];
+ $options['base_url'] = $url_scheme . $domains[$options['language']->langcode];
+ 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;
diff --git a/core/modules/locale/locale.test b/core/modules/locale/locale.test
index c02488f..5408ccd 100644
--- a/core/modules/locale/locale.test
+++ b/core/modules/locale/locale.test
@@ -2212,6 +2212,60 @@ 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.'));
}
+
+ /**
+ * Test if the url function returns the right url when using different domains for different languages.
+ */
+ 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[enabled][locale-url]' => TRUE,
+ 'language[weight][locale-url]' => -10,
+ );
+ $this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
+
+ // Change the domain for the Italian language.
+ $edit = array(
+ 'locale_language_negotiation_url_part' => 1,
+ 'domain[it]' => 'it.example.com',
+ );
+ $this->drupalPost('admin/config/regional/language/configure/url', $edit, t('Save configuration'));
+
+ // Build the link we're going to test based on the clean url setting.
+ $link = (!empty($GLOBALS['conf']['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, t('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']));
+ $correct_link = 'https://' . $link;
+ $this->assertTrue($italian_url == $correct_link, t('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']));
+ $correct_link = 'https://' . $link;
+ $this->assertTrue($italian_url == $correct_link, t('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;
+ }
}
/**