本文整理汇总了PHP中drupal_get_schema函数的典型用法代码示例。如果您正苦于以下问题:PHP drupal_get_schema函数的具体用法?PHP drupal_get_schema怎么用?PHP drupal_get_schema使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了drupal_get_schema函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateSettings
/**
* Validate the settings form.
*/
public function validateSettings(&$element, &$form_state)
{
$schema = drupal_get_schema('membership_entity');
if ($element['length']['#value'] > $schema['fields']['member_id']['length']) {
form_error($element['length'], t('Member ID length cannot exceed %max.', array('%max' => $schema['fields']['member_id']['length'])));
}
}
示例2: testDefaultInsertWithFields
/**
* Tests that we can insert fields with values and defaults in the same query.
*/
function testDefaultInsertWithFields()
{
$query = db_insert('test')->fields(array('name' => 'Bob'))->useDefaults(array('job'));
$id = $query->execute();
$schema = drupal_get_schema('test');
$job = db_query('SELECT job FROM {test} WHERE id = :id', array(':id' => $id))->fetchField();
$this->assertEqual($job, $schema['fields']['job']['default'], 'Default field value is set.');
}
示例3: findRequiredModules
/**
* Overrides Drupal\configuration\Config\Configuration::findRequiredModules().
*/
public function findRequiredModules()
{
$this->addToModules('views');
$view = $this->getData();
// We get the module that creates the table for the view query.
$schema = drupal_get_schema($view->base_table);
$this->addToModules($schema['module']);
foreach (views_object_types() as $type => $info) {
foreach ($view->display as $display_id => $display) {
// Views with a display provided by views_content module.
if ($display->display_plugin == 'panel_pane') {
$this->addToModules('views_content');
}
$view->set_display($display_id);
foreach ($view->display_handler->get_handlers($type) as $handler_id => $handler) {
if ($type == 'field') {
if (!empty($handler->field_info) && !empty($handler->field_info['module'])) {
$this->addToModules($handler->field_info['module']);
}
}
}
}
}
}
示例4: install_finished
/**
* Installation task; perform final steps and display a 'finished' page.
*
* @param $install_state
* An array of information about the current installation state.
* @return
* A message informing the user that the installation is complete.
*/
function install_finished(&$install_state)
{
drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_name())), PASS_THROUGH);
$messages = drupal_set_message();
$output = '<p>' . st('Congratulations, @drupal has been successfully installed.', array('@drupal' => drupal_install_profile_name())) . '</p>';
$output .= '<p>' . (isset($messages['error']) ? st('Review the messages above before continuing on to <a href="@url">your new site</a>.', array('@url' => url(''))) : st('You may now visit <a href="@url">your new site</a>.', array('@url' => url('')))) . '</p>';
if (module_exists('help')) {
$output .= '<p>' . st('For more information on configuring Drupal, refer to the <a href="@help">help section</a>.', array('@help' => url('admin/help'))) . '</p>';
}
// Rebuild the module and theme data, in case any newly-installed modules
// need to modify it via hook_system_info_alter(). We need to clear the
// theme static cache first, to make sure that the theme data is actually
// rebuilt.
drupal_static_reset('_system_rebuild_theme_data');
system_rebuild_module_data();
system_rebuild_theme_data();
// Rebuild menu and registry to get content type links registered by the
// profile, and possibly any other menu items created through the tasks.
menu_rebuild();
// Rebuild the database cache of node types, so that any node types added
// by newly installed modules are registered correctly and initialized with
// the necessary fields.
node_types_rebuild();
// Register actions declared by any modules.
actions_synchronize();
// Randomize query-strings on css/js files, to hide the fact that this is a
// new install, not upgraded yet.
_drupal_flush_css_js();
// Remember the profile which was used.
variable_set('install_profile', drupal_get_profile());
// Install profiles are always loaded last
db_update('system')->fields(array('weight' => 1000))->condition('type', 'module')->condition('name', drupal_get_profile())->execute();
// Cache a fully-built schema.
drupal_get_schema(NULL, TRUE);
// Run cron to populate update status tables (if available) so that users
// will be warned if they've installed an out of date Drupal version.
// Will also trigger indexing of profile-supplied content or feeds.
drupal_cron_run();
return $output;
}
示例5: tearDown
/**
* Delete created files and temporary files directory, delete the tables created by setUp(),
* and reset the database prefix.
*/
protected function tearDown()
{
global $db_prefix;
if (preg_match('/simpletest\\d+/', $db_prefix)) {
// Delete temporary files directory and reset files directory path.
simpletest_clean_temporary_directory(file_directory_path());
variable_set('file_directory_path', $this->originalFileDirectory);
// Remove all prefixed tables (all the tables in the schema).
$schema = drupal_get_schema(NULL, TRUE);
$ret = array();
foreach ($schema as $name => $table) {
db_drop_table($ret, $name);
}
// Return the database prefix to the original.
$db_prefix = $this->originalPrefix;
// Ensure that the internal logged in variable is reset.
$this->isLoggedIn = FALSE;
// Reload module list and implementations to ensure that test module hooks
// aren't called after tests.
module_list(TRUE);
module_implements(MODULE_IMPLEMENTS_CLEAR_CACHE);
// Rebuild caches.
$this->refreshVariables();
// Close the CURL handler.
$this->curlClose();
}
}
示例6: setUp
/**
* Installs Atrium instead of Drupal
*
* 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.
*/
protected function setUp()
{
global $db_prefix, $user, $language, $profile, $install_locale;
// $language (Drupal 6).
// Store necessary current values before switching to prefixed database.
$this->originalPrefix = $db_prefix;
$this->originalLanguage = clone $language;
$clean_url_original = variable_get('clean_url', 0);
// Must reset locale here, since schema calls t(). (Drupal 6)
if (module_exists('locale')) {
$language = (object) array('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => '');
locale(NULL, NULL, TRUE);
}
// Generate temporary prefixed database to ensure that tests have a clean starting point.
// $db_prefix = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}');
$db_prefix = 'simpletest' . mt_rand(1000, 1000000);
$install_locale = $this->install_locale;
$profile = $this->install_profile;
// include_once DRUPAL_ROOT . '/includes/install.inc';
include_once './includes/install.inc';
drupal_install_system();
// $this->preloadRegistry();
// Set up theme system for the maintenance page.
// Otherwise we have trouble: https://ds.openatrium.com/dsi/node/18426#comment-38118
// @todo simpletest module patch
drupal_maintenance_theme();
// Add the specified modules to the list of modules in the default profile.
$args = func_get_args();
// $modules = array_unique(array_merge(drupal_get_profile_modules('default', 'en'), $args));
$modules = array_unique(array_merge(drupal_verify_profile($this->install_profile, $this->install_locale), $args));
// drupal_install_modules($modules, TRUE);
drupal_install_modules($modules);
// Because the schema is static cached, we need to flush
// it between each run. If we don't, then it will contain
// stale data for the previous run's database prefix and all
// calls to it will fail.
drupal_get_schema(NULL, TRUE);
if ($this->install_profile == 'openatrium') {
// Download and import translation if needed
if ($this->install_locale != 'en') {
$this->installLanguage($this->install_locale);
}
// Install more modules
$modules = _openatrium_atrium_modules();
drupal_install_modules($modules);
// Configure intranet
// $profile_tasks = $this->install_profile . '_profile_tasks';
_openatrium_intranet_configure();
_openatrium_intranet_configure_check();
variable_set('atrium_install', 1);
// Clear views cache before rebuilding menu tree. Requires patch
// [patch_here] to Views, as new modules have been included and
// default views need to be re-detected.
module_exists('views') ? views_get_all_views(TRUE) : TRUE;
menu_rebuild();
}
_drupal_flush_css_js();
$this->refreshVariables();
$this->checkPermissions(array(), TRUE);
user_access(NULL, NULL, TRUE);
// Drupal 6.
// Log in with a clean $user.
$this->originalUser = $user;
// drupal_save_session(FALSE);
// $user = user_load(1);
session_save_session(FALSE);
$user = user_load(array('uid' => 1));
// Restore necessary variables.
variable_set('install_profile', $this->install_profile);
variable_set('install_task', 'profile-finished');
variable_set('clean_url', $clean_url_original);
variable_set('site_mail', 'simpletest@example.com');
// Use temporary files directory with the same prefix as database.
$this->originalFileDirectory = file_directory_path();
variable_set('file_directory_path', file_directory_path() . '/' . $db_prefix);
$directory = file_directory_path();
// Create the files directory.
file_check_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
set_time_limit($this->timeLimit);
}
示例7: install_finished
/**
* Installation task; perform final steps and display a 'finished' page.
*
* @param $install_state
* An array of information about the current installation state.
* @return
* A message informing the user that the installation is complete.
*/
function install_finished(&$install_state)
{
drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_name())));
$messages = drupal_set_message();
$output = '<p>' . st('Congratulations, @drupal has been successfully installed.', array('@drupal' => drupal_install_profile_name())) . '</p>';
$output .= '<p>' . (isset($messages['error']) ? st('Please review the messages above before continuing on to <a href="@url">your new site</a>.', array('@url' => url(''))) : st('You may now visit <a href="@url">your new site</a>.', array('@url' => url('')))) . '</p>';
if (module_exists('help')) {
$output .= '<p>' . st('For more information on configuring Drupal, please refer to the <a href="@help">help section</a>.', array('@help' => url('admin/help'))) . '</p>';
}
// Rebuild menu and registry to get content type links registered by the
// profile, and possibly any other menu items created through the tasks.
menu_rebuild();
// Register actions declared by any modules.
actions_synchronize();
// Randomize query-strings on css/js files, to hide the fact that this is a
// new install, not upgraded yet.
_drupal_flush_css_js();
// Remember the profile which was used.
variable_set('install_profile', $install_state['parameters']['profile']);
// Cache a fully-built schema.
drupal_get_schema(NULL, TRUE);
// Run cron to populate update status tables (if available) so that users
// will be warned if they've installed an out of date Drupal version.
// Will also trigger indexing of profile-supplied content or feeds.
drupal_cron_run();
return $output;
}
示例8: install
//.........这里部分代码省略.........
$module_filenames = array();
foreach ($current_modules as $name => $weight) {
if (isset($current_module_filenames[$name])) {
$module_filenames[$name] = $current_module_filenames[$name];
} else {
$module_path = drupal_get_path('module', $name);
$pathname = "{$module_path}/{$name}.info.yml";
$filename = file_exists($module_path . "/{$name}.module") ? "{$name}.module" : NULL;
$module_filenames[$name] = new Extension('module', $pathname, $filename);
}
}
// Update the module handler in order to load the module's code.
// This allows the module to participate in hooks and its existence to
// be discovered by other modules.
// The current ModuleHandler instance is obsolete with the kernel
// rebuild below.
$this->setModuleList($module_filenames);
$this->load($module);
module_load_install($module);
// Clear the static cache of system_rebuild_module_data() to pick up the
// new module, since it merges the installation status of modules into
// its statically cached list.
drupal_static_reset('system_rebuild_module_data');
// Update the kernel to include it.
// This reboots the kernel to register the module's bundle and its
// services in the service container. The $module_filenames argument is
// taken over as %container.modules% parameter, which is passed to a
// fresh ModuleHandler instance upon first retrieval.
// @todo install_begin_request() creates a container without a kernel.
if ($kernel = \Drupal::service('kernel', ContainerInterface::NULL_ON_INVALID_REFERENCE)) {
$kernel->updateModules($module_filenames, $module_filenames);
}
// Refresh the schema to include it.
drupal_get_schema(NULL, TRUE);
// Allow modules to react prior to the installation of a module.
$this->invokeAll('module_preinstall', array($module));
// Now install the module's schema if necessary.
drupal_install_schema($module);
// Clear plugin manager caches and flag router to rebuild if requested.
\Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions();
\Drupal::service('router.builder_indicator')->setRebuildNeeded();
// Set the schema version to the number of the last update provided by
// the module, or the minimum core schema version.
$version = \Drupal::CORE_MINIMUM_SCHEMA_VERSION;
$versions = drupal_get_schema_versions($module);
if ($versions) {
$version = max(max($versions), $version);
}
// Notify the entity manager that this module's entity types are new,
// so that it can notify all interested handlers. For example, a
// SQL-based storage handler can use this as an opportunity to create
// the necessary database tables.
$entity_manager = \Drupal::entityManager();
foreach ($entity_manager->getDefinitions() as $entity_type) {
if ($entity_type->getProvider() == $module) {
$entity_manager->onEntityTypeCreate($entity_type);
}
}
// Install default configuration of the module.
$config_installer = \Drupal::service('config.installer');
if ($sync_status) {
$config_installer->setSyncing(TRUE)->setSourceStorage($source_storage);
} else {
// If we're not in a config synchronisation reset the source storage
// so that the extension install storage will pick up the new
// configuration.
示例9: hook_field_storage_delete_field
/**
* Act on deletion of a field.
*
* This hook is invoked from field_delete_field() to ask the field storage
* module to mark all information stored in the field for deletion.
*
* @param $field
* The field being deleted.
*/
function hook_field_storage_delete_field($field)
{
// Mark all data associated with the field for deletion.
$field['deleted'] = 0;
$table = _field_sql_storage_tablename($field);
$revision_table = _field_sql_storage_revision_tablename($field);
db_update($table)->fields(array('deleted' => 1))->execute();
// Move the table to a unique name while the table contents are being deleted.
$field['deleted'] = 1;
$new_table = _field_sql_storage_tablename($field);
$revision_new_table = _field_sql_storage_revision_tablename($field);
db_rename_table($table, $new_table);
db_rename_table($revision_table, $revision_new_table);
drupal_get_schema(NULL, TRUE);
}
示例10: setUpInstall
protected function setUpInstall()
{
global $db_prefix;
// Store new database prefix.
$db_prefix_new = $db_prefix;
$db_prefix = $this->originalPrefix;
// 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 . '}');
}
// Return to new prefix before performing cloning.
$db_prefix = $db_prefix_new;
// Clone each table into the new database.
foreach ($schemas as $name => $schema) {
$this->cloneTable($name, $sources[$name], $schema);
}
}
示例11: installSchema
/**
* Installs a specific table from a module schema definition.
*
* @param string $module
* The name of the module that defines the table's schema.
* @param string|array $tables
* The name or an array of the names of the tables to install.
*
* @throws \RuntimeException
* Thrown when $module is not enabled or when the table schema cannot be
* found in the module specified.
*/
protected function installSchema($module, $tables)
{
// drupal_get_schema_unprocessed() is technically able to install a schema
// of a non-enabled module, but its ability to load the module's .install
// file depends on many other factors. To prevent differences in test
// behavior and non-reproducible test failures, we only allow the schema of
// explicitly loaded/enabled modules to be installed.
if (!$this->container->get('module_handler')->moduleExists($module)) {
throw new \RuntimeException(format_string("'@module' module is not enabled.", array('@module' => $module)));
}
$tables = (array) $tables;
foreach ($tables as $table) {
$schema = drupal_get_schema_unprocessed($module, $table);
if (empty($schema)) {
throw new \RuntimeException(format_string("Unknown '@table' table schema in '@module' module.", array('@module' => $module, '@table' => $table)));
}
$this->container->get('database')->schema()->createTable($table, $schema);
}
// We need to refresh the schema cache, as any call to drupal_get_schema()
// would not know of/return the schema otherwise.
// @todo Refactor Schema API to make this obsolete.
drupal_get_schema(NULL, TRUE);
$this->pass(format_string('Installed %module tables: %tables.', array('%tables' => '{' . implode('}, {', $tables) . '}', '%module' => $module)));
}
示例12: tearDown
/**
* Delete created files and temporary files directory, delete the tables created by setUp(),
* and reset the database prefix.
*/
protected function tearDown()
{
global $db_prefix, $user;
if (preg_match('/simpletest\\d+/', $db_prefix)) {
// Delete temporary files directory and reset files directory path.
file_unmanaged_delete_recursive(file_directory_path());
variable_set('file_directory_path', $this->originalFileDirectory);
// Remove all prefixed tables (all the tables in the schema).
$schema = drupal_get_schema(NULL, TRUE);
$ret = array();
foreach ($schema as $name => $table) {
db_drop_table($ret, $name);
}
// Return the database prefix to the original.
$db_prefix = $this->originalPrefix;
// Return the user to the original one.
$user = $this->originalUser;
drupal_save_session(TRUE);
// Ensure that internal logged in variable and cURL options are reset.
$this->loggedInUser = FALSE;
$this->additionalCurlOptions = array();
// Reload module list and implementations to ensure that test module hooks
// aren't called after tests.
module_list(TRUE);
module_implements(MODULE_IMPLEMENTS_CLEAR_CACHE);
// Reset the Field API.
field_cache_clear();
// Rebuild caches.
$this->refreshVariables();
// Close the CURL handler.
$this->curlClose();
}
}
示例13: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$form['#title'] = $this->t('Configure site');
// Warn about settings.php permissions risk
$settings_dir = conf_path();
$settings_file = $settings_dir . '/settings.php';
// Check that $_POST is empty so we only show this message when the form is
// first displayed, not on the next page after it is submitted. (We do not
// want to repeat it multiple times because it is a general warning that is
// not related to the rest of the installation process; it would also be
// especially out of place on the last page of the installer, where it would
// distract from the message that the Drupal installation has completed
// successfully.)
$post_params = $this->getRequest()->request->all();
if (empty($post_params) && (!drupal_verify_install_file($this->root . '/' . $settings_file, FILE_EXIST | FILE_READABLE | FILE_NOT_WRITABLE) || !drupal_verify_install_file($this->root . '/' . $settings_dir, FILE_NOT_WRITABLE, 'dir'))) {
drupal_set_message(t('All necessary changes to %dir and %file have been made, so you should remove write permissions to them now in order to avoid security risks. If you are unsure how to do so, consult the <a href="@handbook_url">online handbook</a>.', array('%dir' => $settings_dir, '%file' => $settings_file, '@handbook_url' => 'http://drupal.org/server-permissions')), 'warning');
}
$form['#attached']['library'][] = 'system/drupal.system';
// Add JavaScript time zone detection.
$form['#attached']['library'][] = 'core/drupal.timezone';
// We add these strings as settings because JavaScript translation does not
// work during installation.
$form['#attached']['drupalSettings']['copyFieldValue']['edit-site-mail'] = ['edit-account-mail'];
// Cache a fully-built schema. This is necessary for any invocation of
// index.php because: (1) setting cache table entries requires schema
// information, (2) that occurs during bootstrap before any module are
// loaded, so (3) if there is no cached schema, drupal_get_schema() will
// try to generate one but with no loaded modules will return nothing.
//
// @todo Move this to the 'install_finished' task?
drupal_get_schema(NULL, TRUE);
$form['site_information'] = array('#type' => 'fieldgroup', '#title' => $this->t('Site information'));
$form['site_information']['site_name'] = array('#type' => 'textfield', '#title' => $this->t('Site name'), '#required' => TRUE, '#weight' => -20);
$form['site_information']['site_mail'] = array('#type' => 'email', '#title' => $this->t('Site email address'), '#default_value' => ini_get('sendmail_from'), '#description' => $this->t("Automated emails, such as registration information, will be sent from this address. Use an address ending in your site's domain to help prevent these emails from being flagged as spam."), '#required' => TRUE, '#weight' => -15);
$form['admin_account'] = array('#type' => 'fieldgroup', '#title' => $this->t('Site maintenance account'));
$form['admin_account']['account']['name'] = array('#type' => 'textfield', '#title' => $this->t('Username'), '#maxlength' => USERNAME_MAX_LENGTH, '#description' => $this->t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.'), '#required' => TRUE, '#attributes' => array('class' => array('username')));
$form['admin_account']['account']['pass'] = array('#type' => 'password_confirm', '#required' => TRUE, '#size' => 25);
$form['admin_account']['account']['#tree'] = TRUE;
$form['admin_account']['account']['mail'] = array('#type' => 'email', '#title' => $this->t('Email address'), '#required' => TRUE);
$form['regional_settings'] = array('#type' => 'fieldgroup', '#title' => $this->t('Regional settings'));
$countries = $this->countryManager->getList();
$form['regional_settings']['site_default_country'] = array('#type' => 'select', '#title' => $this->t('Default country'), '#empty_value' => '', '#default_value' => $this->config('system.date')->get('country.default'), '#options' => $countries, '#description' => $this->t('Select the default country for the site.'), '#weight' => 0);
$form['regional_settings']['date_default_timezone'] = array('#type' => 'select', '#title' => $this->t('Default time zone'), '#default_value' => date_default_timezone_get(), '#options' => system_time_zones(), '#description' => $this->t('By default, dates in this site will be displayed in the chosen time zone.'), '#weight' => 5, '#attributes' => array('class' => array('timezone-detect')));
$form['update_notifications'] = array('#type' => 'fieldgroup', '#title' => $this->t('Update notifications'));
$form['update_notifications']['update_status_module'] = array('#type' => 'checkboxes', '#title' => $this->t('Update notifications'), '#options' => array(1 => $this->t('Check for updates automatically'), 2 => $this->t('Receive email notifications')), '#default_value' => array(1, 2), '#description' => $this->t('The system will notify you when updates and important security releases are available for installed components. Anonymous information about your site is sent to <a href="@drupal">Drupal.org</a>.', array('@drupal' => 'http://drupal.org')), '#weight' => 15);
$form['update_notifications']['update_status_module'][2] = array('#states' => array('visible' => array('input[name="update_status_module[1]"]' => array('checked' => TRUE))));
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save and continue'), '#weight' => 15, '#button_type' => 'primary');
return $form;
}
示例14: tearDown
/**
* Delete created files and temporary files directory, delete the tables created by setUp(),
* and reset the database prefix.
*/
protected function tearDown()
{
global $db_prefix, $user, $language;
$emailCount = count(variable_get('simpletest_emails', array()));
if ($emailCount) {
$message = format_plural($emailCount, t('!count e-mail was sent during this test.'), t('!count e-mails were sent during this test.'), array('!count' => $emailCount));
$this->pass($message, t('E-mail'));
}
if (preg_match('/simpletest\\d+/', $db_prefix)) {
// Delete temporary files directory and reset files directory path.
file_unmanaged_delete_recursive(file_directory_path());
variable_set('file_directory_path', $this->originalFileDirectory);
// Remove all prefixed tables (all the tables in the schema).
$schema = drupal_get_schema(NULL, TRUE);
$ret = array();
foreach ($schema as $name => $table) {
db_drop_table($ret, $name);
}
// Return the database prefix to the original.
$db_prefix = $this->originalPrefix;
// Return the user to the original one.
$user = $this->originalUser;
drupal_save_session(TRUE);
// Ensure that internal logged in variable and cURL options are reset.
$this->loggedInUser = FALSE;
$this->additionalCurlOptions = array();
// Reload module list and implementations to ensure that test module hooks
// aren't called after tests.
module_list(TRUE);
module_implements(MODULE_IMPLEMENTS_CLEAR_CACHE);
// Reset the Field API.
field_cache_clear();
// Rebuild caches.
$this->refreshVariables();
// Reset language.
$language = $this->originalLanguage;
if ($this->originalLanguageDefault) {
$GLOBALS['conf']['language_default'] = $this->originalLanguageDefault;
}
// Close the CURL handler.
$this->curlClose();
}
}
示例15: setUp
/**
* 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;
}