Pull merge.
[yaffs-website] / web / core / lib / Drupal / Core / Test / FunctionalTestSetupTrait.php
1 <?php
2
3 namespace Drupal\Core\Test;
4
5 use Drupal\Component\FileCache\FileCacheFactory;
6 use Drupal\Component\Render\FormattableMarkup;
7 use Drupal\Core\Config\Development\ConfigSchemaChecker;
8 use Drupal\Core\Database\Database;
9 use Drupal\Core\DrupalKernel;
10 use Drupal\Core\Extension\MissingDependencyException;
11 use Drupal\Core\Serialization\Yaml;
12 use Drupal\Core\Session\UserSession;
13 use Drupal\Core\Site\Settings;
14 use Drupal\Core\StreamWrapper\StreamWrapperInterface;
15 use Drupal\Tests\SessionTestTrait;
16 use Symfony\Component\DependencyInjection\ContainerInterface;
17 use Symfony\Component\HttpFoundation\Request;
18 use Symfony\Component\Yaml\Yaml as SymfonyYaml;
19
20 /**
21  * Defines a trait for shared functional test setup functionality.
22  */
23 trait FunctionalTestSetupTrait {
24
25   use SessionTestTrait;
26   use RefreshVariablesTrait;
27
28   /**
29    * The "#1" admin user.
30    *
31    * @var \Drupal\Core\Session\AccountInterface
32    */
33   protected $rootUser;
34
35   /**
36    * The class loader to use for installation and initialization of setup.
37    *
38    * @var \Symfony\Component\Classloader\Classloader
39    */
40   protected $classLoader;
41
42   /**
43    * The config directories used in this test.
44    */
45   protected $configDirectories = [];
46
47   /**
48    * The flag to set 'apcu_ensure_unique_prefix' setting.
49    *
50    * Wide use of a unique prefix can lead to problems with memory, if tests are
51    * run with a concurrency higher than 1. Therefore, FALSE by default.
52    *
53    * @var bool
54    *
55    * @see \Drupal\Core\Site\Settings::getApcuPrefix().
56    */
57   protected $apcuEnsureUniquePrefix = FALSE;
58
59   /**
60    * Prepares site settings and services before installation.
61    */
62   protected function prepareSettings() {
63     // Prepare installer settings that are not install_drupal() parameters.
64     // Copy and prepare an actual settings.php, so as to resemble a regular
65     // installation.
66     // Not using File API; a potential error must trigger a PHP warning.
67     $directory = DRUPAL_ROOT . '/' . $this->siteDirectory;
68     copy(DRUPAL_ROOT . '/sites/default/default.settings.php', $directory . '/settings.php');
69
70     // The public file system path is created during installation. Additionally,
71     // during tests:
72     // - The temporary directory is set and created by install_base_system().
73     // - The private file directory is created post install by
74     //   FunctionalTestSetupTrait::initConfig().
75     // @see system_requirements()
76     // @see TestBase::prepareEnvironment()
77     // @see install_base_system()
78     // @see \Drupal\Core\Test\FunctionalTestSetupTrait::initConfig()
79     $settings['settings']['file_public_path'] = (object) [
80       'value' => $this->publicFilesDirectory,
81       'required' => TRUE,
82     ];
83     $settings['settings']['file_private_path'] = (object) [
84       'value' => $this->privateFilesDirectory,
85       'required' => TRUE,
86     ];
87     // Save the original site directory path, so that extensions in the
88     // site-specific directory can still be discovered in the test site
89     // environment.
90     // @see \Drupal\Core\Extension\ExtensionDiscovery::scan()
91     $settings['settings']['test_parent_site'] = (object) [
92       'value' => $this->originalSite,
93       'required' => TRUE,
94     ];
95     // Add the parent profile's search path to the child site's search paths.
96     // @see \Drupal\Core\Extension\ExtensionDiscovery::getProfileDirectories()
97     $settings['conf']['simpletest.settings']['parent_profile'] = (object) [
98       'value' => $this->originalProfile,
99       'required' => TRUE,
100     ];
101     $settings['settings']['apcu_ensure_unique_prefix'] = (object) [
102       'value' => $this->apcuEnsureUniquePrefix,
103       'required' => TRUE,
104     ];
105     $this->writeSettings($settings);
106     // Allow for test-specific overrides.
107     $settings_testing_file = DRUPAL_ROOT . '/' . $this->originalSite . '/settings.testing.php';
108     if (file_exists($settings_testing_file)) {
109       // Copy the testing-specific settings.php overrides in place.
110       copy($settings_testing_file, $directory . '/settings.testing.php');
111       // Add the name of the testing class to settings.php and include the
112       // testing specific overrides.
113       file_put_contents($directory . '/settings.php', "\n\$test_class = '" . get_class($this) . "';\n" . 'include DRUPAL_ROOT . \'/\' . $site_path . \'/settings.testing.php\';' . "\n", FILE_APPEND);
114     }
115     $settings_services_file = DRUPAL_ROOT . '/' . $this->originalSite . '/testing.services.yml';
116     if (!file_exists($settings_services_file)) {
117       // Otherwise, use the default services as a starting point for overrides.
118       $settings_services_file = DRUPAL_ROOT . '/sites/default/default.services.yml';
119     }
120     // Copy the testing-specific service overrides in place.
121     copy($settings_services_file, $directory . '/services.yml');
122     if ($this->strictConfigSchema) {
123       // Add a listener to validate configuration schema on save.
124       $yaml = new SymfonyYaml();
125       $content = file_get_contents($directory . '/services.yml');
126       $services = $yaml->parse($content);
127       $services['services']['simpletest.config_schema_checker'] = [
128         'class' => ConfigSchemaChecker::class,
129         'arguments' => ['@config.typed', $this->getConfigSchemaExclusions()],
130         'tags' => [['name' => 'event_subscriber']],
131       ];
132       file_put_contents($directory . '/services.yml', $yaml->dump($services));
133     }
134     // Since Drupal is bootstrapped already, install_begin_request() will not
135     // bootstrap again. Hence, we have to reload the newly written custom
136     // settings.php manually.
137     Settings::initialize(DRUPAL_ROOT, $this->siteDirectory, $this->classLoader);
138   }
139
140   /**
141    * Rewrites the settings.php file of the test site.
142    *
143    * @param array $settings
144    *   An array of settings to write out, in the format expected by
145    *   drupal_rewrite_settings().
146    *
147    * @see drupal_rewrite_settings()
148    */
149   protected function writeSettings(array $settings) {
150     include_once DRUPAL_ROOT . '/core/includes/install.inc';
151     $filename = $this->siteDirectory . '/settings.php';
152     // system_requirements() removes write permissions from settings.php
153     // whenever it is invoked.
154     // Not using File API; a potential error must trigger a PHP warning.
155     chmod($filename, 0666);
156     drupal_rewrite_settings($settings, $filename);
157   }
158
159   /**
160    * Changes parameters in the services.yml file.
161    *
162    * @param string $name
163    *   The name of the parameter.
164    * @param string $value
165    *   The value of the parameter.
166    */
167   protected function setContainerParameter($name, $value) {
168     $filename = $this->siteDirectory . '/services.yml';
169     chmod($filename, 0666);
170
171     $services = Yaml::decode(file_get_contents($filename));
172     $services['parameters'][$name] = $value;
173     file_put_contents($filename, Yaml::encode($services));
174
175     // Ensure that the cache is deleted for the yaml file loader.
176     $file_cache = FileCacheFactory::get('container_yaml_loader');
177     $file_cache->delete($filename);
178   }
179
180   /**
181    * Rebuilds \Drupal::getContainer().
182    *
183    * Use this to update the test process's kernel with a new service container.
184    * For example, when the list of enabled modules is changed via the internal
185    * browser the test process's kernel has a service container with an out of
186    * date module list.
187    *
188    * @see TestBase::prepareEnvironment()
189    * @see TestBase::restoreEnvironment()
190    *
191    * @todo Fix https://www.drupal.org/node/2021959 so that module enable/disable
192    *   changes are immediately reflected in \Drupal::getContainer(). Until then,
193    *   tests can invoke this workaround when requiring services from newly
194    *   enabled modules to be immediately available in the same request.
195    */
196   protected function rebuildContainer() {
197     // Rebuild the kernel and bring it back to a fully bootstrapped state.
198     $this->container = $this->kernel->rebuildContainer();
199
200     // Make sure the url generator has a request object, otherwise calls to
201     // $this->drupalGet() will fail.
202     $this->prepareRequestForGenerator();
203   }
204
205   /**
206    * Resets all data structures after having enabled new modules.
207    *
208    * This method is called by FunctionalTestSetupTrait::rebuildAll() after
209    * enabling the requested modules. It must be called again when additional
210    * modules are enabled later.
211    *
212    * @see \Drupal\Core\Test\FunctionalTestSetupTrait::rebuildAll()
213    * @see \Drupal\Tests\BrowserTestBase::installDrupal()
214    * @see \Drupal\simpletest\WebTestBase::setUp()
215    */
216   protected function resetAll() {
217     // Clear all database and static caches and rebuild data structures.
218     drupal_flush_all_caches();
219     $this->container = \Drupal::getContainer();
220
221     // Reset static variables and reload permissions.
222     $this->refreshVariables();
223   }
224
225   /**
226    * Creates a mock request and sets it on the generator.
227    *
228    * This is used to manipulate how the generator generates paths during tests.
229    * It also ensures that calls to $this->drupalGet() will work when running
230    * from run-tests.sh because the url generator no longer looks at the global
231    * variables that are set there but relies on getting this information from a
232    * request object.
233    *
234    * @param bool $clean_urls
235    *   Whether to mock the request using clean urls.
236    * @param array $override_server_vars
237    *   An array of server variables to override.
238    *
239    * @return \Symfony\Component\HttpFoundation\Request
240    *   The mocked request object.
241    */
242   protected function prepareRequestForGenerator($clean_urls = TRUE, $override_server_vars = []) {
243     $request = Request::createFromGlobals();
244     $server = $request->server->all();
245     if (basename($server['SCRIPT_FILENAME']) != basename($server['SCRIPT_NAME'])) {
246       // We need this for when the test is executed by run-tests.sh.
247       // @todo Remove this once run-tests.sh has been converted to use a Request
248       //   object.
249       $cwd = getcwd();
250       $server['SCRIPT_FILENAME'] = $cwd . '/' . basename($server['SCRIPT_NAME']);
251       $base_path = rtrim($server['REQUEST_URI'], '/');
252     }
253     else {
254       $base_path = $request->getBasePath();
255     }
256     if ($clean_urls) {
257       $request_path = $base_path ? $base_path . '/user' : 'user';
258     }
259     else {
260       $request_path = $base_path ? $base_path . '/index.php/user' : '/index.php/user';
261     }
262     $server = array_merge($server, $override_server_vars);
263
264     $request = Request::create($request_path, 'GET', [], [], [], $server);
265     // Ensure the request time is REQUEST_TIME to ensure that API calls
266     // in the test use the right timestamp.
267     $request->server->set('REQUEST_TIME', REQUEST_TIME);
268     $this->container->get('request_stack')->push($request);
269
270     // The request context is normally set by the router_listener from within
271     // its KernelEvents::REQUEST listener. In the simpletest parent site this
272     // event is not fired, therefore it is necessary to updated the request
273     // context manually here.
274     $this->container->get('router.request_context')->fromRequest($request);
275
276     return $request;
277   }
278
279   /**
280    * Execute the non-interactive installer.
281    *
282    * @see install_drupal()
283    */
284   protected function doInstall() {
285     require_once DRUPAL_ROOT . '/core/includes/install.core.inc';
286     install_drupal($this->classLoader, $this->installParameters());
287   }
288
289   /**
290    * Initialize settings created during install.
291    */
292   protected function initSettings() {
293     Settings::initialize(DRUPAL_ROOT, $this->siteDirectory, $this->classLoader);
294     foreach ($GLOBALS['config_directories'] as $type => $path) {
295       $this->configDirectories[$type] = $path;
296     }
297
298     // After writing settings.php, the installer removes write permissions
299     // from the site directory. To allow drupal_generate_test_ua() to write
300     // a file containing the private key for drupal_valid_test_ua(), the site
301     // directory has to be writable.
302     // TestBase::restoreEnvironment() will delete the entire site directory.
303     // Not using File API; a potential error must trigger a PHP warning.
304     chmod(DRUPAL_ROOT . '/' . $this->siteDirectory, 0777);
305
306     // During tests, cacheable responses should get the debugging cacheability
307     // headers by default.
308     $this->setContainerParameter('http.response.debug_cacheability_headers', TRUE);
309   }
310
311   /**
312    * Initialize various configurations post-installation.
313    *
314    * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
315    *   The container.
316    */
317   protected function initConfig(ContainerInterface $container) {
318     $config = $container->get('config.factory');
319
320     // Manually create the private directory.
321     file_prepare_directory($this->privateFilesDirectory, FILE_CREATE_DIRECTORY);
322
323     // Manually configure the test mail collector implementation to prevent
324     // tests from sending out emails and collect them in state instead.
325     // While this should be enforced via settings.php prior to installation,
326     // some tests expect to be able to test mail system implementations.
327     $config->getEditable('system.mail')
328       ->set('interface.default', 'test_mail_collector')
329       ->save();
330
331     // By default, verbosely display all errors and disable all production
332     // environment optimizations for all tests to avoid needless overhead and
333     // ensure a sane default experience for test authors.
334     // @see https://www.drupal.org/node/2259167
335     $config->getEditable('system.logging')
336       ->set('error_level', 'verbose')
337       ->save();
338     $config->getEditable('system.performance')
339       ->set('css.preprocess', FALSE)
340       ->set('js.preprocess', FALSE)
341       ->save();
342
343     // Set an explicit time zone to not rely on the system one, which may vary
344     // from setup to setup. The Australia/Sydney time zone is chosen so all
345     // tests are run using an edge case scenario (UTC10 and DST). This choice
346     // is made to prevent time zone related regressions and reduce the
347     // fragility of the testing system in general.
348     $config->getEditable('system.date')
349       ->set('timezone.default', 'Australia/Sydney')
350       ->save();
351   }
352
353   /**
354    * Initializes user 1 for the site to be installed.
355    */
356   protected function initUserSession() {
357     $password = $this->randomMachineName();
358     // Define information about the user 1 account.
359     $this->rootUser = new UserSession([
360       'uid' => 1,
361       'name' => 'admin',
362       'mail' => 'admin@example.com',
363       'pass_raw' => $password,
364       'passRaw' => $password,
365       'timezone' => date_default_timezone_get(),
366     ]);
367
368     // The child site derives its session name from the database prefix when
369     // running web tests.
370     $this->generateSessionName($this->databasePrefix);
371   }
372
373   /**
374    * Initializes the kernel after installation.
375    *
376    * @param \Symfony\Component\HttpFoundation\Request $request
377    *   Request object.
378    *
379    * @return \Symfony\Component\DependencyInjection\ContainerInterface
380    *   The container.
381    */
382   protected function initKernel(Request $request) {
383     $this->kernel = DrupalKernel::createFromRequest($request, $this->classLoader, 'prod', TRUE);
384     $this->kernel->prepareLegacyRequest($request);
385     // Force the container to be built from scratch instead of loaded from the
386     // disk. This forces us to not accidentally load the parent site.
387     return $this->kernel->rebuildContainer();
388   }
389
390   /**
391    * Install modules defined by `static::$modules`.
392    *
393    * To install test modules outside of the testing environment, add
394    * @code
395    * $settings['extension_discovery_scan_tests'] = TRUE;
396    * @endcode
397    * to your settings.php.
398    *
399    * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
400    *   The container.
401    */
402   protected function installModulesFromClassProperty(ContainerInterface $container) {
403     $class = get_class($this);
404     $modules = [];
405     while ($class) {
406       if (property_exists($class, 'modules')) {
407         $modules = array_merge($modules, $class::$modules);
408       }
409       $class = get_parent_class($class);
410     }
411     if ($modules) {
412       $modules = array_unique($modules);
413       try {
414         $success = $container->get('module_installer')->install($modules, TRUE);
415         $this->assertTrue($success, new FormattableMarkup('Enabled modules: %modules', ['%modules' => implode(', ', $modules)]));
416       }
417       catch (MissingDependencyException $e) {
418         // The exception message has all the details.
419         $this->fail($e->getMessage());
420       }
421
422       $this->rebuildContainer();
423     }
424   }
425
426   /**
427    * Resets and rebuilds the environment after setup.
428    */
429   protected function rebuildAll() {
430     // Reset/rebuild all data structures after enabling the modules, primarily
431     // to synchronize all data structures and caches between the test runner and
432     // the child site.
433     // @see \Drupal\Core\DrupalKernel::bootCode()
434     // @todo Test-specific setUp() methods may set up further fixtures; find a
435     //   way to execute this after setUp() is done, or to eliminate it entirely.
436     $this->resetAll();
437     $this->kernel->prepareLegacyRequest(\Drupal::request());
438
439     // Explicitly call register() again on the container registered in \Drupal.
440     // @todo This should already be called through
441     //   DrupalKernel::prepareLegacyRequest() -> DrupalKernel::boot() but that
442     //   appears to be calling a different container.
443     $this->container->get('stream_wrapper_manager')->register();
444   }
445
446   /**
447    * Returns the parameters that will be used when Simpletest installs Drupal.
448    *
449    * @see install_drupal()
450    * @see install_state_defaults()
451    *
452    * @return array
453    *   Array of parameters for use in install_drupal().
454    */
455   protected function installParameters() {
456     $connection_info = Database::getConnectionInfo();
457     $driver = $connection_info['default']['driver'];
458     $connection_info['default']['prefix'] = $connection_info['default']['prefix']['default'];
459     unset($connection_info['default']['driver']);
460     unset($connection_info['default']['namespace']);
461     unset($connection_info['default']['pdo']);
462     unset($connection_info['default']['init_commands']);
463     // Remove database connection info that is not used by SQLite.
464     if ($driver === 'sqlite') {
465       unset($connection_info['default']['username']);
466       unset($connection_info['default']['password']);
467       unset($connection_info['default']['host']);
468       unset($connection_info['default']['port']);
469     }
470     $parameters = [
471       'interactive' => FALSE,
472       'parameters' => [
473         'profile' => $this->profile,
474         'langcode' => 'en',
475       ],
476       'forms' => [
477         'install_settings_form' => [
478           'driver' => $driver,
479           $driver => $connection_info['default'],
480         ],
481         'install_configure_form' => [
482           'site_name' => 'Drupal',
483           'site_mail' => 'simpletest@example.com',
484           'account' => [
485             'name' => $this->rootUser->name,
486             'mail' => $this->rootUser->getEmail(),
487             'pass' => [
488               'pass1' => isset($this->rootUser->pass_raw) ? $this->rootUser->pass_raw : $this->rootUser->passRaw,
489               'pass2' => isset($this->rootUser->pass_raw) ? $this->rootUser->pass_raw : $this->rootUser->passRaw,
490             ],
491           ],
492           // form_type_checkboxes_value() requires NULL instead of FALSE values
493           // for programmatic form submissions to disable a checkbox.
494           'enable_update_status_module' => NULL,
495           'enable_update_status_emails' => NULL,
496         ],
497       ],
498     ];
499
500     // If we only have one db driver available, we cannot set the driver.
501     include_once DRUPAL_ROOT . '/core/includes/install.inc';
502     if (count($this->getDatabaseTypes()) == 1) {
503       unset($parameters['forms']['install_settings_form']['driver']);
504     }
505     return $parameters;
506   }
507
508   /**
509    * Sets up the base URL based upon the environment variable.
510    *
511    * @throws \Exception
512    *   Thrown when no SIMPLETEST_BASE_URL environment variable is provided.
513    */
514   protected function setupBaseUrl() {
515     global $base_url;
516
517     // Get and set the domain of the environment we are running our test
518     // coverage against.
519     $base_url = getenv('SIMPLETEST_BASE_URL');
520     if (!$base_url) {
521       throw new \Exception(
522         'You must provide a SIMPLETEST_BASE_URL environment variable to run some PHPUnit based functional tests.'
523       );
524     }
525
526     // Setup $_SERVER variable.
527     $parsed_url = parse_url($base_url);
528     $host = $parsed_url['host'] . (isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '');
529     $path = isset($parsed_url['path']) ? rtrim(rtrim($parsed_url['path']), '/') : '';
530     $port = isset($parsed_url['port']) ? $parsed_url['port'] : 80;
531
532     $this->baseUrl = $base_url;
533
534     // If the passed URL schema is 'https' then setup the $_SERVER variables
535     // properly so that testing will run under HTTPS.
536     if ($parsed_url['scheme'] === 'https') {
537       $_SERVER['HTTPS'] = 'on';
538     }
539     $_SERVER['HTTP_HOST'] = $host;
540     $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
541     $_SERVER['SERVER_ADDR'] = '127.0.0.1';
542     $_SERVER['SERVER_PORT'] = $port;
543     $_SERVER['SERVER_SOFTWARE'] = NULL;
544     $_SERVER['SERVER_NAME'] = 'localhost';
545     $_SERVER['REQUEST_URI'] = $path . '/';
546     $_SERVER['REQUEST_METHOD'] = 'GET';
547     $_SERVER['SCRIPT_NAME'] = $path . '/index.php';
548     $_SERVER['SCRIPT_FILENAME'] = $path . '/index.php';
549     $_SERVER['PHP_SELF'] = $path . '/index.php';
550     $_SERVER['HTTP_USER_AGENT'] = 'Drupal command line';
551   }
552
553   /**
554    * Prepares the current environment for running the test.
555    *
556    * Also sets up new resources for the testing environment, such as the public
557    * filesystem and configuration directories.
558    *
559    * This method is private as it must only be called once by
560    * BrowserTestBase::setUp() (multiple invocations for the same test would have
561    * unpredictable consequences) and it must not be callable or overridable by
562    * test classes.
563    */
564   protected function prepareEnvironment() {
565     // Bootstrap Drupal so we can use Drupal's built in functions.
566     $this->classLoader = require __DIR__ . '/../../../../../autoload.php';
567     $request = Request::createFromGlobals();
568     $kernel = TestRunnerKernel::createFromRequest($request, $this->classLoader);
569     // TestRunnerKernel expects the working directory to be DRUPAL_ROOT.
570     chdir(DRUPAL_ROOT);
571     $kernel->prepareLegacyRequest($request);
572     $this->prepareDatabasePrefix();
573
574     $this->originalSite = $kernel->findSitePath($request);
575
576     // Create test directory ahead of installation so fatal errors and debug
577     // information can be logged during installation process.
578     file_prepare_directory($this->siteDirectory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
579
580     // Prepare filesystem directory paths.
581     $this->publicFilesDirectory = $this->siteDirectory . '/files';
582     $this->privateFilesDirectory = $this->siteDirectory . '/private';
583     $this->tempFilesDirectory = $this->siteDirectory . '/temp';
584     $this->translationFilesDirectory = $this->siteDirectory . '/translations';
585
586     // Ensure the configImporter is refreshed for each test.
587     $this->configImporter = NULL;
588
589     // Unregister all custom stream wrappers of the parent site.
590     $wrappers = \Drupal::service('stream_wrapper_manager')->getWrappers(StreamWrapperInterface::ALL);
591     foreach ($wrappers as $scheme => $info) {
592       stream_wrapper_unregister($scheme);
593     }
594
595     // Reset statics.
596     drupal_static_reset();
597
598     $this->container = NULL;
599
600     // Unset globals.
601     unset($GLOBALS['config_directories']);
602     unset($GLOBALS['config']);
603     unset($GLOBALS['conf']);
604
605     // Log fatal errors.
606     ini_set('log_errors', 1);
607     ini_set('error_log', DRUPAL_ROOT . '/' . $this->siteDirectory . '/error.log');
608
609     // Change the database prefix.
610     $this->changeDatabasePrefix();
611
612     // After preparing the environment and changing the database prefix, we are
613     // in a valid test environment.
614     drupal_valid_test_ua($this->databasePrefix);
615
616     // Reset settings.
617     new Settings([
618       // For performance, simply use the database prefix as hash salt.
619       'hash_salt' => $this->databasePrefix,
620     ]);
621
622     drupal_set_time_limit($this->timeLimit);
623
624     // Save and clean the shutdown callbacks array because it is static cached
625     // and will be changed by the test run. Otherwise it will contain callbacks
626     // from both environments and the testing environment will try to call the
627     // handlers defined by the original one.
628     $callbacks = &drupal_register_shutdown_function();
629     $this->originalShutdownCallbacks = $callbacks;
630     $callbacks = [];
631   }
632
633   /**
634    * Returns all supported database driver installer objects.
635    *
636    * This wraps drupal_get_database_types() for use without a current container.
637    *
638    * @return \Drupal\Core\Database\Install\Tasks[]
639    *   An array of available database driver installer objects.
640    */
641   protected function getDatabaseTypes() {
642     if (isset($this->originalContainer) && $this->originalContainer) {
643       \Drupal::setContainer($this->originalContainer);
644     }
645     $database_types = drupal_get_database_types();
646     if (isset($this->originalContainer) && $this->originalContainer) {
647       \Drupal::unsetContainer();
648     }
649     return $database_types;
650   }
651
652 }