diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index f65ab4c..73d8a95 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -602,6 +602,15 @@ function drupal_settings_initialize() { if (file_exists(DRUPAL_ROOT . '/' . conf_path() . '/settings.php')) { include_once DRUPAL_ROOT . '/' . conf_path() . '/settings.php'; } + + // Enable simpletest to include additional settings so overrides and requests + // that don't use the database can be tested + if ($test_prefix = drupal_valid_test_ua()) { + if (file_exists(DRUPAL_ROOT . '/' . conf_path() . '/files/simpletest/' . substr($test_prefix, 10) . '/settings/simpletest_settings.php')) { + include_once DRUPAL_ROOT . '/' . conf_path() . '/files/simpletest/' . substr($test_prefix, 10) . '/settings/simpletest_settings.php'; + } + } + $is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on'; if (isset($base_url)) { @@ -2184,13 +2193,13 @@ function _drupal_bootstrap_page_cache() { require_once DRUPAL_ROOT . '/' . $include; } // Check for a cache mode force from settings.php. - if (variable_get('page_cache_without_database')) { + if (config('system.performance')->get('page_cache_without_database')) { $cache_enabled = TRUE; } else { drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES, FALSE); - $config = config('system.performance'); - $cache_enabled = $config->get('cache'); + // Database now available get a fresh system.performance config object. + $cache_enabled = config('system.performance')->get('cache'); } drupal_block_denied(ip_address()); // If there is no session cookie and cache is enabled (or forced), try diff --git a/core/lib/Drupal/Core/Cache/NullBackend.php b/core/lib/Drupal/Core/Cache/NullBackend.php index c3da5d7..1397335 100644 --- a/core/lib/Drupal/Core/Cache/NullBackend.php +++ b/core/lib/Drupal/Core/Cache/NullBackend.php @@ -42,7 +42,7 @@ class NullBackend implements CacheBackendInterface { /** * Implements Drupal\Core\Cache\CacheBackendInterface::set(). */ - function set($cid, $data, $expire = CACHE_PERMANENT) {} + function set($cid, $data, $expire = CACHE_PERMANENT, array $tags = array()) {} /** * Implements Drupal\Core\Cache\CacheBackendInterface::delete(). @@ -70,6 +70,11 @@ class NullBackend implements CacheBackendInterface { function expire() {} /** + * Implements Drupal\Core\Cache\CacheBackendInterface::invalidateTags(). + */ + function invalidateTags(array $tags) {} + + /** * Implements Drupal\Core\Cache\CacheBackendInterface::garbageCollection(). */ function garbageCollection() {} diff --git a/core/lib/Drupal/Core/Config/DatabaseStorage.php b/core/lib/Drupal/Core/Config/DatabaseStorage.php index 63ae7b4..6302847 100644 --- a/core/lib/Drupal/Core/Config/DatabaseStorage.php +++ b/core/lib/Drupal/Core/Config/DatabaseStorage.php @@ -18,11 +18,13 @@ class DatabaseStorage extends StorageBase { // read without actually having the database available. In this case, // catch the exception and just return an empty array so the caller can // handle it if need be. - try { - return db_query('SELECT data FROM {config} WHERE name = :name', array(':name' => $this->name))->fetchField(); - } catch (Exception $e) { - return array(); + if (function_exists('db_query')) { + try { + return db_query('SELECT data FROM {config} WHERE name = :name', array(':name' => $this->name))->fetchField(); + } catch (Exception $e) { + } } + return array(); } /** diff --git a/core/modules/config/config.test b/core/modules/config/config.test index f69dde9..d176b58 100644 --- a/core/modules/config/config.test +++ b/core/modules/config/config.test @@ -293,3 +293,44 @@ class ConfUpdate7to8TestCase extends WebTestBase { $this->assertEqual($config->get('config_test_bar'), $this->testContent); } } + +/** + * Tests using Configuration if the database is not available + */ +class ConfEarlyConfigGetTestCase extends WebTestBase { + + public static function getInfo() { + return array( + 'name' => 'Configuration use if database unavailable', + 'description' => 'Tests the ability to access config if database is + unavailable eg. if page_cache_without_database is set.', + 'group' => 'Configuration', + ); + } + + function setUp() { + parent::setUp('config_upgrade'); + require_once DRUPAL_ROOT . '/core/includes/update.inc'; + } + + /** + * Test getting a page from the site when page_cache_without_database is set + * to TRUE. This will use use system.performance config. + */ + function testGetFrontPageCacheWithoutDatabase() { + // Set the page_cache_without_database as this configuration is used before + // the database has been bootstrapped. Set the cache backend to use the + // NullBackend class so we avoid php errors from trying to use cache's + // DatabaseBackend. + $conf_lines = array( + "\$conf['system.performance']['page_cache_without_database'] = TRUE;", + "\$conf['cache_classes']['cache'] = 'Drupal\Core\Cache\NullBackend';", + ); + $this->createSimpletestSettingsFile($conf_lines); + $this->drupalGet(''); + + // Drupal will return the user account page on a page cache miss on a site + // with no content + $this->assertText(t('User account')); + } +} diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 277e97b..60be7a6 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -144,6 +144,11 @@ abstract class WebTestBase extends TestBase { protected $redirect_count; /** + * A directory for simpletest to write a settings file to. + */ + protected $simpletestSettingsDir; + + /** * Constructor for Drupal\simpletest\WebTestBase. */ function __construct($test_id = NULL) { @@ -635,6 +640,14 @@ abstract class WebTestBase extends TestBase { $this->configFileDirectory = $this->originalFileDirectory . '/' . $GLOBALS['config_directory_name']; file_prepare_directory($this->configFileDirectory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); + // Create and set a new directory to store a settings.phpand signature key. + // The child site automatically adjusts conf_path to use a seetings.php file + // stored here. + // @see config_get_config_directory() + $this->simpletestSettingsDir = $this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10) . '/settings'; + file_prepare_directory($this->simpletestSettingsDir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); + file_save_htaccess($this->simpletestSettingsDir); + // Log fatal errors. ini_set('log_errors', 1); ini_set('error_log', $this->public_files_directory . '/error.log'); @@ -2863,4 +2876,30 @@ abstract class WebTestBase extends TestBase { $this->verbose(t('Email:') . '
' . print_r($mail, TRUE) . '
'); } } + + /** + * Creates simpletest_settings.php file. + * + * @param array $lines + * Lines to add to the simpletest_settings.php, for eaxmple: + * @code + * array( + * "\$conf['page_cache_without_database'] = TRUE;", + * ); + * @endcode + */ + protected function createSimpletestSettingsFile($lines = array()) { + $header = <<simpletestSettingsDir . '/simpletest_settings.php', implode("\n", $contents) . "\n"); + } }