Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.867 diff -u -p -r1.867 common.inc --- includes/common.inc 13 Feb 2009 04:43:00 -0000 1.867 +++ includes/common.inc 21 Feb 2009 10:22:07 -0000 @@ -1846,7 +1846,7 @@ function l($text, $path, array $options * react to the closing of the page by calling hook_exit(). */ function drupal_page_footer() { - global $user; + global $user, $no_cache; // Destroy empty anonymous sessions if possible. if (!headers_sent() && drupal_session_is_started() && empty($_SESSION) && !$user->uid) { @@ -1856,7 +1856,7 @@ function drupal_page_footer() { watchdog('session', '$_SESSION is non-empty yet no code has called drupal_session_start().', array(), WATCHDOG_NOTICE); } - if (variable_get('cache', CACHE_DISABLED) != CACHE_DISABLED) { + if (variable_get('cache', CACHE_DISABLED) != CACHE_DISABLED && $no_cache != TRUE) { page_set_cache(); } 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 21 Feb 2009 10:22:07 -0000 @@ -10,7 +10,7 @@ * Choose a language for the page, based on language negotiation settings. */ function language_initialize() { - global $user; + global $user, $no_cache; // Configured presentation language mode. $mode = variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE); @@ -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 $no_cache to TRUE + // to avoid caching the page in this language for subsequent requests. + if ($language != language_default()) { + $no_cache = TRUE; + } 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 21 Feb 2009 10:22:08 -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() {