Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / lib / Drupal / Core / Test / FunctionalTestSetupTrait.php
index 3165815b175575060528ab9a94a4e6f222743c6c..9e8307a5571790dbf70b89edebfb4ed9f37cd8af 100644 (file)
@@ -3,8 +3,7 @@
 namespace Drupal\Core\Test;
 
 use Drupal\Component\FileCache\FileCacheFactory;
-use Drupal\Component\Utility\SafeMarkup;
-use Drupal\Core\Cache\Cache;
+use Drupal\Component\Render\FormattableMarkup;
 use Drupal\Core\Config\Development\ConfigSchemaChecker;
 use Drupal\Core\Database\Database;
 use Drupal\Core\DrupalKernel;
@@ -13,6 +12,7 @@ use Drupal\Core\Serialization\Yaml;
 use Drupal\Core\Session\UserSession;
 use Drupal\Core\Site\Settings;
 use Drupal\Core\StreamWrapper\StreamWrapperInterface;
+use Drupal\Tests\SessionTestTrait;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\Yaml\Yaml as SymfonyYaml;
@@ -22,6 +22,9 @@ use Symfony\Component\Yaml\Yaml as SymfonyYaml;
  */
 trait FunctionalTestSetupTrait {
 
+  use SessionTestTrait;
+  use RefreshVariablesTrait;
+
   /**
    * The "#1" admin user.
    *
@@ -219,32 +222,6 @@ trait FunctionalTestSetupTrait {
     $this->refreshVariables();
   }
 
-  /**
-   * Refreshes in-memory configuration and state information.
-   *
-   * Useful after a page request is made that changes configuration or state in
-   * a different thread.
-   *
-   * In other words calling a settings page with $this->drupalPostForm() with a
-   * changed value would update configuration to reflect that change, but in the
-   * thread that made the call (thread running the test) the changed values
-   * would not be picked up.
-   *
-   * This method clears the cache and loads a fresh copy.
-   */
-  protected function refreshVariables() {
-    // Clear the tag cache.
-    \Drupal::service('cache_tags.invalidator')->resetChecksums();
-    foreach (Cache::getBins() as $backend) {
-      if (is_callable([$backend, 'reset'])) {
-        $backend->reset();
-      }
-    }
-
-    $this->container->get('config.factory')->reset();
-    $this->container->get('state')->resetCache();
-  }
-
   /**
    * Creates a mock request and sets it on the generator.
    *
@@ -435,7 +412,7 @@ trait FunctionalTestSetupTrait {
       $modules = array_unique($modules);
       try {
         $success = $container->get('module_installer')->install($modules, TRUE);
-        $this->assertTrue($success, SafeMarkup::format('Enabled modules: %modules', ['%modules' => implode(', ', $modules)]));
+        $this->assertTrue($success, new FormattableMarkup('Enabled modules: %modules', ['%modules' => implode(', ', $modules)]));
       }
       catch (MissingDependencyException $e) {
         // The exception message has all the details.
@@ -662,11 +639,11 @@ trait FunctionalTestSetupTrait {
    *   An array of available database driver installer objects.
    */
   protected function getDatabaseTypes() {
-    if ($this->originalContainer) {
+    if (isset($this->originalContainer) && $this->originalContainer) {
       \Drupal::setContainer($this->originalContainer);
     }
     $database_types = drupal_get_database_types();
-    if ($this->originalContainer) {
+    if (isset($this->originalContainer) && $this->originalContainer) {
       \Drupal::unsetContainer();
     }
     return $database_types;