Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function __construct($environment, $class_loader, $allow_dumping = TRUE)
 {
     // Include our bootstrap file.
     require_once __DIR__ . '/../../../../includes/bootstrap.inc';
     // Exit if we should be in a test environment but aren't.
     if (!drupal_valid_test_ua()) {
         header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
         exit;
     }
     parent::__construct($environment, $class_loader, $allow_dumping);
 }
 /**
  * {@inheritdoc}
  */
 public static function createFromRequest(Request $request, ClassLoader $class_loader, $environment, $allow_dumping = TRUE)
 {
     // Include our bootstrap file.
     require_once __DIR__ . '/../../../../includes/bootstrap.inc';
     // Exit if we should be in a test environment but aren't.
     if (!drupal_valid_test_ua()) {
         header($request->server->get('SERVER_PROTOCOL') . ' 403 Forbidden');
         exit;
     }
     return parent::createFromRequest($request, $class_loader, $environment, $allow_dumping);
 }
 /**
  * Event callback for the 'before' event
  */
 public function onBeforeSendRequest(BeforeEvent $event)
 {
     // If the database prefix is being used by SimpleTest to run the tests in a copied
     // database then set the user-agent header to the database prefix so that any
     // calls to other Drupal pages will run the SimpleTest prefixed database. The
     // user-agent is used to ensure that multiple testing sessions running at the
     // same time won't interfere with each other as they would if the database
     // prefix were stored statically in a file or database variable.
     if ($test_prefix = drupal_valid_test_ua()) {
         $event->getRequest()->setHeader('User-Agent', drupal_generate_test_ua($test_prefix));
     }
 }
 /**
  * {@inheritdoc}
  *
  * HTTP middleware that replaces the user agent for simpletest requests.
  */
 public function __invoke()
 {
     // If the database prefix is being used by SimpleTest to run the tests in a copied
     // database then set the user-agent header to the database prefix so that any
     // calls to other Drupal pages will run the SimpleTest prefixed database. The
     // user-agent is used to ensure that multiple testing sessions running at the
     // same time won't interfere with each other as they would if the database
     // prefix were stored statically in a file or database variable.
     return function ($handler) {
         return function (RequestInterface $request, array $options) use($handler) {
             if ($test_prefix = drupal_valid_test_ua()) {
                 $request = $request->withHeader('User-Agent', drupal_generate_test_ua($test_prefix));
             }
             return $handler($request, $options);
         };
     };
 }
Beispiel #5
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $install_state = NULL)
 {
     $form['#title'] = $this->t('Select an installation profile');
     $profiles = array();
     $names = array();
     foreach ($install_state['profiles'] as $profile) {
         /** @var $profile \Drupal\Core\Extension\Extension */
         $details = install_profile_info($profile->getName());
         // Don't show hidden profiles. This is used by to hide the testing profile,
         // which only exists to speed up test runs.
         if ($details['hidden'] === TRUE && !drupal_valid_test_ua()) {
             continue;
         }
         $profiles[$profile->getName()] = $details;
         // Determine the name of the profile; default to file name if defined name
         // is unspecified.
         $name = isset($details['name']) ? $details['name'] : $profile->getName();
         $names[$profile->getName()] = $name;
     }
     // Display radio buttons alphabetically by human-readable name, but always
     // put the core profiles first (if they are present in the filesystem).
     natcasesort($names);
     if (isset($names['minimal'])) {
         // If the expert ("Minimal") core profile is present, put it in front of
         // any non-core profiles rather than including it with them alphabetically,
         // since the other profiles might be intended to group together in a
         // particular way.
         $names = array('minimal' => $names['minimal']) + $names;
     }
     if (isset($names['standard'])) {
         // If the default ("Standard") core profile is present, put it at the very
         // top of the list. This profile will have its radio button pre-selected,
         // so we want it to always appear at the top.
         $names = array('standard' => $names['standard']) + $names;
     }
     // The profile name and description are extracted for translation from the
     // .info file, so we can use $this->t() on them even though they are dynamic
     // data at this point.
     $form['profile'] = array('#type' => 'radios', '#title' => $this->t('Select an installation profile'), '#title_display' => 'invisible', '#options' => array_map(array($this, 't'), $names), '#default_value' => 'standard');
     foreach (array_keys($names) as $profile_name) {
         $form['profile'][$profile_name]['#description'] = isset($profiles[$profile_name]['description']) ? $this->t($profiles[$profile_name]['description']) : '';
     }
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save and continue'), '#button_type' => 'primary');
     return $form;
 }
 /**
  * {@inheritdoc}
  *
  * HTTP middleware that replaces the user agent for simpletest requests.
  */
 public function __invoke()
 {
     // If the database prefix is being used by SimpleTest to run the tests in a copied
     // database then set the user-agent header to the database prefix so that any
     // calls to other Drupal pages will run the SimpleTest prefixed database. The
     // user-agent is used to ensure that multiple testing sessions running at the
     // same time won't interfere with each other as they would if the database
     // prefix were stored statically in a file or database variable.
     return function ($handler) {
         return function (RequestInterface $request, array $options) use($handler) {
             if ($test_prefix = drupal_valid_test_ua()) {
                 $request = $request->withHeader('User-Agent', drupal_generate_test_ua($test_prefix));
             }
             return $handler($request, $options)->then(function (ResponseInterface $response) use($request) {
                 if (!drupal_valid_test_ua()) {
                     return $response;
                 }
                 $headers = $response->getHeaders();
                 foreach ($headers as $header_name => $header_values) {
                     if (preg_match('/^X-Drupal-Assertion-[0-9]+$/', $header_name, $matches)) {
                         foreach ($header_values as $header_value) {
                             // Call \Drupal\simpletest\WebTestBase::error() with the parameters from
                             // the header.
                             $parameters = unserialize(urldecode($header_value));
                             if (count($parameters) === 3) {
                                 throw new \Exception($parameters[1] . ': ' . $parameters[0] . "\n" . Error::formatBacktrace([$parameters[2]]));
                             } else {
                                 throw new \Exception('Error thrown with the wrong amount of parameters.');
                             }
                         }
                     }
                 }
                 return $response;
             });
         };
     };
 }
 public function testSettings()
 {
     // The user agent header is used to pass a database prefix in the request when
     // running tests. However, for security reasons, it is imperative that we
     // validate we ourselves made the request.
     if ($test_prefix = drupal_valid_test_ua()) {
         // Set the test run id for use in other parts of Drupal.
         $test_info =& $GLOBALS['drupal_test_info'];
         $test_info['test_run_id'] = $test_prefix;
         $test_info['in_child_site'] = TRUE;
         foreach ($GLOBALS['databases']['default'] as &$value) {
             // Extract the current default database prefix.
             if (!isset($value['prefix'])) {
                 $current_prefix = '';
             } elseif (is_array($value['prefix'])) {
                 $current_prefix = $value['prefix']['default'];
             } else {
                 $current_prefix = $value['prefix'];
             }
             // Remove the current database prefix and replace it by our own.
             $value['prefix'] = array('default' => $current_prefix . $test_prefix);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $local_cache = NULL;
     if ($form_state->getValue('project_url')) {
         $local_cache = update_manager_file_get($form_state->getValue('project_url'));
         if (!$local_cache) {
             drupal_set_message($this->t('Unable to retrieve Drupal project from %url.', array('%url' => $form_state->getValue('project_url'))), 'error');
             return;
         }
     } elseif ($_FILES['files']['name']['project_upload']) {
         $validators = array('file_validate_extensions' => array(archiver_get_extensions()));
         if (!($finfo = file_save_upload('project_upload', $validators, NULL, 0, FILE_EXISTS_REPLACE))) {
             // Failed to upload the file. file_save_upload() calls
             // drupal_set_message() on failure.
             return;
         }
         $local_cache = $finfo->getFileUri();
     }
     $directory = _update_manager_extract_directory();
     try {
         $archive = update_manager_archive_extract($local_cache, $directory);
     } catch (\Exception $e) {
         drupal_set_message($e->getMessage(), 'error');
         return;
     }
     $files = $archive->listContents();
     if (!$files) {
         drupal_set_message($this->t('Provided archive contains no files.'), 'error');
         return;
     }
     // Unfortunately, we can only use the directory name to determine the
     // project name. Some archivers list the first file as the directory (i.e.,
     // MODULE/) and others list an actual file (i.e., MODULE/README.TXT).
     $project = strtok($files[0], '/\\');
     $archive_errors = $this->moduleHandler->invokeAll('verify_update_archive', array($project, $local_cache, $directory));
     if (!empty($archive_errors)) {
         drupal_set_message(array_shift($archive_errors), 'error');
         // @todo: Fix me in D8: We need a way to set multiple errors on the same
         // form element and have all of them appear!
         if (!empty($archive_errors)) {
             foreach ($archive_errors as $error) {
                 drupal_set_message($error, 'error');
             }
         }
         return;
     }
     // Make sure the Updater registry is loaded.
     drupal_get_updaters();
     $project_location = $directory . '/' . $project;
     try {
         $updater = Updater::factory($project_location, $this->root);
     } catch (\Exception $e) {
         drupal_set_message($e->getMessage(), 'error');
         return;
     }
     try {
         $project_title = Updater::getProjectTitle($project_location);
     } catch (\Exception $e) {
         drupal_set_message($e->getMessage(), 'error');
         return;
     }
     if (!$project_title) {
         drupal_set_message($this->t('Unable to determine %project name.', array('%project' => $project)), 'error');
     }
     if ($updater->isInstalled()) {
         drupal_set_message($this->t('%project is already installed.', array('%project' => $project_title)), 'error');
         return;
     }
     $project_real_location = drupal_realpath($project_location);
     $arguments = array('project' => $project, 'updater_name' => get_class($updater), 'local_url' => $project_real_location);
     // This process is inherently difficult to test therefore use a state flag.
     $test_authorize = FALSE;
     if (drupal_valid_test_ua()) {
         $test_authorize = \Drupal::state()->get('test_uploaders_via_prompt', FALSE);
     }
     // If the owner of the directory we extracted is the same as the owner of
     // our configuration directory (e.g. sites/default) where we're trying to
     // install the code, there's no need to prompt for FTP/SSH credentials.
     // Instead, we instantiate a Drupal\Core\FileTransfer\Local and invoke
     // update_authorize_run_install() directly.
     if (fileowner($project_real_location) == fileowner($this->sitePath) && !$test_authorize) {
         $this->moduleHandler->loadInclude('update', 'inc', 'update.authorize');
         $filetransfer = new Local($this->root);
         $response = call_user_func_array('update_authorize_run_install', array_merge(array($filetransfer), $arguments));
         if ($response instanceof Response) {
             $form_state->setResponse($response);
         }
     } else {
         // The page title must be passed here to ensure it is initially used when
         // authorize.php loads for the first time with the FTP/SSH credentials
         // form.
         system_authorized_init('update_authorize_run_install', __DIR__ . '/../../update.authorize.inc', $arguments, $this->t('Update manager'));
         $form_state->setRedirectUrl(system_authorized_get_url());
     }
 }
 /**
  * Cleans up the test environment and restores the original environment.
  *
  * Deletes created files, database tables, and reverts environment changes.
  *
  * This method needs to be invoked for both unit and integration tests.
  *
  * @see TestBase::prepareDatabasePrefix()
  * @see TestBase::changeDatabasePrefix()
  * @see TestBase::prepareEnvironment()
  */
 private function restoreEnvironment()
 {
     // Destroy the session if one was started during the test-run.
     $_SESSION = array();
     if (PHP_SAPI !== 'cli' && session_status() === PHP_SESSION_ACTIVE) {
         session_destroy();
         $params = session_get_cookie_params();
         setcookie(session_name(), '', REQUEST_TIME - 3600, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
     }
     session_name($this->originalSessionName);
     // Reset all static variables.
     // Unsetting static variables will potentially invoke destruct methods,
     // which might call into functions that prime statics and caches again.
     // In that case, all functions are still operating on the test environment,
     // which means they may need to access its filesystem and database.
     drupal_static_reset();
     if ($this->container && $this->container->has('state') && ($state = $this->container->get('state'))) {
         $captured_emails = $state->get('system.test_mail_collector') ?: array();
         $emailCount = count($captured_emails);
         if ($emailCount) {
             $message = $emailCount == 1 ? '1 email was sent during this test.' : $emailCount . ' emails were sent during this test.';
             $this->pass($message, 'Email');
         }
     }
     // Sleep for 50ms to allow shutdown functions and terminate events to
     // complete. Further information: https://www.drupal.org/node/2194357.
     usleep(50000);
     // Remove all prefixed tables.
     $original_connection_info = Database::getConnectionInfo('simpletest_original_default');
     $original_prefix = $original_connection_info['default']['prefix']['default'];
     $test_connection_info = Database::getConnectionInfo('default');
     $test_prefix = $test_connection_info['default']['prefix']['default'];
     if ($original_prefix != $test_prefix) {
         $tables = Database::getConnection()->schema()->findTables('%');
         foreach ($tables as $table) {
             if (Database::getConnection()->schema()->dropTable($table)) {
                 unset($tables[$table]);
             }
         }
     }
     // In case a fatal error occurred that was not in the test process read the
     // log to pick up any fatal errors.
     simpletest_log_read($this->testId, $this->databasePrefix, get_class($this));
     // Restore original dependency injection container.
     $this->container = $this->originalContainer;
     \Drupal::setContainer($this->originalContainer);
     // Delete test site directory.
     file_unmanaged_delete_recursive($this->siteDirectory, array($this, 'filePreDeleteCallback'));
     // Restore original database connection.
     Database::removeConnection('default');
     Database::renameConnection('simpletest_original_default', 'default');
     // Reset all static variables.
     // All destructors of statically cached objects have been invoked above;
     // this second reset is guaranteed to reset everything to nothing.
     drupal_static_reset();
     // Restore original in-memory configuration.
     $GLOBALS['config'] = $this->originalConfig;
     $GLOBALS['conf'] = $this->originalConf;
     new Settings($this->originalSettings);
     // Restore original statics and globals.
     $GLOBALS['config_directories'] = $this->originalConfigDirectories;
     // Re-initialize original stream wrappers of the parent site.
     // This must happen after static variables have been reset and the original
     // container and $config_directories are restored, as simpletest_log_read()
     // uses the public stream wrapper to locate the error.log.
     $this->originalContainer->get('stream_wrapper_manager')->register();
     if (isset($this->originalPrefix)) {
         drupal_valid_test_ua($this->originalPrefix);
     } else {
         drupal_valid_test_ua(FALSE);
     }
     // Restore original shutdown callbacks.
     $callbacks =& drupal_register_shutdown_function();
     $callbacks = $this->originalShutdownCallbacks;
 }
Beispiel #10
0
 /**
  * Bootstraps a basic test environment.
  *
  * Should not be called by tests. Only visible for DrupalKernel integration
  * tests.
  *
  * @see \Drupal\system\Tests\DrupalKernel\DrupalKernelTest
  * @internal
  */
 protected function bootEnvironment()
 {
     $this->streamWrappers = array();
     \Drupal::unsetContainer();
     $this->classLoader = (require $this->root . '/autoload.php');
     require_once $this->root . '/core/includes/bootstrap.inc';
     // Set up virtual filesystem.
     // Ensure that the generated test site directory does not exist already,
     // which may happen with a large amount of concurrent threads and
     // long-running tests.
     do {
         $suffix = mt_rand(100000, 999999);
         $this->siteDirectory = 'sites/simpletest/' . $suffix;
         $this->databasePrefix = 'simpletest' . $suffix;
     } while (is_dir($this->root . '/' . $this->siteDirectory));
     $this->vfsRoot = vfsStream::setup('root', NULL, array('sites' => array('simpletest' => array($suffix => array()))));
     $this->siteDirectory = vfsStream::url('root/sites/simpletest/' . $suffix);
     mkdir($this->siteDirectory . '/files', 0775);
     mkdir($this->siteDirectory . '/files/config/' . CONFIG_SYNC_DIRECTORY, 0775, TRUE);
     // Ensure that all code that relies on drupal_valid_test_ua() can still be
     // safely executed. This primarily affects the (test) site directory
     // resolution (used by e.g. LocalStream and PhpStorage).
     $this->databasePrefix = 'simpletest' . $suffix;
     drupal_valid_test_ua($this->databasePrefix);
     $settings = array('hash_salt' => get_class($this), 'file_public_path' => $this->siteDirectory . '/files', 'twig_cache' => FALSE);
     new Settings($settings);
     $GLOBALS['config_directories'] = array(CONFIG_SYNC_DIRECTORY => $this->siteDirectory . '/files/config/sync');
     foreach (Database::getAllConnectionInfo() as $key => $targets) {
         Database::removeConnection($key);
     }
     Database::addConnectionInfo('default', 'default', $this->getDatabaseConnectionInfo()['default']);
 }
 /**
  * Wraps drupal_valid_test_ua().
  *
  * @return string|FALSE
  *   Either the simpletest prefix (the string "simpletest" followed by any
  *   number of digits) or FALSE if the user agent does not contain a valid
  *   HMAC and timestamp.
  */
 protected function drupalValidTestUa()
 {
     return drupal_valid_test_ua();
 }
Beispiel #12
0
 /**
  * Prepares the current environment for running the test.
  *
  * Also sets up new resources for the testing environment, such as the public
  * filesystem and configuration directories.
  *
  * This method is private as it must only be called once by
  * BrowserTestBase::setUp() (multiple invocations for the same test would have
  * unpredictable consequences) and it must not be callable or overridable by
  * test classes.
  */
 protected function prepareEnvironment()
 {
     // Bootstrap Drupal so we can use Drupal's built in functions.
     $this->classLoader = (require __DIR__ . '/../../../../autoload.php');
     $request = Request::createFromGlobals();
     $kernel = TestRunnerKernel::createFromRequest($request, $this->classLoader);
     // TestRunnerKernel expects the working directory to be DRUPAL_ROOT.
     chdir(DRUPAL_ROOT);
     $kernel->prepareLegacyRequest($request);
     $this->prepareDatabasePrefix();
     $this->originalSiteDirectory = $kernel->findSitePath($request);
     // Create test directory ahead of installation so fatal errors and debug
     // information can be logged during installation process.
     file_prepare_directory($this->siteDirectory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
     // Prepare filesystem directory paths.
     $this->publicFilesDirectory = $this->siteDirectory . '/files';
     $this->privateFilesDirectory = $this->siteDirectory . '/private';
     $this->tempFilesDirectory = $this->siteDirectory . '/temp';
     $this->translationFilesDirectory = $this->siteDirectory . '/translations';
     // Ensure the configImporter is refreshed for each test.
     $this->configImporter = NULL;
     // Unregister all custom stream wrappers of the parent site.
     $wrappers = \Drupal::service('stream_wrapper_manager')->getWrappers(StreamWrapperInterface::ALL);
     foreach ($wrappers as $scheme => $info) {
         stream_wrapper_unregister($scheme);
     }
     // Reset statics.
     drupal_static_reset();
     // Ensure there is no service container.
     $this->container = NULL;
     \Drupal::unsetContainer();
     // Unset globals.
     unset($GLOBALS['config_directories']);
     unset($GLOBALS['config']);
     unset($GLOBALS['conf']);
     // Log fatal errors.
     ini_set('log_errors', 1);
     ini_set('error_log', DRUPAL_ROOT . '/' . $this->siteDirectory . '/error.log');
     // Change the database prefix.
     $this->changeDatabasePrefix();
     // After preparing the environment and changing the database prefix, we are
     // in a valid test environment.
     drupal_valid_test_ua($this->databasePrefix);
     // Reset settings.
     new Settings(array('hash_salt' => $this->databasePrefix));
     drupal_set_time_limit($this->timeLimit);
 }
Beispiel #13
0
 /**
  * Setup a consistent PHP environment.
  *
  * This method sets PHP environment options we want to be sure are set
  * correctly for security or just saneness.
  *
  * @param string $app_root
  *   (optional) The path to the application root as a string. If not supplied,
  *   the application root will be computed.
  */
 public static function bootEnvironment($app_root = NULL)
 {
     if (static::$isEnvironmentInitialized) {
         return;
     }
     // Determine the application root if it's not supplied.
     if ($app_root === NULL) {
         $app_root = static::guessApplicationRoot();
     }
     // Include our bootstrap file.
     require_once $app_root . '/core/includes/bootstrap.inc';
     // Enforce E_STRICT, but allow users to set levels not part of E_STRICT.
     error_reporting(E_STRICT | E_ALL);
     // Override PHP settings required for Drupal to work properly.
     // sites/default/default.settings.php contains more runtime settings.
     // The .htaccess file contains settings that cannot be changed at runtime.
     // Use session cookies, not transparent sessions that puts the session id in
     // the query string.
     ini_set('session.use_cookies', '1');
     ini_set('session.use_only_cookies', '1');
     ini_set('session.use_trans_sid', '0');
     // Don't send HTTP headers using PHP's session handler.
     // Send an empty string to disable the cache limiter.
     ini_set('session.cache_limiter', '');
     // Use httponly session cookies.
     ini_set('session.cookie_httponly', '1');
     // Set sane locale settings, to ensure consistent string, dates, times and
     // numbers handling.
     setlocale(LC_ALL, 'C');
     // Detect string handling method.
     Unicode::check();
     // Indicate that code is operating in a test child site.
     if (!defined('DRUPAL_TEST_IN_CHILD_SITE')) {
         if ($test_prefix = drupal_valid_test_ua()) {
             $test_db = new TestDatabase($test_prefix);
             // Only code that interfaces directly with tests should rely on this
             // constant; e.g., the error/exception handler conditionally adds further
             // error information into HTTP response headers that are consumed by
             // Simpletest's internal browser.
             define('DRUPAL_TEST_IN_CHILD_SITE', TRUE);
             // Web tests are to be conducted with runtime assertions active.
             assert_options(ASSERT_ACTIVE, TRUE);
             // Now synchronize PHP 5 and 7's handling of assertions as much as
             // possible.
             Handle::register();
             // Log fatal errors to the test site directory.
             ini_set('log_errors', 1);
             ini_set('error_log', $app_root . '/' . $test_db->getTestSitePath() . '/error.log');
             // Ensure that a rewritten settings.php is used if opcache is on.
             ini_set('opcache.validate_timestamps', 'on');
             ini_set('opcache.revalidate_freq', 0);
         } else {
             // Ensure that no other code defines this.
             define('DRUPAL_TEST_IN_CHILD_SITE', FALSE);
         }
     }
     // Set the Drupal custom error handler.
     set_error_handler('_drupal_error_handler');
     set_exception_handler('_drupal_exception_handler');
     static::$isEnvironmentInitialized = TRUE;
 }
Beispiel #14
0
 /**
  * Bootstraps a basic test environment.
  *
  * Should not be called by tests. Only visible for DrupalKernel integration
  * tests.
  *
  * @see \Drupal\system\Tests\DrupalKernel\DrupalKernelTest
  * @internal
  */
 protected function bootEnvironment()
 {
     $this->streamWrappers = array();
     \Drupal::unsetContainer();
     $this->classLoader = (require $this->root . '/autoload.php');
     require_once $this->root . '/core/includes/bootstrap.inc';
     // Set up virtual filesystem.
     Database::addConnectionInfo('default', 'test-runner', $this->getDatabaseConnectionInfo()['default']);
     $test_db = new TestDatabase();
     $this->siteDirectory = $test_db->getTestSitePath();
     // Ensure that all code that relies on drupal_valid_test_ua() can still be
     // safely executed. This primarily affects the (test) site directory
     // resolution (used by e.g. LocalStream and PhpStorage).
     $this->databasePrefix = $test_db->getDatabasePrefix();
     drupal_valid_test_ua($this->databasePrefix);
     $settings = array('hash_salt' => get_class($this), 'file_public_path' => $this->siteDirectory . '/files', 'twig_cache' => FALSE);
     new Settings($settings);
     $this->setUpFilesystem();
     foreach (Database::getAllConnectionInfo() as $key => $targets) {
         Database::removeConnection($key);
     }
     Database::addConnectionInfo('default', 'default', $this->getDatabaseConnectionInfo()['default']);
 }
Beispiel #15
0
<?php

/**
 * @file
 * Fake an HTTPS request, for use during testing.
 */
// Set a global variable to indicate a mock HTTPS request.
$is_https_mock = empty($_SERVER['HTTPS']);
// Change to HTTPS.
$_SERVER['HTTPS'] = 'on';
foreach ($_SERVER as $key => $value) {
    $_SERVER[$key] = str_replace('modules/simpletest/tests/https.php', 'index.php', $value);
    $_SERVER[$key] = str_replace('http://', 'https://', $_SERVER[$key]);
}
// Change current directory to the Drupal root.
chdir('../../..');
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
// Make sure this file can only be used by simpletest.
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
if (!drupal_valid_test_ua()) {
    header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
    exit;
}
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
menu_execute_active_handler();
Beispiel #16
0
 /**
  * Setup a consistent PHP environment.
  *
  * This method sets PHP environment options we want to be sure are set
  * correctly for security or just saneness.
  */
 public static function bootEnvironment()
 {
     if (static::$isEnvironmentInitialized) {
         return;
     }
     // Enforce E_STRICT, but allow users to set levels not part of E_STRICT.
     error_reporting(E_STRICT | E_ALL);
     // Override PHP settings required for Drupal to work properly.
     // sites/default/default.settings.php contains more runtime settings.
     // The .htaccess file contains settings that cannot be changed at runtime.
     // Use session cookies, not transparent sessions that puts the session id in
     // the query string.
     ini_set('session.use_cookies', '1');
     ini_set('session.use_only_cookies', '1');
     ini_set('session.use_trans_sid', '0');
     // Don't send HTTP headers using PHP's session handler.
     // Send an empty string to disable the cache limiter.
     ini_set('session.cache_limiter', '');
     // Use httponly session cookies.
     ini_set('session.cookie_httponly', '1');
     // Set sane locale settings, to ensure consistent string, dates, times and
     // numbers handling.
     setlocale(LC_ALL, 'C');
     // Detect string handling method.
     Unicode::check();
     // Indicate that code is operating in a test child site.
     if (!defined('DRUPAL_TEST_IN_CHILD_SITE')) {
         if ($test_prefix = drupal_valid_test_ua()) {
             // Only code that interfaces directly with tests should rely on this
             // constant; e.g., the error/exception handler conditionally adds further
             // error information into HTTP response headers that are consumed by
             // Simpletest's internal browser.
             define('DRUPAL_TEST_IN_CHILD_SITE', TRUE);
             // Log fatal errors to the test site directory.
             ini_set('log_errors', 1);
             ini_set('error_log', DRUPAL_ROOT . '/sites/simpletest/' . substr($test_prefix, 10) . '/error.log');
         } else {
             // Ensure that no other code defines this.
             define('DRUPAL_TEST_IN_CHILD_SITE', FALSE);
         }
     }
     // Set the Drupal custom error handler.
     set_error_handler('_drupal_error_handler');
     set_exception_handler('_drupal_exception_handler');
     static::$isEnvironmentInitialized = TRUE;
 }
 /**
  * Registers services and event subscribers for a site under test.
  */
 protected function registerTest(ContainerBuilder $container)
 {
     // Do nothing if we are not in a test environment.
     if (!drupal_valid_test_ua()) {
         return;
     }
     // Add the HTTP request subscriber to Guzzle.
     $container->register('test.http_client.request_subscriber', 'Drupal\\Core\\Test\\EventSubscriber\\HttpRequestSubscriber')->addTag('http_client_subscriber');
 }
 /**
  * Sets installation profile directories based on current site settings.
  *
  * @return $this
  */
 public function setProfileDirectoriesFromSettings()
 {
     $this->profileDirectories = array();
     $profile = drupal_get_profile();
     // For SimpleTest to be able to test modules packaged together with a
     // distribution we need to include the profile of the parent site (in
     // which test runs are triggered).
     if (drupal_valid_test_ua() && !drupal_installation_attempted()) {
         $testing_profile = \Drupal::config('simpletest.settings')->get('parent_profile');
         if ($testing_profile && $testing_profile != $profile) {
             $this->profileDirectories[] = drupal_get_path('profile', $testing_profile);
         }
     }
     // In case both profile directories contain the same extension, the actual
     // profile always has precedence.
     if ($profile) {
         $this->profileDirectories[] = drupal_get_path('profile', $profile);
     }
     return $this;
 }
 /**
  * Registers services and event subscribers for a site under test.
  */
 protected function registerTest(ContainerBuilder $container)
 {
     // Do nothing if we are not in a test environment.
     if (!drupal_valid_test_ua()) {
         return;
     }
     // Add the HTTP request middleware to Guzzle.
     $container->register('test.http_client.middleware', 'Drupal\\Core\\Test\\HttpClientMiddleware\\TestHttpClientMiddleware')->addTag('http_client_middleware');
 }