diff core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents 129ea1e6d783
children
line wrap: on
line diff
--- a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php	Thu Feb 28 13:21:36 2019 +0000
+++ b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php	Thu May 09 15:33:08 2019 +0100
@@ -10,6 +10,7 @@
 use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Core\Language\Language;
 use Drupal\Core\Url;
+use Drupal\Tests\RequirementsPageTrait;
 use Drupal\user\Entity\User;
 use Symfony\Component\DependencyInjection\Reference;
 use Symfony\Component\HttpFoundation\Request;
@@ -42,6 +43,7 @@
 abstract class UpdatePathTestBase extends BrowserTestBase {
 
   use SchemaCheckTestTrait;
+  use RequirementsPageTrait;
 
   /**
    * Modules to enable after the database is loaded.
@@ -160,8 +162,10 @@
 
     // Set the update url. This must be set here rather than in
     // self::__construct() or the old URL generator will leak additional test
-    // sites.
-    $this->updateUrl = Url::fromRoute('system.db_update');
+    // sites. Additionally, we need to prevent the path alias processor from
+    // running because we might not have a working alias system before running
+    // the updates.
+    $this->updateUrl = Url::fromRoute('system.db_update', [], ['path_processing' => FALSE]);
 
     $this->setupBaseUrl();
 
@@ -264,6 +268,12 @@
       'required' => TRUE,
     ];
 
+    // Force every update hook to only run one entity per batch.
+    $settings['entity_update_batch_size'] = (object) [
+      'value' => 1,
+      'required' => TRUE,
+    ];
+
     $this->writeSettings($settings);
   }
 
@@ -287,6 +297,7 @@
     ]);
 
     $this->drupalGet($this->updateUrl);
+    $this->updateRequirementsProblem();
     $this->clickLink(t('Continue'));
 
     $this->doSelectionTest();
@@ -319,9 +330,38 @@
           }
         }
       }
-      // Reset the static cache of drupal_get_installed_schema_version() so that
-      // more complex update path testing works.
-      drupal_static_reset('drupal_get_installed_schema_version');
+
+      // Ensure that the container is updated if any modules are installed or
+      // uninstalled during the update.
+      /** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
+      $module_handler = $this->container->get('module_handler');
+      $config_module_list = $this->config('core.extension')->get('module');
+      $module_handler_list = $module_handler->getModuleList();
+      $modules_installed = FALSE;
+      // Modules that are in configuration but not the module handler have been
+      // installed.
+      foreach (array_keys(array_diff_key($config_module_list, $module_handler_list)) as $module) {
+        $module_handler->addModule($module, drupal_get_path('module', $module));
+        $modules_installed = TRUE;
+      }
+      $modules_uninstalled = FALSE;
+      $module_handler_list = $module_handler->getModuleList();
+      // Modules that are in the module handler but not configuration have been
+      // uninstalled.
+      foreach (array_keys(array_diff_key($module_handler_list, $config_module_list)) as $module) {
+        $modules_uninstalled = TRUE;
+        unset($module_handler_list[$module]);
+      }
+      if ($modules_installed || $modules_uninstalled) {
+        // Note that resetAll() does not reset the kernel module list so we
+        // have to do that manually.
+        $this->kernel->updateModules($module_handler_list, $module_handler_list);
+      }
+
+      // If we have successfully clicked 'Apply pending updates' then we need to
+      // clear the caches in the update test runner as this has occurred as part
+      // of the updates.
+      $this->resetAll();
 
       // The config schema can be incorrect while the update functions are being
       // executed. But once the update has been completed, it needs to be valid
@@ -329,7 +369,6 @@
       $names = $this->container->get('config.storage')->listAll();
       /** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config */
       $typed_config = $this->container->get('config.typed');
-      $typed_config->clearCachedDefinitions();
       foreach ($names as $name) {
         $config = $this->config($name);
         $this->assertConfigSchema($typed_config, $name, $config->get());
@@ -385,7 +424,7 @@
     $account = User::load(1);
     $account->setPassword($this->rootUser->pass_raw);
     $account->setEmail($this->rootUser->getEmail());
-    $account->setUsername($this->rootUser->getUsername());
+    $account->setUsername($this->rootUser->getAccountName());
     $account->save();
   }