diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 601e97b..5c190ad 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -689,16 +689,20 @@ function drupal_settings_initialize() { // Make conf_path() available as local variable in settings.php. $conf_path = conf_path(); - if (file_exists(DRUPAL_ROOT . '/' . $conf_path . '/settings.php')) { - include_once DRUPAL_ROOT . '/' . $conf_path . '/settings.php'; - } - // If running as a SimpleTest child site, load additional per-test settings. + // If running within a test, load settings.php for this test run instead. 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'; + $settings_file = DRUPAL_ROOT . '/' . conf_path() . '/files/simpletest/' . substr($test_prefix, 10) . '/settings.php'; + if (file_exists($settings_file)) { + include_once $settings_file; + } + else { + die(); } } + elseif (file_exists(DRUPAL_ROOT . '/' . $conf_path . '/settings.php')) { + include_once DRUPAL_ROOT . '/' . $conf_path . '/settings.php'; + } $is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on'; @@ -2334,13 +2338,12 @@ function _drupal_bootstrap_page_cache() { date_default_timezone_set(drupal_get_user_timezone()); // If the skipping of the bootstrap hooks is not enforced, call // hook_boot. Hooks cannot be invoked without database access. - if (!variable_get('page_cache_without_database') && variable_get('page_cache_invoke_hooks', TRUE)) { + $invoke_boot_hooks = (!variable_get('page_cache_without_database') && variable_get('page_cache_invoke_hooks', TRUE)); + if ($invoke_boot_hooks) { bootstrap_invoke_all('boot'); } drupal_serve_page_from_cache($cache); - // If the skipping of the bootstrap hooks is not enforced, call - // hook_exit. Hooks cannot be invoked without database access. - if (!variable_get('page_cache_without_database') && variable_get('page_cache_invoke_hooks', TRUE)) { + if ($invoke_boot_hooks) { bootstrap_invoke_all('exit'); } // We are done. diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index 6884d69..d0c154f 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -87,9 +87,9 @@ abstract class TestBase { protected $setup = FALSE; /** - * A directory for simpletest to write a settings file to. + * The base filesystem directory for this test. */ - protected $additionalSettingsDirectory; + protected $testFileDirectory; /** * Constructor for Test. @@ -639,10 +639,10 @@ abstract class TestBase { // Create test directory ahead of installation so fatal errors and debug // information can be logged during installation process. - // Use temporary files directory with the same prefix as the database. - $this->public_files_directory = $this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10); - $this->private_files_directory = $this->public_files_directory . '/private'; - $this->temp_files_directory = $this->private_files_directory . '/temp'; + $this->testFileDirectory = $this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10); + $this->public_files_directory = $this->testFileDirectory . '/public'; + $this->private_files_directory = $this->testFileDirectory . '/private'; + $this->temp_files_directory = $this->testFileDirectory . '/temp'; // Create the directories file_prepare_directory($this->public_files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); @@ -654,17 +654,11 @@ abstract class TestBase { // The child site automatically adjusts the global $config_directory_name to // a test-prefix-specific directory within the public files directory. // @see config_get_config_directory() + // Hint: $this->configFileDirectory == $this->testFileDirectory . '/config' $GLOBALS['config_directory_name'] = 'simpletest/' . substr($this->databasePrefix, 10) . '/config'; $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 simpletest_settings.php file. - // The child site loads this in addition to the primary settings.php file. - // @see drupal_settings_initialize() - $this->additionalSettingsDirectory = $this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10) . '/settings'; - file_prepare_directory($this->additionalSettingsDirectory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); - file_save_htaccess($this->additionalSettingsDirectory); - // Log fatal errors. ini_set('log_errors', 1); ini_set('error_log', $this->public_files_directory . '/error.log'); @@ -699,7 +693,7 @@ abstract class TestBase { } // Delete temporary files directory. - file_unmanaged_delete_recursive($this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10)); + file_unmanaged_delete_recursive($this->testFileDirectory); // Restore original database connection. Database::removeConnection('default'); @@ -864,32 +858,4 @@ abstract class TestBase { } return $all_permutations; } - - /** - * Creates simpletest_settings.php file. - * - * @param array $conf - * Conf overrides to add to the simpletest_settings.php, for example: - * @code - * array( - * 'page_cache_without_database' = TRUE, - * ); - * @endcode - */ - protected function createSimpletestSettingsFile($conf = array()) { - include_once './core/includes/utility.inc'; - - $contents = <<additionalSettingsDirectory . '/simpletest_settings.php', $contents); - } } diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index f1a5f95..b2db751 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -587,6 +587,10 @@ abstract class WebTestBase extends TestBase { // Prepare the environment for running tests. $this->prepareEnvironment(); + // Create settings.php file for this test. + // @see drupal_settings_initialize() + $this->createSettings(); + // Reset all statics and variables to perform tests in a clean environment. $conf = array(); drupal_static_reset(); @@ -679,6 +683,48 @@ abstract class WebTestBase extends TestBase { } /** + * Creates a settings.php file for the site under test. + * + * @param array $conf + * Conf overrides to add to settings.php; e.g.: + * @code + * array( + * 'page_cache_without_database' = TRUE, + * ); + * @endcode + * + * @see drupal_settings_initialize() + */ + protected function createSettings(array $new_conf = array()) { + include_once DRUPAL_ROOT . '/core/includes/utility.inc'; + + $settings_file = $this->testFileDirectory . '/settings.php'; + // If the test site specific settings.php exists already, read/append to it. + if (file_exists($settings_file)) { + include $settings_file; + } + // Otherwise, use the parent site's settings.php as base. + else { + include DRUPAL_ROOT . '/' . conf_path() . '/settings.php'; + } + + $conf = array_merge($conf, $new_conf); + $contents = 'testFileDirectory . '/settings.php'; + unlink($settings_file); + } + + /** * Preload the registry from the testing site. * * This method is called by Drupal\simpletest\WebTestBase::setUp(), and preloads diff --git a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php index 9514946..851b924 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php @@ -125,8 +125,8 @@ class PageCacheTest extends WebTestBase { 'page' => 'Drupal\bootstrap_test\Cache\TestBackend', ), ); + $this->createSettings($conf); - $this->createSimpletestSettingsFile($conf); $this->drupalGet(''); $this->assertText('Page returned by Drupal\bootstrap_test\Cache\TestBackend'); } diff --git a/core/modules/system/tests/modules/bootstrap_test/lib/Drupal/bootstrap_test/Cache/TestBackend.php b/core/modules/system/tests/modules/bootstrap_test/lib/Drupal/bootstrap_test/Cache/TestBackend.php index 8812398..6b10ddb 100644 --- a/core/modules/system/tests/modules/bootstrap_test/lib/Drupal/bootstrap_test/Cache/TestBackend.php +++ b/core/modules/system/tests/modules/bootstrap_test/lib/Drupal/bootstrap_test/Cache/TestBackend.php @@ -6,6 +6,7 @@ */ namespace Drupal\bootstrap_test\Cache; + use Drupal\Core\Cache\NullBackend; /**