comparison core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
2 2
3 namespace Drupal\Core\Test; 3 namespace Drupal\Core\Test;
4 4
5 use Drupal\Component\FileCache\FileCacheFactory; 5 use Drupal\Component\FileCache\FileCacheFactory;
6 use Drupal\Component\Render\FormattableMarkup; 6 use Drupal\Component\Render\FormattableMarkup;
7 use Drupal\Component\Utility\Environment;
7 use Drupal\Core\Config\Development\ConfigSchemaChecker; 8 use Drupal\Core\Config\Development\ConfigSchemaChecker;
8 use Drupal\Core\Database\Database; 9 use Drupal\Core\Database\Database;
9 use Drupal\Core\DrupalKernel; 10 use Drupal\Core\DrupalKernel;
10 use Drupal\Core\Extension\MissingDependencyException; 11 use Drupal\Core\Extension\MissingDependencyException;
12 use Drupal\Core\File\FileSystemInterface;
11 use Drupal\Core\Serialization\Yaml; 13 use Drupal\Core\Serialization\Yaml;
12 use Drupal\Core\Session\UserSession; 14 use Drupal\Core\Session\UserSession;
13 use Drupal\Core\Site\Settings; 15 use Drupal\Core\Site\Settings;
14 use Drupal\Core\StreamWrapper\StreamWrapperInterface; 16 use Drupal\Core\StreamWrapper\StreamWrapperInterface;
15 use Drupal\Tests\SessionTestTrait; 17 use Drupal\Tests\SessionTestTrait;
316 */ 318 */
317 protected function initConfig(ContainerInterface $container) { 319 protected function initConfig(ContainerInterface $container) {
318 $config = $container->get('config.factory'); 320 $config = $container->get('config.factory');
319 321
320 // Manually create the private directory. 322 // Manually create the private directory.
321 file_prepare_directory($this->privateFilesDirectory, FILE_CREATE_DIRECTORY); 323 \Drupal::service('file_system')->prepareDirectory($this->privateFilesDirectory, FileSystemInterface::CREATE_DIRECTORY);
322 324
323 // Manually configure the test mail collector implementation to prevent 325 // Manually configure the test mail collector implementation to prevent
324 // tests from sending out emails and collect them in state instead. 326 // tests from sending out emails and collect them in state instead.
325 // While this should be enforced via settings.php prior to installation, 327 // While this should be enforced via settings.php prior to installation,
326 // some tests expect to be able to test mail system implementations. 328 // some tests expect to be able to test mail system implementations.
379 * @return \Symfony\Component\DependencyInjection\ContainerInterface 381 * @return \Symfony\Component\DependencyInjection\ContainerInterface
380 * The container. 382 * The container.
381 */ 383 */
382 protected function initKernel(Request $request) { 384 protected function initKernel(Request $request) {
383 $this->kernel = DrupalKernel::createFromRequest($request, $this->classLoader, 'prod', TRUE); 385 $this->kernel = DrupalKernel::createFromRequest($request, $this->classLoader, 'prod', TRUE);
384 $this->kernel->prepareLegacyRequest($request); 386
385 // Force the container to be built from scratch instead of loaded from the 387 // 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. 388 // disk. This forces us to not accidentally load the parent site.
387 return $this->kernel->rebuildContainer(); 389 $this->kernel->invalidateContainer();
390
391 $this->kernel->prepareLegacyRequest($request);
392 return \Drupal::getContainer();
388 } 393 }
389 394
390 /** 395 /**
391 * Install modules defined by `static::$modules`. 396 * Install modules defined by `static::$modules`.
392 * 397 *
416 } 421 }
417 catch (MissingDependencyException $e) { 422 catch (MissingDependencyException $e) {
418 // The exception message has all the details. 423 // The exception message has all the details.
419 $this->fail($e->getMessage()); 424 $this->fail($e->getMessage());
420 } 425 }
421 426 // The container was already rebuilt by the ModuleInstaller.
422 $this->rebuildContainer(); 427 $this->container = \Drupal::getContainer();
423 } 428 }
424 } 429 }
425 430
426 /** 431 /**
427 * Resets and rebuilds the environment after setup. 432 * Resets and rebuilds the environment after setup.
573 578
574 $this->originalSite = $kernel->findSitePath($request); 579 $this->originalSite = $kernel->findSitePath($request);
575 580
576 // Create test directory ahead of installation so fatal errors and debug 581 // Create test directory ahead of installation so fatal errors and debug
577 // information can be logged during installation process. 582 // information can be logged during installation process.
578 file_prepare_directory($this->siteDirectory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); 583 \Drupal::service('file_system')->prepareDirectory($this->siteDirectory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
579 584
580 // Prepare filesystem directory paths. 585 // Prepare filesystem directory paths.
581 $this->publicFilesDirectory = $this->siteDirectory . '/files'; 586 $this->publicFilesDirectory = $this->siteDirectory . '/files';
582 $this->privateFilesDirectory = $this->siteDirectory . '/private'; 587 $this->privateFilesDirectory = $this->siteDirectory . '/private';
583 $this->tempFilesDirectory = $this->siteDirectory . '/temp'; 588 $this->tempFilesDirectory = $this->siteDirectory . '/temp';
617 new Settings([ 622 new Settings([
618 // For performance, simply use the database prefix as hash salt. 623 // For performance, simply use the database prefix as hash salt.
619 'hash_salt' => $this->databasePrefix, 624 'hash_salt' => $this->databasePrefix,
620 ]); 625 ]);
621 626
622 drupal_set_time_limit($this->timeLimit); 627 Environment::setTimeLimit($this->timeLimit);
623 628
624 // Save and clean the shutdown callbacks array because it is static cached 629 // 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 630 // 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 631 // from both environments and the testing environment will try to call the
627 // handlers defined by the original one. 632 // handlers defined by the original one.