Index: includes/language.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/language.inc,v retrieving revision 1.19 diff -u -p -r1.19 language.inc --- includes/language.inc 1 Feb 2009 16:45:53 -0000 1.19 +++ includes/language.inc 27 Mar 2009 12:06:35 -0000 @@ -59,6 +59,11 @@ function language_initialize() { // Browser accept-language parsing. if ($language = language_from_browser()) { + // If the language is set from browser preferences, set CACHE_DISABLED + // to avoid caching the page in this language for subsequent requests. + if ($language != language_default()) { + $GLOBALS['conf']['cache'] = CACHE_DISABLED; + } return $language; } Index: modules/simpletest/tests/bootstrap.test =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/bootstrap.test,v retrieving revision 1.12 diff -u -p -r1.12 bootstrap.test --- modules/simpletest/tests/bootstrap.test 31 Jan 2009 16:50:57 -0000 1.12 +++ modules/simpletest/tests/bootstrap.test 27 Mar 2009 12:06:35 -0000 @@ -80,6 +80,75 @@ class BootstrapIPAddressTestCase extends } } +/** + * Test page caching with language negotiation. + */ +class BootstrapPageCacheWithLanguageFallbackTestCase extends DrupalWebTestCase { + + function getInfo() { + return array( + 'name' => t('Page cache test with language negotiation'), + 'description' => t('Enable the page cache and language negotiation, ensure that cached pages are served in the correct language.'), + 'group' => t('Bootstrap') + ); + } + + function setUp() { + parent::setUp('locale'); + $this->web_user = $this->drupalCreateUser(array('administer languages', 'access administration pages')); + $this->drupalLogin($this->web_user); + + // Enable French language. + $edit = array(); + $edit['langcode'] = 'fr'; + + $this->drupalPost('admin/settings/language/add', $edit, t('Add language')); + $this->drupalLogout($this->web_user); + + // Set language negotiation to "Path prefix with fallback". + variable_set('language_negotiation', LANGUAGE_NEGOTIATION_PATH); + + // Force inclusion of language.inc. + drupal_init_language(); + // Enable the page cache. + variable_set('cache', CACHE_NORMAL); + } + + /** + * Test page caching with language fallback. + */ + function testPageCacheLanguageFallback() { + + // Visit the root path with browser language preference set to French. + // Since this is in the default site language (English), the page should + // not be cached for this request. + $this->drupalGet('', array(), array('Accept-Language: fr')); + + // The visitor should be served the page in their preferred language. + $this->assertRaw('xml:lang="fr"', t('Page returned in the correct language.')); + + // Since the page has been set by language preferences, we should neither + // serve the page from cache nor cache the rendered page.. + $this->assertFalse(cache_get(url('', array('absolute' => TRUE)), 'cache_page'), t('Page has not been cached.')); + $this->assertFalse($this->drupalGetHeader('Etag'), t('Page not served from cache.')); + + // Visit the page again with no browser language preference, and confirm + // that it is returned in the correct language. + $this->drupalGet(''); + $this->assertRaw('xml:lang="en"', t('Page returned in the correct language.')); + // This request should not have been served from cache since there have + // been no valid requests. + $this->assertFalse($this->drupalGetHeader('Etag'), t('Page not served from cache.')); + // Confirm the cache was populated from this request. + $this->assertTrue(cache_get(url('', array('absolute' => TRUE)), 'cache_page'), t('Page has been cached.')); + + // Ensure that the page served from cache correctly when requested again. + $this->drupalGet(''); + $this->assertTrue($this->drupalGetHeader('Etag'), t('Page served from cache')); + $this->assertRaw('xml:lang="en"', t('Page returned in the correct language.')); + } +} + class BootstrapPageCacheTestCase extends DrupalWebTestCase { function getInfo() {