/**
  * Prepares the current environment for running the test.
  *
  * Backups various current environment variables and resets them, so they do
  * not interfere with the Backdrop site installation in which tests are executed
  * and can be restored in tearDown().
  *
  * Also sets up new resources for the testing environment, such as the public
  * filesystem and configuration directories.
  *
  * @see BackdropWebTestCase::setUp()
  * @see BackdropWebTestCase::tearDown()
  */
 protected function prepareEnvironment()
 {
     global $user, $language, $settings, $config_directories;
     // Store necessary current values before switching to prefixed database.
     $this->originalLanguage = $language;
     $this->originalLanguageDefault = config_get('system.core', 'language_default');
     $this->originalConfigDirectories = $config_directories;
     $this->originalFileDirectory = config_get('system.core', 'file_public_path', 'files');
     $this->originalProfile = backdrop_get_profile();
     $this->originalCleanUrl = config_get('system.core', 'clean_url');
     $this->originalUser = $user;
     $this->originalSettings = $settings;
     // Set to English to prevent exceptions from utf8_truncate() from t()
     // during install if the current language is not 'en'.
     // The following array/object conversion is copied from language_default().
     $language = (object) array('langcode' => 'en', 'name' => 'English', 'direction' => 0, 'enabled' => 1, 'weight' => 0);
     // Save and clean the shutdown callbacks array because it is static cached
     // and will be changed by the test run. Otherwise it will contain callbacks
     // from both environments and the testing environment will try to call the
     // handlers defined by the original one.
     $callbacks =& backdrop_register_shutdown_function();
     $this->originalShutdownCallbacks = $callbacks;
     $callbacks = array();
     // 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';
     // Create the directories.
     file_prepare_directory($this->public_files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
     file_prepare_directory($this->private_files_directory, FILE_CREATE_DIRECTORY);
     file_prepare_directory($this->temp_files_directory, FILE_CREATE_DIRECTORY);
     $this->generatedTestFiles = FALSE;
     // Set the new config directories. During test execution, these values are
     // manually set directly in config_get_config_directory().
     $config_base_path = 'files/simpletest/' . substr($this->databasePrefix, 10) . '/config_';
     $config_directories['active'] = $config_base_path . 'active';
     $config_directories['staging'] = $config_base_path . 'staging';
     $active_directory = config_get_config_directory('active');
     $staging_directory = config_get_config_directory('staging');
     file_prepare_directory($active_directory, FILE_CREATE_DIRECTORY);
     file_prepare_directory($staging_directory, FILE_CREATE_DIRECTORY);
     // Log fatal errors.
     ini_set('log_errors', 1);
     ini_set('error_log', $this->public_files_directory . '/error.log');
     // Set the test information for use in other parts of Backdrop.
     $test_info =& $GLOBALS['backdrop_test_info'];
     $test_info['test_run_id'] = $this->databasePrefix;
     $test_info['in_child_site'] = FALSE;
     // Disable Drupal compatibility for test runs.
     $settings['backdrop_drupal_compatibility'] = FALSE;
     // Indicate the environment was set up correctly.
     $this->setupEnvironment = TRUE;
 }
Пример #2
0
 function get_profile()
 {
     return backdrop_get_profile();
 }