diff options
Diffstat (limited to 'modules/locale/locale.test')
-rw-r--r-- | modules/locale/locale.test | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/modules/locale/locale.test b/modules/locale/locale.test index 2efa63d82..6bc2fb757 100644 --- a/modules/locale/locale.test +++ b/modules/locale/locale.test @@ -1730,15 +1730,14 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase { parent::setUp('locale', 'locale_test'); require_once DRUPAL_ROOT . '/includes/language.inc'; drupal_load('module', 'locale'); + $admin_user = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages', 'administer blocks')); + $this->drupalLogin($admin_user); } /** * Tests for language switching by URL path. */ function testUILanguageNegotiation() { - $admin_user = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages')); - $this->drupalLogin($admin_user); - // A few languages to switch to. // This one is unknown, should get the default lang version. $language_unknown = 'blah-blah'; @@ -1892,6 +1891,50 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase { $this->drupalGet($test['path'], array(), $test['http_header']); $this->assertText($test['expect'], $test['message']); } + + /** + * Test URL language detection when the requested URL has no language. + */ + function testUrlLanguageFallback() { + // Add the Italian language. + $language_browser_fallback = 'it'; + locale_add_language($language_browser_fallback); + $languages = language_list(); + + // Enable the path prefix for the default language: this way any unprefixed + // URL must have a valid fallback value. + $edit = array('prefix' => 'en'); + $this->drupalPost('admin/config/regional/language/edit/en', $edit, t('Save language')); + + // Enable browser and URL language detection. + $edit = array( + 'language[enabled][locale-browser]' => TRUE, + 'language[enabled][locale-url]' => TRUE, + 'language[weight][locale-browser]' => -8, + 'language[weight][locale-url]' => -10, + ); + $this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings')); + $this->drupalGet('admin/config/regional/language/configure'); + + // Enable the language switcher block. + $edit = array('blocks[locale_language][region]' => 'sidebar_first'); + $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); + + // Access the front page without specifying any valid URL language prefix + // and having as browser language preference a non-default language. + $http_header = array("Accept-Language: $language_browser_fallback;q=1"); + $this->drupalGet('', array(), $http_header); + + // Check that the language switcher active link matches the given browser + // language. + $args = array(':url' => base_path() . (!empty($GLOBALS['conf']['clean_url']) ? $language_browser_fallback : "?q=$language_browser_fallback")); + $fields = $this->xpath('//div[@id="block-locale-language"]//a[@class="language-link active" and @href=:url]', $args); + $this->assertTrue($fields[0] == $languages[$language_browser_fallback]->native, t('The browser language is the URL active language')); + + // Check that URLs are rewritten using the given browser language. + $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.')); + } } /** |