- <?php
- * Class for setting up a full installation profile for caching purposes.
- *
- * This class is used when using the run-tests.sh script and passing in the
- * --cache option. If used, then the script will initiate this class once per
- * installation profile. The installation profile will be fully installed and
- * set up, then used for all test runs that use that same profile.
- *
- * Note that no actual tests should be run using this class. This is only used
- * to install a profile, store it, and then exit.
- */
- class BackdropWebTestCaseCache extends BackdropWebTestCase {
-
- * Set the installation profile to be used as a cache.
- */
- public function setProfile($profile) {
- $this->profile = $profile;
-
- $this->databasePrefix = 'simpletest_cache_' . $this->profile . '_';
- $this->fileDirectoryName = 'simpletest_cache_' . $this->profile;
- }
-
-
- * Check if cache folder already exists.
- *
- * @return boolean
- * TRUE if cache exists, FALSE if no cache for current profile.
- */
- public function isCached(){
- $file_public_path = config_get('system.core', 'file_public_path', 'files');
- $cache_dir = $file_public_path . '/simpletest/' . $this->fileDirectoryName;
- if (is_dir($cache_dir)) {
- return TRUE;
- }
- return FALSE;
- }
-
-
- * Prepare cache tables and config directories.
- */
- public function prepareCache($skip_myisam = FALSE) {
- $this->setUp();
-
- if (!$skip_myisam) {
-
- $this->alterToMyISAM();
- }
-
- $this->tearDown();
- }
-
-
- * Sets up a Backdrop site to be used as a cached installation profile.
- */
- protected function setUp(){
- global $conf;
-
-
- $this->prepareEnvironment();
- if (!$this->setupEnvironment) {
- return FALSE;
- }
-
-
- $conf = array();
- backdrop_static_reset();
-
-
-
-
-
- $this->changeDatabasePrefix();
- if (!$this->setupDatabasePrefix) {
- return FALSE;
- }
-
-
-
- config_get_config_storage('active')->initializeStorage();
- config_get_config_storage('staging')->initializeStorage();
-
-
-
-
-
-
- config_install_default_config('system');
- config_set('system.core', 'install_profile', $this->profile);
-
-
- include_once BACKDROP_ROOT . '/core/includes/install.inc';
- backdrop_install_system();
-
-
- $core_config = config('system.core');
- $core_config->set('file_default_scheme', 'public');
- $core_config->set('file_public_path', $this->public_files_directory);
- $core_config->set('file_private_path', $this->private_files_directory);
- $core_config->set('file_temporary_path', $this->temp_files_directory);
- $core_config->save();
-
-
- backdrop_static_reset('backdrop_get_schema_versions');
-
-
- config_set('system.core', 'install_profile', $this->profile);
- $profile_details = install_profile_info($this->profile, 'en');
-
-
- module_enable($profile_details['dependencies'], FALSE);
-
-
- $install_profile_module_exists = db_query("SELECT 1 FROM {system} WHERE type = 'module' AND name = :name", array(':name' => $this->profile))->fetchField();
- if ($install_profile_module_exists) {
- module_enable(array($this->profile), FALSE);
- }
- return TRUE;
- }
-
-
- * Reset the database prefix and global config.
- */
- protected function tearDown() {
- global $user, $language, $settings, $config_directories;
-
- Database::removeConnection('default');
- Database::renameConnection('simpletest_original_default', 'default');
-
-
- $config_directories = $this->originalConfigDirectories;
-
-
- $settings = $this->originalSettings;
-
-
-
- $callbacks = &backdrop_register_shutdown_function();
- $callbacks = $this->originalShutdownCallbacks;
-
-
- $user = $this->originalUser;
- backdrop_save_session(TRUE);
-
-
- $this->loggedInUser = FALSE;
- $this->additionalCurlOptions = array();
-
-
-
- module_list(TRUE);
- module_implements_reset();
-
-
- field_cache_clear();
-
-
- $this->refreshVariables();
-
-
- $this->curlClose();
- }
-
-
- * Alter tables to MyISAM engine to speed up tests.
- *
- * MyISAM is faster to delete and copy tables. Its advantage is small when
- * using /var/lib/mysql on an SHM (memory) device but is much bigger when
- * tests are run on a regular device.
- */
- protected function alterToMyISAM() {
- if (Database::getConnection()->driver() != 'mysql') {
- return;
- }
- $skip_alter = array(
- 'taxonomy_term_data',
- 'node',
- 'node_access',
- 'node_revision',
- 'node_comment_statistics',
- );
- $tables = db_find_tables($this->databasePrefix . '%');
- foreach ($tables as $table) {
- $original_table_name = substr($table, strlen($this->databasePrefix));
- if(!in_array($original_table_name, $skip_alter)){
- db_query('ALTER TABLE ' . $table . ' ENGINE=MyISAM');
- }
- }
- }
- }