diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index f65ab4c..a85ec6d 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)) { diff --git a/core/modules/config/config.test b/core/modules/config/config.test index f69dde9..4833507 100644 --- a/core/modules/config/config.test +++ b/core/modules/config/config.test @@ -293,3 +293,38 @@ 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() { + $conf_lines = array( + "\$conf['page_cache_without_database'] = TRUE;", + ); + $this->createSimpletestSettingsFile($conf_lines); + $this->drupalGet(''); + // The page returned will be the User Account page as the site has 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..78f9112 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)); + } }