/**
  * Generates a random database prefix, runs the install scripts on the
  * prefixed database and enable the specified modules. After installation
  * many caches are flushed and the internal browser is setup so that the
  * page requests will run on the new prefix. A temporary files directory
  * is created with the same name as the database prefix.
  *
  * @param ...
  *   List of modules to enable for the duration of the test. This can be
  *   either a single array or a variable number of string arguments.
  */
 protected function setUp()
 {
     global $user, $language, $conf;
     // Generate a temporary prefixed database to ensure that tests have a clean starting point.
     $this->databasePrefix = 'simpletest' . mt_rand(1000, 1000000);
     db_update('simpletest_test_id')->fields(array('last_prefix' => $this->databasePrefix))->condition('test_id', $this->testId)->execute();
     // Clone the current connection and replace the current prefix.
     $connection_info = Database::getConnectionInfo('default');
     Database::renameConnection('default', 'simpletest_original_default');
     foreach ($connection_info as $target => $value) {
         $connection_info[$target]['prefix'] = array('default' => $value['prefix']['default'] . $this->databasePrefix);
     }
     Database::addConnectionInfo('default', 'default', $connection_info['default']);
     // Store necessary current values before switching to prefixed database.
     $this->originalLanguage = $language;
     $this->originalLanguageDefault = variable_get('language_default');
     $this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files');
     $this->originalProfile = drupal_get_profile();
     $clean_url_original = variable_get('clean_url', 0);
     // 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('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => '');
     // Save and clean shutdown callbacks array because it static cached and
     // will be changed by the test run. If we don't, then it will contain
     // callbacks from both environments. So testing environment will try
     // to call handlers from original environment.
     $callbacks =& drupal_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.
     $public_files_directory = $this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10);
     $private_files_directory = $public_files_directory . '/private';
     $temp_files_directory = $private_files_directory . '/temp';
     // Create the directories
     file_prepare_directory($public_files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
     file_prepare_directory($private_files_directory, FILE_CREATE_DIRECTORY);
     file_prepare_directory($temp_files_directory, FILE_CREATE_DIRECTORY);
     $this->generatedTestFiles = FALSE;
     // Log fatal errors.
     ini_set('log_errors', 1);
     ini_set('error_log', $public_files_directory . '/error.log');
     // Reset all statics and variables to perform tests in a clean environment.
     $conf = array();
     drupal_static_reset();
     // Set the test information for use in other parts of Drupal.
     $test_info =& $GLOBALS['drupal_test_info'];
     $test_info['test_run_id'] = $this->databasePrefix;
     $test_info['in_child_site'] = FALSE;
     include_once DRUPAL_ROOT . '/includes/install.inc';
     drupal_install_system();
     $this->preloadRegistry();
     // Set path variables.
     variable_set('file_public_path', $public_files_directory);
     variable_set('file_private_path', $private_files_directory);
     variable_set('file_temporary_path', $temp_files_directory);
     // Include the testing profile.
     variable_set('install_profile', $this->profile);
     $profile_details = install_profile_info($this->profile, 'en');
     // Install the modules specified by the testing profile.
     module_enable($profile_details['dependencies'], FALSE);
     // Install modules needed for this test. This could have been passed in as
     // either a single array argument or a variable number of string arguments.
     // @todo Remove this compatibility layer in Drupal 8, and only accept
     // $modules as a single array argument.
     $modules = func_get_args();
     if (isset($modules[0]) && is_array($modules[0])) {
         $modules = $modules[0];
     }
     if ($modules) {
         $success = module_enable($modules, TRUE);
         $this->assertTrue($success, t('Enabled modules: %modules', array('%modules' => implode(', ', $modules))));
     }
     // Run the profile tasks.
     $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);
     }
     // Reset/rebuild all data structures after enabling the modules.
     $this->resetAll();
     // Run cron once in that environment, as install.php does at the end of
     // the installation process.
     drupal_cron_run();
     // Log in with a clean $user.
     $this->originalUser = $user;
     drupal_save_session(FALSE);
     $user = user_load(1);
     // Restore necessary variables.
     variable_set('install_task', 'done');
     variable_set('clean_url', $clean_url_original);
     variable_set('site_mail', '*****@*****.**');
     variable_set('date_default_timezone', date_default_timezone_get());
     // Set up English language.
     unset($GLOBALS['conf']['language_default']);
     $language = language_default();
     // Use the test mail class instead of the default mail handler class.
     variable_set('mail_system', array('default-system' => 'TestingMailSystem'));
     drupal_set_time_limit($this->timeLimit);
 }
 /**
  * Changes the database connection to the prefixed one.
  *
  * @see BackdropWebTestCase::setUp()
  */
 protected function changeDatabasePrefix()
 {
     if (empty($this->databasePrefix)) {
         $this->prepareDatabasePrefix();
         // If $this->prepareDatabasePrefix() failed to work, return without
         // setting $this->setupDatabasePrefix to TRUE, so setUp() methods will
         // know to bail out.
         if (empty($this->databasePrefix)) {
             return;
         }
     }
     // Clone the current connection and replace the current prefix.
     $connection_info = Database::getConnectionInfo('default');
     Database::renameConnection('default', 'simpletest_original_default');
     foreach ($connection_info as $target => $value) {
         $connection_info[$target]['prefix'] = array('default' => $value['prefix']['default'] . $this->databasePrefix);
     }
     Database::addConnectionInfo('default', 'default', $connection_info['default']);
     // Indicate the database prefix was set up correctly.
     $this->setupDatabasePrefix = TRUE;
 }
 /**
  * Determine when to run against remote environment.
  */
 protected function setUp()
 {
     //     // BEGIN: Excerpt from DrupalUnitTestCase.
     //     global $conf;
     //
     // Set to that verbose mode works properly.
     $this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files');
     //
     //     spl_autoload_register('db_autoload');
     //
     //     // Reset all statics so that test is performed with a clean environment.
     //     drupal_static_reset();
     //
     //     // Generate temporary prefixed database to ensure that tests have a clean starting point.
     //     $this->databasePrefix = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}');
     //     $conf['file_public_path'] = $this->originalFileDirectory . '/' . $this->databasePrefix;
     //
     // Clone the current connection and replace the current prefix.
     $connection_info = Database::getConnectionInfo('default');
     Database::renameConnection('default', 'simpletest_original_default');
     foreach ($connection_info as $target => $value) {
         $connection_info[$target]['prefix'] = array('default' => $value['prefix']['default'] . $this->databasePrefix);
     }
     Database::addConnectionInfo('default', 'default', $connection_info['default']);
     //
     //     // Set user agent to be consistent with web test case.
     //     $_SERVER['HTTP_USER_AGENT'] = $this->databasePrefix;
     //
     //     // If locale is enabled then t() will try to access the database and
     //     // subsequently will fail as the database is not accessible.
     //     $module_list = module_list();
     //     if (isset($module_list['locale'])) {
     //       $this->originalModuleList = $module_list;
     //       unset($module_list['locale']);
     //       module_list(TRUE, FALSE, FALSE, $module_list);
     //     }
     //     // END: Excerpt from DrupalUnitTestCase.
     if (!$this->remoteUrl && !($this->remoteUrl = variable_get('simpletest_remote_url', FALSE))) {
         $this->remoteUrl = url('', array('absolute' => TRUE));
     }
     // Point the internal browser to the staging site.
     foreach (self::$URL_VARIABLES as $variable) {
         $this->originalUrls[$variable] = $GLOBALS[$variable];
         $GLOBALS[$variable] = $this->remoteUrl;
     }
     $GLOBALS['base_secure_url'] = str_replace('http://', 'https://', $GLOBALS['base_secure_url']);
     // Generate unique remote prefix.
     self::$REMOTE_PREFIX = 'test' . mt_rand(100, 100000);
     // Set the time-limit for the test case.
     drupal_set_time_limit($this->timeLimit);
 }
 /**
  * Return database connection using the given driver
  *
  * @param string $driver
  *
  * @return \DatabaseConnection
  *   Return false if the database API could not bootstrapped or if the
  *   database credentials are missing in the phpunit.xml file
  */
 protected final function getDatabaseConnection($driver)
 {
     if ($this->databaseConnection) {
         return $this->databaseConnection;
     }
     try {
         $credentials = $this->buildDatabaseCredentials();
     } catch (\Exception $e) {
         $this->markTestSkipped("'%s' driver: connection information is missing or invalid");
         return false;
     }
     $this->databaseKey = uniqid('test');
     $this->databaseTarget = $this->databaseKey;
     if (!$this->bootstrapDatabase()) {
         $this->markTestSkipped("could not bootstrap the Drupal database component");
         return false;
     }
     \Database::addConnectionInfo($this->databaseKey, $this->databaseTarget, $credentials);
     return $this->databaseConnection = \Database::getConnection($this->databaseTarget, $this->databaseKey);
 }
Example #5
0
/**
 * Drop-in replacement for db_select that creates a query on default site's database.
 * @see db_select
 * @return SelectQuery
 */
function unl_shared_db_select($table, $alias = NULL, array $options = array())
{
    $databases = unl_get_shared_db_settings();
    Database::addConnectionInfo('default', 'unl_parent_site', $databases['default']['default']);
    $options['target'] = 'unl_parent_site';
    return db_select($table, $alias, $options);
}
 /**
  * Generates a random database prefix, runs the install scripts on the
  * prefixed database and enable the specified modules. After installation
  * many caches are flushed and the internal browser is setup so that the
  * page requests will run on the new prefix. A temporary files directory
  * is created with the same name as the database prefix.
  *
  * @param ...
  *   List of modules to enable for the duration of the test. This can be
  *   either a single array or a variable number of string arguments.
  */
 protected function setUp()
 {
     global $user, $language, $conf;
     // Generate a temporary prefixed database to ensure that tests have a clean starting point.
     $this->databasePrefix = 'simpletest' . mt_rand(1000, 1000000);
     db_update('simpletest_test_id')->fields(array('last_prefix' => $this->databasePrefix))->condition('test_id', $this->testId)->execute();
     // Clone the current connection and replace the current prefix.
     $connection_info = Database::getConnectionInfo('default');
     Database::renameConnection('default', 'simpletest_original_default');
     foreach ($connection_info as $target => $value) {
         $connection_info[$target]['prefix'] = array('default' => $value['prefix']['default'] . $this->databasePrefix);
     }
     Database::addConnectionInfo('default', 'default', $connection_info['default']);
     // Store necessary current values before switching to prefixed database.
     $this->originalLanguage = $language;
     $this->originalLanguageDefault = variable_get('language_default');
     $this->originalFileDirectory = file_directory_path();
     $this->originalProfile = drupal_get_profile();
     $clean_url_original = variable_get('clean_url', 0);
     // Save and clean shutdown callbacks array because it static cached and
     // will be changed by the test run. If we don't, then it will contain
     // callbacks from both environments. So testing environment will try
     // to call handlers from original environment.
     $callbacks =& drupal_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.
     $public_files_directory = $this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10);
     $private_files_directory = $public_files_directory . '/private';
     $temp_files_directory = $private_files_directory . '/temp';
     // Create the directories
     file_prepare_directory($public_files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
     file_prepare_directory($private_files_directory, FILE_CREATE_DIRECTORY);
     file_prepare_directory($temp_files_directory, FILE_CREATE_DIRECTORY);
     $this->generatedTestFiles = FALSE;
     // Log fatal errors.
     ini_set('log_errors', 1);
     ini_set('error_log', $public_files_directory . '/error.log');
     // Reset all statics and variables to perform tests in a clean environment.
     $conf = array();
     drupal_static_reset();
     // Set the test information for use in other parts of Drupal.
     $test_info =& $GLOBALS['drupal_test_info'];
     $test_info['test_run_id'] = $this->databasePrefix;
     $test_info['in_child_site'] = FALSE;
     include_once DRUPAL_ROOT . '/includes/install.inc';
     drupal_install_system();
     $this->preloadRegistry();
     // Set path variables.
     variable_set('file_public_path', $public_files_directory);
     variable_set('file_private_path', $private_files_directory);
     variable_set('file_temporary_path', $temp_files_directory);
     // Include the default profile.
     variable_set('install_profile', 'standard');
     $profile_details = install_profile_info('standard', 'en');
     // Install the modules specified by the default profile.
     module_enable($profile_details['dependencies'], FALSE);
     // Install modules needed for this test. This could have been passed in as
     // either a single array argument or a variable number of string arguments.
     // @todo Remove this compatibility layer in Drupal 8, and only accept
     // $modules as a single array argument.
     $modules = func_get_args();
     if (isset($modules[0]) && is_array($modules[0])) {
         $modules = $modules[0];
     }
     if ($modules) {
         module_enable($modules, TRUE);
     }
     // Run default profile tasks.
     module_enable(array('standard'), FALSE);
     // Rebuild caches.
     drupal_static_reset();
     drupal_flush_all_caches();
     // Register actions declared by any modules.
     actions_synchronize();
     // Reload global $conf array and permissions.
     $this->refreshVariables();
     $this->checkPermissions(array(), TRUE);
     // Reset statically cached schema for new database prefix.
     drupal_get_schema(NULL, TRUE);
     // Run cron once in that environment, as install.php does at the end of
     // the installation process.
     drupal_cron_run();
     // Log in with a clean $user.
     $this->originalUser = $user;
     drupal_save_session(FALSE);
     $user = user_load(1);
     // Restore necessary variables.
     variable_set('install_task', 'done');
     variable_set('clean_url', $clean_url_original);
     variable_set('site_mail', '*****@*****.**');
     variable_set('date_default_timezone', date_default_timezone_get());
     // Set up English language.
     unset($GLOBALS['conf']['language_default']);
     $language = language_default();
     // Use the test mail class instead of the default mail handler class.
     variable_set('mail_system', array('default-system' => 'TestingMailSystem'));
     drupal_set_time_limit($this->timeLimit);
 }
 /**
  * Don't create test db via install, instead copy existing db.
  */
 protected function setUp()
 {
     // Copy of parent::setUp();
     global $user, $language, $conf;
     // Generate a temporary prefixed database to ensure that tests have a clean starting point.
     $this->databasePrefix = 'simpletest' . mt_rand(1000, 1000000);
     db_update('simpletest_test_id')->fields(array('last_prefix' => $this->databasePrefix))->condition('test_id', $this->testId)->execute();
     // Store necessary current values before switching to prefixed database.
     $this->originalLanguage = $language;
     $this->originalLanguageDefault = variable_get('language_default');
     $this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files');
     $this->originalProfile = drupal_get_profile();
     $clean_url_original = variable_get('clean_url', 0);
     // Save and clean shutdown callbacks array because it static cached and
     // will be changed by the test run. If we don't, then it will contain
     // callbacks from both environments. So testing environment will try
     // to call handlers from original environment.
     $callbacks =& drupal_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;
     // 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 Drupal.
     $test_info =& $GLOBALS['drupal_test_info'];
     $test_info['test_run_id'] = $this->databasePrefix;
     $test_info['in_child_site'] = FALSE;
     // Rebuild schema based on prefixed database and such.
     $schemas = drupal_get_schema(NULL, TRUE);
     // Create a list of prefixed source table names.
     $sources = array();
     foreach ($schemas as $name => $schema) {
         $sources[$name] = Database::getConnection()->prefixTables('{' . $name . '}');
     }
     // Clone the current connection and replace the current prefix.
     $connection_info = Database::getConnectionInfo('default');
     Database::renameConnection('default', 'simpletest_original_default');
     foreach ($connection_info as $target => $value) {
         $connection_info[$target]['prefix'] = array('default' => $value['prefix']['default'] . $this->databasePrefix);
     }
     Database::addConnectionInfo('default', 'default', $connection_info['default']);
     // Clone each table into the new database.
     foreach ($schemas as $name => $schema) {
         $this->cloneTable($name, $sources[$name], $schema);
     }
     // Log in with a clean $user.
     $this->originalUser = $user;
     drupal_save_session(FALSE);
     $user = user_load(1);
     // Set up English language.
     unset($GLOBALS['conf']['language_default']);
     $language = language_default();
     // Use the test mail class instead of the default mail handler class.
     variable_set('mail_system', array('default-system' => 'TestingMailSystem'));
     drupal_set_time_limit($this->timeLimit);
     $this->resetAll();
     $this->refreshVariables();
     $this->setup = TRUE;
 }
Example #8
0
/**
 * Adds virtual name and access fields to a result set from the unl_sites table.
 * @param $sites The result of db_select()->fetchAll() on the unl_sites table.
 */
function unl_add_extra_site_info($sites)
{
    // Get all custom made roles (roles other than authenticated, anonymous, administrator)
    $roles = user_roles(TRUE);
    unset($roles[DRUPAL_AUTHENTICATED_RID]);
    unset($roles[variable_get('user_admin_role')]);
    // Setup alternate db connection so we can query other sites' tables without a prefix being attached
    $database_noprefix = array('database' => $GLOBALS['databases']['default']['default']['database'], 'username' => $GLOBALS['databases']['default']['default']['username'], 'password' => $GLOBALS['databases']['default']['default']['password'], 'host' => $GLOBALS['databases']['default']['default']['host'], 'port' => $GLOBALS['databases']['default']['default']['port'], 'driver' => $GLOBALS['databases']['default']['default']['driver']);
    Database::addConnectionInfo('UNLNoPrefix', 'default', $database_noprefix);
    // The master prefix that was specified during initial drupal install
    $master_prefix = $GLOBALS['databases']['default']['default']['prefix'];
    foreach ($sites as $row) {
        // Skip over any sites that aren't properly installed.
        if (!in_array($row->installed, array(2, 6))) {
            continue;
        }
        // Switch to alt db connection
        db_set_active('UNLNoPrefix');
        // Get site name
        $table = $row->db_prefix . '_' . $master_prefix . 'variable';
        $name = db_query("SELECT value FROM " . $table . " WHERE name = 'site_name'")->fetchField();
        // Get last access timestamp (by a non-administrator)
        $table_users = $row->db_prefix . '_' . $master_prefix . 'users u';
        $table_users_roles = $row->db_prefix . '_' . $master_prefix . 'users_roles r';
        if (!empty($roles)) {
            $access = db_query('SELECT u.access FROM ' . $table_users . ', ' . $table_users_roles . ' WHERE u.uid = r.uid AND u.access > 0 AND r.rid IN (' . implode(',', array_keys($roles)) . ') ORDER BY u.access DESC')->fetchColumn();
        } else {
            $access = 0;
        }
        // Restore default db connection
        db_set_active();
        // Update unl_sites table of the default site
        $row->name = @unserialize($name);
        $row->access = (int) $access;
    }
}
</div>
  <?php 
}
?>


<div class="clear"></div>
</div><!--end content-->
</div><!--end contentContainer-->

<div id="footer-viewer">
	<section id="menuArea">
		<select id="menu">
		<?php 
$epi_database = array('database' => 'epidemiology', 'username' => 'admin', 'password' => 'roan2[twangs', 'host' => 'can.cdspk1y1mo9a.us-west-2.rds.amazonaws.com', 'driver' => 'mysql');
Database::addConnectionInfo('epidemiology_data', 'default', $epi_database);
db_set_active('epidemiology_data');
$result = db_select('menu_params')->fields('menu_params')->execute();
while ($row = $result->fetchAssoc()) {
    echo "<option value='" . $row["data_suffix"] . ($row["aggregate?"] == 1 ? "&a" : "") . "' data-aggregate=" . ($row["aggregate?"] == 1 ? 1 : 0) . ">" . $row["name"] . "</option>";
}
db_set_active();
?>
		</select>
	</section>
	<section id="selectArea">
		<select>
			
		</select>
	</section>
	<section id="buttonArea">