예제 #1
0
 /**
  * @return \Drupal\Core\DrupalKernel
  */
 public function getKernel()
 {
     if (!$this->kernel) {
         $this->request = Request::createFromGlobals();
         $this->kernel = DrupalKernel::createFromRequest($this->request, $this->class_loader, $this->environment);
     }
     return $this->kernel;
 }
예제 #2
0
파일: DrupalBoot8.php 프로젝트: nuwud/drush
 function bootstrap_drupal_configuration()
 {
     $this->request = Request::createFromGlobals();
     $classloader = drush_drupal_load_autoloader(DRUPAL_ROOT);
     $this->kernel = DrupalKernel::createFromRequest($this->request, $classloader, 'prod');
     // Unset drupal error handler and restore drush's one.
     restore_error_handler();
     parent::bootstrap_drupal_configuration();
 }
예제 #3
0
 /**
  * {@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);
 }
예제 #4
0
 public function initialize(\Boris\Boris $boris, $dir)
 {
     parent::initialize($boris, $dir);
     $classloader = (require_once $dir . '/core/vendor/autoload.php');
     $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
     $kernel = \Drupal\Core\DrupalKernel::createFromRequest($request, $classloader, 'dev');
     $kernel->boot();
     $kernel->prepareLegacyRequest($request);
     \Drupal::getContainer()->set('request', $request);
     $boris->onStart(function ($worker, $vars) use($kernel) {
         $worker->setLocal('kernel', $kernel);
         $worker->setLocal('container', $kernel->getContainer());
     });
 }
예제 #5
0
 /**
  * Build a kernel for testings.
  *
  * Because the bootstrap is in DrupalKernel::boot and that involved loading
  * settings from the filesystem we need to go to extra lengths to build a kernel
  * for testing.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   A request object to use in booting the kernel.
  * @param array $modules_enabled
  *   A list of modules to enable on the kernel.
  * @param bool $read_only
  *   Build the kernel in a read only state.
  * @return DrupalKernel
  */
 protected function getTestKernel(Request $request, array $modules_enabled = NULL, $read_only = FALSE)
 {
     // Manually create kernel to avoid replacing settings.
     $kernel = DrupalKernel::createFromRequest($request, drupal_classloader(), 'testing');
     $this->settingsSet('hash_salt', $this->databasePrefix);
     if (isset($modules_enabled)) {
         $kernel->updateModules($modules_enabled);
     }
     $kernel->boot();
     if ($read_only) {
         $php_storage = Settings::get('php_storage');
         $php_storage['service_container']['class'] = 'Drupal\\Component\\PhpStorage\\FileReadOnlyStorage';
         $this->settingsSet('php_storage', $php_storage);
     }
     return $kernel;
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function bootstrap()
 {
     // Validate, and prepare environment for Drupal bootstrap.
     if (!defined('DRUPAL_ROOT')) {
         define('DRUPAL_ROOT', $this->drupalRoot);
     }
     // Bootstrap Drupal.
     chdir(DRUPAL_ROOT);
     $autoloader = (require DRUPAL_ROOT . '/autoload.php');
     require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
     $this->validateDrupalSite();
     $request = Request::createFromGlobals();
     $kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
     $kernel->boot();
     $kernel->prepareLegacyRequest($request);
     // Initialise an anonymous session. required for the bootstrap.
     \Drupal::service('session_manager')->start();
 }
예제 #7
0
 /**
  * Create a Drupal application.
  */
 public function getApplication()
 {
     // Bootstrap Drupal.
     // Bootstrap code is modeled on a few examples in core/scripts, such as
     // db-tools.php.
     // Assume we're in DRUPAL_ROOT/vendor/php-pm/httpkernel-adapter/Bootstraps.
     // There may be a safer way to do this...
     $drupal_root = dirname(dirname(dirname(dirname(__DIR__))));
     // @todo: Is it necessary to call bootEnv()?  It's called automatically by createFromRequest().
     DrupalKernel::bootEnvironment();
     $request = Request::createFromGlobals();
     // @todo: Is it necessary to call initialize()? Is it called through createFromRequest()?
     $autoloader = (include $drupal_root . '/autoload.php');
     Settings::initialize($drupal_root, DrupalKernel::findSitePath($request), $autoloader);
     $app = DrupalKernel::createFromRequest($request, $autoloader, $this->appenv);
     $app->boot();
     return $app;
 }
 /**
  * Overrides method.
  *
  * We have several forms to navigate through.
  */
 protected function setUpSite()
 {
     // Recreate the container so that we can simulate the submission of the
     // SyncConfigureForm after the full bootstrap has occurred. Without out this
     // drupal_realpath() does not work so uploading files through
     // WebTestBase::postForm() is impossible.
     $request = Request::createFromGlobals();
     $class_loader = (require $this->container->get('app.root') . '/vendor/autoload.php');
     Settings::initialize($this->container->get('app.root'), DrupalKernel::findSitePath($request), $class_loader);
     foreach ($GLOBALS['config_directories'] as $type => $path) {
         $this->configDirectories[$type] = $path;
     }
     $this->kernel = DrupalKernel::createFromRequest($request, $class_loader, 'prod', FALSE);
     $this->kernel->prepareLegacyRequest($request);
     $this->container = $this->kernel->getContainer();
     $this->setUpSyncForm();
     $this->setUpInstallConfigureForm();
     // If we've got to this point the site is installed using the regular
     // installation workflow.
     $this->isInstalled = TRUE;
 }
예제 #9
0
파일: WebTestBase.php 프로젝트: Wylbur/gj
 /**
  * Initializes the kernel after installation.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   Request object.
  *
  * @return \Symfony\Component\DependencyInjection\ContainerInterface
  *   The container.
  */
 protected function initKernel(Request $request)
 {
     $this->kernel = DrupalKernel::createFromRequest($request, $this->classLoader, 'prod', TRUE);
     $this->kernel->prepareLegacyRequest($request);
     // Force the container to be built from scratch instead of loaded from the
     // disk. This forces us to not accidentally load the parent site.
     return $this->kernel->rebuildContainer();
 }
 /**
  * Overrides WebTestBase::setUp().
  */
 protected function setUp()
 {
     $this->isInstalled = FALSE;
     // Define information about the user 1 account.
     $this->root_user = new UserSession(array('uid' => 1, 'name' => 'admin', 'mail' => '*****@*****.**', 'pass_raw' => $this->randomMachineName()));
     // If any $settings are defined for this test, copy and prepare an actual
     // settings.php, so as to resemble a regular installation.
     if (!empty($this->settings)) {
         // Not using File API; a potential error must trigger a PHP warning.
         copy(DRUPAL_ROOT . '/sites/default/default.settings.php', DRUPAL_ROOT . '/' . $this->siteDirectory . '/settings.php');
         $this->writeSettings($this->settings);
     }
     // Note that WebTestBase::installParameters() returns form input values
     // suitable for a programmed drupal_form_submit().
     // @see WebTestBase::translatePostValues()
     $this->parameters = $this->installParameters();
     // Set up a minimal container (required by WebTestBase).
     // @see install_begin_request()
     $request = Request::create($GLOBALS['base_url'] . '/core/install.php');
     $this->container = new ContainerBuilder();
     $request_stack = new RequestStack();
     $request_stack->push($request);
     $this->container->set('request_stack', $request_stack);
     $this->container->setParameter('language.default_values', Language::$defaultValues);
     $this->container->register('language.default', 'Drupal\\Core\\Language\\LanguageDefault')->addArgument('%language.default_values%');
     $this->container->register('language_manager', 'Drupal\\Core\\Language\\LanguageManager')->addArgument(new Reference('language.default'));
     $this->container->register('string_translation', 'Drupal\\Core\\StringTranslation\\TranslationManager')->addArgument(new Reference('language_manager'));
     \Drupal::setContainer($this->container);
     $this->drupalGet($GLOBALS['base_url'] . '/core/install.php');
     // Select language.
     $this->setUpLanguage();
     // Select profile.
     $this->setUpProfile();
     // Configure settings.
     $this->setUpSettings();
     // @todo Allow test classes based on this class to act on further installer
     //   screens.
     // Configure site.
     $this->setUpSite();
     // Import new settings.php written by the installer.
     $request = Request::createFromGlobals();
     $class_loader = (require DRUPAL_ROOT . '/core/vendor/autoload.php');
     Settings::initialize(DrupalKernel::findSitePath($request), $class_loader);
     foreach ($GLOBALS['config_directories'] as $type => $path) {
         $this->configDirectories[$type] = $path;
     }
     // After writing settings.php, the installer removes write permissions
     // from the site directory. To allow drupal_generate_test_ua() to write
     // a file containing the private key for drupal_valid_test_ua(), the site
     // directory has to be writable.
     // WebTestBase::tearDown() will delete the entire test site directory.
     // Not using File API; a potential error must trigger a PHP warning.
     chmod(DRUPAL_ROOT . '/' . $this->siteDirectory, 0777);
     $this->kernel = DrupalKernel::createFromRequest($request, $class_loader, 'prod', FALSE);
     $this->kernel->prepareLegacyRequest($request);
     $this->container = $this->kernel->getContainer();
     $config = $this->container->get('config.factory');
     // Manually configure the test mail collector implementation to prevent
     // tests from sending out e-mails and collect them in state instead.
     $config->get('system.mail')->set('interface.default', 'test_mail_collector')->save();
     // When running from run-tests.sh we don't get an empty current path which
     // would indicate we're on the home page.
     $path = current_path();
     if (empty($path)) {
         _current_path('run-tests');
     }
     $this->isInstalled = TRUE;
 }
예제 #11
0
 /**
  * Installs Drupal into the Simpletest site.
  */
 public function installDrupal()
 {
     // Define information about the user 1 account.
     $this->rootUser = new UserSession(array('uid' => 1, 'name' => 'admin', 'mail' => '*****@*****.**', 'passRaw' => $this->randomMachineName()));
     // The child site derives its session name from the database prefix when
     // running web tests.
     $this->generateSessionName($this->databasePrefix);
     // Get parameters for install_drupal() before removing global variables.
     $parameters = $this->installParameters();
     // Prepare installer settings that are not install_drupal() parameters.
     // Copy and prepare an actual settings.php, so as to resemble a regular
     // installation.
     // Not using File API; a potential error must trigger a PHP warning.
     $directory = DRUPAL_ROOT . '/' . $this->siteDirectory;
     copy(DRUPAL_ROOT . '/sites/default/default.settings.php', $directory . '/settings.php');
     // All file system paths are created by System module during installation.
     // @see system_requirements()
     // @see TestBase::prepareEnvironment()
     $settings['settings']['file_public_path'] = (object) array('value' => $this->publicFilesDirectory, 'required' => TRUE);
     $this->writeSettings($settings);
     // Allow for test-specific overrides.
     $settings_testing_file = DRUPAL_ROOT . '/' . $this->originalSiteDirectory . '/settings.testing.php';
     if (file_exists($settings_testing_file)) {
         // Copy the testing-specific settings.php overrides in place.
         copy($settings_testing_file, $directory . '/settings.testing.php');
         // Add the name of the testing class to settings.php and include the
         // testing specific overrides.
         file_put_contents($directory . '/settings.php', "\n\$test_class = '" . get_class($this) . "';\n" . 'include DRUPAL_ROOT . \'/\' . $site_path . \'/settings.testing.php\';' . "\n", FILE_APPEND);
     }
     $settings_services_file = DRUPAL_ROOT . '/' . $this->originalSiteDirectory . '/testing.services.yml';
     if (file_exists($settings_services_file)) {
         // Copy the testing-specific service overrides in place.
         copy($settings_services_file, $directory . '/services.yml');
     }
     // Since Drupal is bootstrapped already, install_begin_request() will not
     // bootstrap into DRUPAL_BOOTSTRAP_CONFIGURATION (again). Hence, we have to
     // reload the newly written custom settings.php manually.
     Settings::initialize(DRUPAL_ROOT, $directory, $this->classLoader);
     // Execute the non-interactive installer.
     require_once DRUPAL_ROOT . '/core/includes/install.core.inc';
     install_drupal($parameters);
     // Import new settings.php written by the installer.
     Settings::initialize(DRUPAL_ROOT, $directory, $this->classLoader);
     foreach ($GLOBALS['config_directories'] as $type => $path) {
         $this->configDirectories[$type] = $path;
     }
     // After writing settings.php, the installer removes write permissions from
     // the site directory. To allow drupal_generate_test_ua() to write a file
     // containing the private key for drupal_valid_test_ua(), the site directory
     // has to be writable.
     // TestBase::restoreEnvironment() will delete the entire site directory. Not
     // using File API; a potential error must trigger a PHP warning.
     chmod($directory, 0777);
     $request = \Drupal::request();
     $this->kernel = DrupalKernel::createFromRequest($request, $this->classLoader, 'prod', TRUE);
     $this->kernel->prepareLegacyRequest($request);
     // Force the container to be built from scratch instead of loaded from the
     // disk. This forces us to not accidentally load the parent site.
     $container = $this->kernel->rebuildContainer();
     $config = $container->get('config.factory');
     // Manually create and configure private and temporary files directories.
     // While these could be preset/enforced in settings.php like the public
     // files directory above, some tests expect them to be configurable in the
     // UI. If declared in settings.php, they would no longer be configurable.
     file_prepare_directory($this->privateFilesDirectory, FILE_CREATE_DIRECTORY);
     file_prepare_directory($this->tempFilesDirectory, FILE_CREATE_DIRECTORY);
     $config->getEditable('system.file')->set('path.private', $this->privateFilesDirectory)->set('path.temporary', $this->tempFilesDirectory)->save();
     // Manually configure the test mail collector implementation to prevent
     // tests from sending out emails and collect them in state instead.
     // While this should be enforced via settings.php prior to installation,
     // some tests expect to be able to test mail system implementations.
     $config->getEditable('system.mail')->set('interface.default', 'test_mail_collector')->save();
     // By default, verbosely display all errors and disable all production
     // environment optimizations for all tests to avoid needless overhead and
     // ensure a sane default experience for test authors.
     // @see https://www.drupal.org/node/2259167
     $config->getEditable('system.logging')->set('error_level', 'verbose')->save();
     $config->getEditable('system.performance')->set('css.preprocess', FALSE)->set('js.preprocess', FALSE)->save();
     // Collect modules to install.
     $class = get_class($this);
     $modules = array();
     while ($class) {
         if (property_exists($class, 'modules')) {
             $modules = array_merge($modules, $class::$modules);
         }
         $class = get_parent_class($class);
     }
     if ($modules) {
         $modules = array_unique($modules);
         $success = $container->get('module_installer')->install($modules, TRUE);
         $this->assertTrue($success, SafeMarkup::format('Enabled modules: %modules', array('%modules' => implode(', ', $modules))));
         $this->rebuildContainer();
     }
     // Reset/rebuild all data structures after enabling the modules, primarily
     // to synchronize all data structures and caches between the test runner and
     // the child site.
     // Affects e.g. StreamWrapperManagerInterface::getWrappers().
     // @see \Drupal\Core\DrupalKernel::bootCode()
     // @todo Test-specific setUp() methods may set up further fixtures; find a
     //   way to execute this after setUp() is done, or to eliminate it entirely.
     $this->resetAll();
     $this->kernel->prepareLegacyRequest($request);
 }
예제 #12
0
<?php

/**
 * @file
 * Handles counts of node views via AJAX with minimal bootstrap.
 */
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
chdir('../../..');
$autoloader = (require_once dirname(dirname(__DIR__)) . '/vendor/autoload.php');
$kernel = DrupalKernel::createFromRequest(Request::createFromGlobals(), $autoloader, 'prod');
$kernel->boot();
$views = $kernel->getContainer()->get('config.factory')->get('statistics.settings')->get('count_content_views');
if ($views) {
    $nid = filter_input(INPUT_POST, 'nid', FILTER_VALIDATE_INT);
    if ($nid) {
        \Drupal::database()->merge('node_counter')->key('nid', $nid)->fields(array('daycount' => 1, 'totalcount' => 1, 'timestamp' => REQUEST_TIME))->expression('daycount', 'daycount + 1')->expression('totalcount', 'totalcount + 1')->execute();
    }
}
예제 #13
0
/**
 * @file
 * The PHP page that serves all page requests on a Drupal installation.
 *
 * All Drupal code is released under the GNU General Public License.
 * See COPYRIGHT.txt and LICENSE.txt files in the "core" directory.
 */
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$autoloader = (require_once 'autoload.php');
try {
    $request = Request::createFromGlobals();
    $kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
    $response = $kernel->handle($request)->prepare($request)->send();
    $kernel->terminate($request, $response);
} catch (HttpExceptionInterface $e) {
    $response = new Response($e->getMessage(), $e->getStatusCode());
    $response->prepare($request)->send();
} catch (Exception $e) {
    $message = 'If you have just changed code (for example deployed a new module or moved an existing one) read <a href="http://drupal.org/documentation/rebuild">http://drupal.org/documentation/rebuild</a>';
    if (Settings::get('rebuild_access', FALSE)) {
        $rebuild_path = $GLOBALS['base_url'] . '/rebuild.php';
        $message .= " or run the <a href=\"{$rebuild_path}\">rebuild script</a>";
    }
    // Set the response code manually. Otherwise, this response will default to a
    // 200.
    http_response_code(500);
    print $message;
예제 #14
0
 /**
  * Sets up a Drupal site for running functional and integration tests.
  *
  * Installs Drupal with the installation profile specified in
  * \Drupal\simpletest\WebTestBase::$profile into the prefixed database.
  *
  * Afterwards, installs any additional modules specified in the static
  * \Drupal\simpletest\WebTestBase::$modules property of each class in the
  * class hierarchy.
  *
  * After installation all caches are flushed and several configuration values
  * are reset to the values of the parent site executing the test, since the
  * default values may be incompatible with the environment in which tests are
  * being executed.
  */
 protected function setUp()
 {
     // When running tests through the Simpletest UI (vs. on the command line),
     // Simpletest's batch conflicts with the installer's batch. Batch API does
     // not support the concept of nested batches (in which the nested is not
     // progressive), so we need to temporarily pretend there was no batch.
     // Backup the currently running Simpletest batch.
     $this->originalBatch = batch_get();
     // Define information about the user 1 account.
     $this->rootUser = new UserSession(array('uid' => 1, 'name' => 'admin', 'mail' => '*****@*****.**', 'pass_raw' => $this->randomMachineName()));
     // The child site derives its session name from the database prefix when
     // running web tests.
     $this->generateSessionName($this->databasePrefix);
     // Reset the static batch to remove Simpletest's batch operations.
     $batch =& batch_get();
     $batch = array();
     // Get parameters for install_drupal() before removing global variables.
     $parameters = $this->installParameters();
     // Prepare installer settings that are not install_drupal() parameters.
     // Copy and prepare an actual settings.php, so as to resemble a regular
     // installation.
     // Not using File API; a potential error must trigger a PHP warning.
     $directory = DRUPAL_ROOT . '/' . $this->siteDirectory;
     copy(DRUPAL_ROOT . '/sites/default/default.settings.php', $directory . '/settings.php');
     copy(DRUPAL_ROOT . '/sites/default/default.services.yml', $directory . '/services.yml');
     // All file system paths are created by System module during installation.
     // @see system_requirements()
     // @see TestBase::prepareEnvironment()
     $settings['settings']['file_public_path'] = (object) array('value' => $this->publicFilesDirectory, 'required' => TRUE);
     $settings['settings']['file_private_path'] = (object) array('value' => $this->privateFilesDirectory, 'required' => TRUE);
     // Save the original site directory path, so that extensions in the
     // site-specific directory can still be discovered in the test site
     // environment.
     // @see \Drupal\Core\Extension\ExtensionDiscovery::scan()
     $settings['settings']['test_parent_site'] = (object) array('value' => $this->originalSite, 'required' => TRUE);
     // Add the parent profile's search path to the child site's search paths.
     // @see \Drupal\Core\Extension\ExtensionDiscovery::getProfileDirectories()
     $settings['conf']['simpletest.settings']['parent_profile'] = (object) array('value' => $this->originalProfile, 'required' => TRUE);
     $settings['settings']['apcu_ensure_unique_prefix'] = (object) array('value' => FALSE, 'required' => TRUE);
     $this->writeSettings($settings);
     // Allow for test-specific overrides.
     $settings_testing_file = DRUPAL_ROOT . '/' . $this->originalSite . '/settings.testing.php';
     if (file_exists($settings_testing_file)) {
         // Copy the testing-specific settings.php overrides in place.
         copy($settings_testing_file, $directory . '/settings.testing.php');
         // Add the name of the testing class to settings.php and include the
         // testing specific overrides
         file_put_contents($directory . '/settings.php', "\n\$test_class = '" . get_class($this) . "';\n" . 'include DRUPAL_ROOT . \'/\' . $site_path . \'/settings.testing.php\';' . "\n", FILE_APPEND);
     }
     $settings_services_file = DRUPAL_ROOT . '/' . $this->originalSite . '/testing.services.yml';
     if (file_exists($settings_services_file)) {
         // Copy the testing-specific service overrides in place.
         copy($settings_services_file, $directory . '/services.yml');
     }
     if ($this->strictConfigSchema) {
         // Add a listener to validate configuration schema on save.
         $yaml = new \Symfony\Component\Yaml\Yaml();
         $services = $yaml->parse($directory . '/services.yml');
         $services['services']['simpletest.config_schema_checker'] = ['class' => 'Drupal\\Core\\Config\\Testing\\ConfigSchemaChecker', 'arguments' => ['@config.typed'], 'tags' => [['name' => 'event_subscriber']]];
         file_put_contents($directory . '/services.yml', $yaml->dump($services));
     }
     // Since Drupal is bootstrapped already, install_begin_request() will not
     // bootstrap again. Hence, we have to reload the newly written custom
     // settings.php manually.
     $class_loader = (require DRUPAL_ROOT . '/autoload.php');
     Settings::initialize(DRUPAL_ROOT, $this->siteDirectory, $class_loader);
     // Execute the non-interactive installer.
     require_once DRUPAL_ROOT . '/core/includes/install.core.inc';
     install_drupal($class_loader, $parameters);
     // Import new settings.php written by the installer.
     Settings::initialize(DRUPAL_ROOT, $this->siteDirectory, $class_loader);
     foreach ($GLOBALS['config_directories'] as $type => $path) {
         $this->configDirectories[$type] = $path;
     }
     // After writing settings.php, the installer removes write permissions
     // from the site directory. To allow drupal_generate_test_ua() to write
     // a file containing the private key for drupal_valid_test_ua(), the site
     // directory has to be writable.
     // TestBase::restoreEnvironment() will delete the entire site directory.
     // Not using File API; a potential error must trigger a PHP warning.
     chmod($directory, 0777);
     $request = \Drupal::request();
     $this->kernel = DrupalKernel::createFromRequest($request, $class_loader, 'prod', TRUE);
     $this->kernel->prepareLegacyRequest($request);
     // Force the container to be built from scratch instead of loaded from the
     // disk. This forces us to not accidentally load the parent site.
     $container = $this->kernel->rebuildContainer();
     $config = $container->get('config.factory');
     // Manually create and configure private and temporary files directories.
     // While these could be preset/enforced in settings.php like the public
     // files directory above, some tests expect them to be configurable in the
     // UI. If declared in settings.php, they would no longer be configurable.
     file_prepare_directory($this->privateFilesDirectory, FILE_CREATE_DIRECTORY);
     file_prepare_directory($this->tempFilesDirectory, FILE_CREATE_DIRECTORY);
     $config->getEditable('system.file')->set('path.temporary', $this->tempFilesDirectory)->save();
     // Manually configure the test mail collector implementation to prevent
     // tests from sending out emails and collect them in state instead.
     // While this should be enforced via settings.php prior to installation,
     // some tests expect to be able to test mail system implementations.
     $config->getEditable('system.mail')->set('interface.default', 'test_mail_collector')->save();
     // By default, verbosely display all errors and disable all production
     // environment optimizations for all tests to avoid needless overhead and
     // ensure a sane default experience for test authors.
     // @see https://www.drupal.org/node/2259167
     $config->getEditable('system.logging')->set('error_level', 'verbose')->save();
     $config->getEditable('system.performance')->set('css.preprocess', FALSE)->set('js.preprocess', FALSE)->save();
     // Collect modules to install.
     $class = get_class($this);
     $modules = array();
     while ($class) {
         if (property_exists($class, 'modules')) {
             $modules = array_merge($modules, $class::$modules);
         }
         $class = get_parent_class($class);
     }
     if ($modules) {
         $modules = array_unique($modules);
         try {
             $success = $container->get('module_installer')->install($modules, TRUE);
             $this->assertTrue($success, SafeMarkup::format('Enabled modules: %modules', array('%modules' => implode(', ', $modules))));
         } catch (\Drupal\Core\Extension\MissingDependencyException $e) {
             // The exception message has all the details.
             $this->fail($e->getMessage());
         }
         $this->rebuildContainer();
     }
     // Restore the original Simpletest batch.
     $batch =& batch_get();
     $batch = $this->originalBatch;
     // Reset/rebuild all data structures after enabling the modules, primarily
     // to synchronize all data structures and caches between the test runner and
     // the child site.
     // @see \Drupal\Core\DrupalKernel::bootCode()
     // @todo Test-specific setUp() methods may set up further fixtures; find a
     //   way to execute this after setUp() is done, or to eliminate it entirely.
     $this->resetAll();
     $this->kernel->prepareLegacyRequest($request);
     // Explicitly call register() again on the container registered in \Drupal.
     // @todo This should already be called through
     //   DrupalKernel::prepareLegacyRequest() -> DrupalKernel::boot() but that
     //   appears to be calling a different container.
     $this->container->get('stream_wrapper_manager')->register();
 }
 /**
  * {@inheritdoc}
  */
 public static function createFromRequest(Request $request, $class_loader, $environment = 'test_runner', $allow_dumping = TRUE)
 {
     return parent::createFromRequest($request, $class_loader, $environment);
 }
예제 #16
0
 /**
  * Tests repeated loading of compiled DIC with different environment.
  */
 public function testRepeatedBootWithDifferentEnvironment()
 {
     $request = Request::createFromGlobals();
     $class_loader = (require $this->root . '/autoload.php');
     $environments = ['testing1', 'testing1', 'testing2', 'testing2'];
     foreach ($environments as $environment) {
         $kernel = DrupalKernel::createFromRequest($request, $class_loader, $environment);
         $this->setSetting('container_yamls', []);
         $this->setSetting('hash_salt', $this->databasePrefix);
         $kernel->boot();
     }
     $this->pass('Repeatedly loaded compiled DIC with different environment');
 }
예제 #17
0
 function bootstrap_drupal_configuration()
 {
     $this->request = Request::createFromGlobals();
     $classloader = drush_drupal_load_autoloader(DRUPAL_ROOT);
     // @todo - use Request::create() and then no need to set PHP superglobals
     $kernelClass = new \ReflectionClass('\\Drupal\\Core\\DrupalKernel');
     if ($kernelClass->hasMethod('addServiceModifier')) {
         $this->kernel = DrupalKernel::createFromRequest($this->request, $classloader, 'prod', DRUPAL_ROOT);
     } else {
         $this->kernel = DrushDrupalKernel::createFromRequest($this->request, $classloader, 'prod', DRUPAL_ROOT);
     }
     // @see Drush\Drupal\DrupalKernel::addServiceModifier()
     $this->kernel->addServiceModifier(new DrushServiceModfier());
     // Unset drupal error handler and restore Drush's one.
     restore_error_handler();
     // Disable automated cron if the module is enabled.
     $GLOBALS['config']['automated_cron.settings']['interval'] = 0;
     parent::bootstrap_drupal_configuration();
 }
예제 #18
0
 /**
  * Load drupal bootstrap.
  *
  * @param array $params
  *   Either uid, or name & pass.
  * @param bool $loadUser
  *   Boolean Require CMS user load.
  * @param bool $throwError
  *   If true, print error on failure and exit.
  * @param bool|string $realPath path to script
  *
  * @return bool
  * @Todo Handle setting cleanurls configuration for CiviCRM?
  */
 public function loadBootStrap($params = array(), $loadUser = TRUE, $throwError = TRUE, $realPath = NULL)
 {
     static $run_once = FALSE;
     if ($run_once) {
         return TRUE;
     } else {
         $run_once = TRUE;
     }
     if (!($root = $this->cmsRootPath())) {
         return FALSE;
     }
     chdir($root);
     // Create a mock $request object
     $autoloader = (require_once $root . '/vendor/autoload.php');
     // @Todo: do we need to handle case where $_SERVER has no HTTP_HOST key, ie. when run via cli?
     $request = new \Symfony\Component\HttpFoundation\Request(array(), array(), array(), array(), array(), $_SERVER);
     // Create a kernel and boot it.
     \Drupal\Core\DrupalKernel::createFromRequest($request, $autoloader, 'prod')->prepareLegacyRequest($request);
     // Initialize Civicrm
     \Drupal::service('civicrm');
     // We need to call the config hook again, since we now know
     // all the modules that are listening on it (CRM-8655).
     CRM_Utils_Hook::config($config);
     if ($loadUser) {
         if (!empty($params['uid']) && ($username = \Drupal\user\Entity\User::load($uid)->getUsername())) {
             $this->loadUser($username);
         } elseif (!empty($params['name']) && !empty($params['pass']) && $this->authenticate($params['name'], $params['pass'])) {
             $this->loadUser($params['name']);
         }
     }
     return TRUE;
 }
예제 #19
0
 /**
  * @return \Drupal\Core\DrupalKernel
  */
 public function getKernel()
 {
     // Add support for Acquia Dev Desktop sites on Mac OS X
     $devdesktop_dir = getenv('HOME') . "/.acquia/DevDesktop/DrupalSettings";
     if (file_exists($devdesktop_dir)) {
         $_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR'] = $devdesktop_dir;
     }
     if (!$this->kernel) {
         if ($this->requestUri) {
             $this->request = Request::create($this->requestUri);
             $this->request->server->set('SCRIPT_NAME', '/index.php');
         } else {
             $this->request = Request::createFromGlobals();
         }
         $this->kernel = DrupalKernel::createFromRequest($this->request, $this->classLoader, $this->environment);
     }
     return $this->kernel;
 }
예제 #20
0
function update_task_list($active = NULL)
{
    // Default list of tasks.
    $tasks = array('requirements' => 'Verify requirements', 'info' => 'Overview', 'select' => 'Review updates', 'run' => 'Run updates', 'finished' => 'Review log');
    $task_list = array('#theme' => 'task_list', '#items' => $tasks, '#active' => $active);
    return $task_list;
}
// Some unavoidable errors happen because the database is not yet up-to-date.
// Our custom error handler is not yet installed, so we just suppress them.
ini_set('display_errors', FALSE);
// We prepare a minimal bootstrap for the update requirements check to avoid
// reaching the PHP memory limit.
require_once __DIR__ . '/includes/update.inc';
require_once __DIR__ . '/includes/install.inc';
$request = Request::createFromGlobals();
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'update', FALSE);
// Enable UpdateServiceProvider service overrides.
// @see update_flush_all_caches()
$GLOBALS['conf']['container_service_providers']['UpdateServiceProvider'] = 'Drupal\\Core\\DependencyInjection\\UpdateServiceProvider';
$GLOBALS['conf']['update_service_provider_overrides'] = TRUE;
$kernel->boot();
// Updating from a site schema version prior to 8000 should block the update
// process. Ensure that the site is not attempting to update a database
// created in a previous version of Drupal.
if (db_table_exists('system')) {
    $system_schema = db_query('SELECT schema_version FROM {system} WHERE name = :system', array(':system' => 'system'))->fetchField();
    if ($system_schema < \Drupal::CORE_MINIMUM_SCHEMA_VERSION) {
        print 'Your system schema version is ' . $system_schema . '. Updating directly from a schema version prior to 8000 is not supported. You must <a href="https://drupal.org/node/2179269">migrate your site to Drupal 8</a> first.';
        exit;
    }
}
예제 #21
0
 /**
  * @return \Drupal\Core\DrupalKernel
  */
 public function getKernel()
 {
     // Add support for Acquia Dev Desktop sites on Mac OS X
     // @TODO: Check if this condition works in Windows
     $devdesktop_dir = getenv('HOME') . "/.acquia/DevDesktop/DrupalSettings";
     if (file_exists($devdesktop_dir)) {
         $_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR'] = $devdesktop_dir;
     }
     if (!$this->kernel) {
         $this->request = Request::createFromGlobals();
         $this->kernel = DrupalKernel::createFromRequest($this->request, $this->classLoader, $this->environment);
     }
     return $this->kernel;
 }