Mercurial > hg > isophonics-drupal-site
comparison 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 |
comparison
equal
deleted
inserted
replaced
17:129ea1e6d783 | 18:af1871eacc83 |
---|---|
8 use Drupal\Tests\SchemaCheckTestTrait; | 8 use Drupal\Tests\SchemaCheckTestTrait; |
9 use Drupal\Core\Database\Database; | 9 use Drupal\Core\Database\Database; |
10 use Drupal\Core\DependencyInjection\ContainerBuilder; | 10 use Drupal\Core\DependencyInjection\ContainerBuilder; |
11 use Drupal\Core\Language\Language; | 11 use Drupal\Core\Language\Language; |
12 use Drupal\Core\Url; | 12 use Drupal\Core\Url; |
13 use Drupal\Tests\RequirementsPageTrait; | |
13 use Drupal\user\Entity\User; | 14 use Drupal\user\Entity\User; |
14 use Symfony\Component\DependencyInjection\Reference; | 15 use Symfony\Component\DependencyInjection\Reference; |
15 use Symfony\Component\HttpFoundation\Request; | 16 use Symfony\Component\HttpFoundation\Request; |
16 | 17 |
17 /** | 18 /** |
40 * @see hook_update_N() | 41 * @see hook_update_N() |
41 */ | 42 */ |
42 abstract class UpdatePathTestBase extends BrowserTestBase { | 43 abstract class UpdatePathTestBase extends BrowserTestBase { |
43 | 44 |
44 use SchemaCheckTestTrait; | 45 use SchemaCheckTestTrait; |
46 use RequirementsPageTrait; | |
45 | 47 |
46 /** | 48 /** |
47 * Modules to enable after the database is loaded. | 49 * Modules to enable after the database is loaded. |
48 */ | 50 */ |
49 protected static $modules = []; | 51 protected static $modules = []; |
158 $kernel = TestRunnerKernel::createFromRequest($request, $autoloader); | 160 $kernel = TestRunnerKernel::createFromRequest($request, $autoloader); |
159 $kernel->loadLegacyIncludes(); | 161 $kernel->loadLegacyIncludes(); |
160 | 162 |
161 // Set the update url. This must be set here rather than in | 163 // Set the update url. This must be set here rather than in |
162 // self::__construct() or the old URL generator will leak additional test | 164 // self::__construct() or the old URL generator will leak additional test |
163 // sites. | 165 // sites. Additionally, we need to prevent the path alias processor from |
164 $this->updateUrl = Url::fromRoute('system.db_update'); | 166 // running because we might not have a working alias system before running |
167 // the updates. | |
168 $this->updateUrl = Url::fromRoute('system.db_update', [], ['path_processing' => FALSE]); | |
165 | 169 |
166 $this->setupBaseUrl(); | 170 $this->setupBaseUrl(); |
167 | 171 |
168 // Install Drupal test site. | 172 // Install Drupal test site. |
169 $this->prepareEnvironment(); | 173 $this->prepareEnvironment(); |
259 ]; | 263 ]; |
260 | 264 |
261 // Since the installer isn't run, add the database settings here too. | 265 // Since the installer isn't run, add the database settings here too. |
262 $settings['databases']['default'] = (object) [ | 266 $settings['databases']['default'] = (object) [ |
263 'value' => Database::getConnectionInfo(), | 267 'value' => Database::getConnectionInfo(), |
268 'required' => TRUE, | |
269 ]; | |
270 | |
271 // Force every update hook to only run one entity per batch. | |
272 $settings['entity_update_batch_size'] = (object) [ | |
273 'value' => 1, | |
264 'required' => TRUE, | 274 'required' => TRUE, |
265 ]; | 275 ]; |
266 | 276 |
267 $this->writeSettings($settings); | 277 $this->writeSettings($settings); |
268 } | 278 } |
285 ], | 295 ], |
286 ], | 296 ], |
287 ]); | 297 ]); |
288 | 298 |
289 $this->drupalGet($this->updateUrl); | 299 $this->drupalGet($this->updateUrl); |
300 $this->updateRequirementsProblem(); | |
290 $this->clickLink(t('Continue')); | 301 $this->clickLink(t('Continue')); |
291 | 302 |
292 $this->doSelectionTest(); | 303 $this->doSelectionTest(); |
293 // Run the update hooks. | 304 // Run the update hooks. |
294 $this->clickLink(t('Apply pending updates')); | 305 $this->clickLink(t('Apply pending updates')); |
317 $this->fail("The $update_name() update function from the $module module did not run."); | 328 $this->fail("The $update_name() update function from the $module module did not run."); |
318 } | 329 } |
319 } | 330 } |
320 } | 331 } |
321 } | 332 } |
322 // Reset the static cache of drupal_get_installed_schema_version() so that | 333 |
323 // more complex update path testing works. | 334 // Ensure that the container is updated if any modules are installed or |
324 drupal_static_reset('drupal_get_installed_schema_version'); | 335 // uninstalled during the update. |
336 /** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */ | |
337 $module_handler = $this->container->get('module_handler'); | |
338 $config_module_list = $this->config('core.extension')->get('module'); | |
339 $module_handler_list = $module_handler->getModuleList(); | |
340 $modules_installed = FALSE; | |
341 // Modules that are in configuration but not the module handler have been | |
342 // installed. | |
343 foreach (array_keys(array_diff_key($config_module_list, $module_handler_list)) as $module) { | |
344 $module_handler->addModule($module, drupal_get_path('module', $module)); | |
345 $modules_installed = TRUE; | |
346 } | |
347 $modules_uninstalled = FALSE; | |
348 $module_handler_list = $module_handler->getModuleList(); | |
349 // Modules that are in the module handler but not configuration have been | |
350 // uninstalled. | |
351 foreach (array_keys(array_diff_key($module_handler_list, $config_module_list)) as $module) { | |
352 $modules_uninstalled = TRUE; | |
353 unset($module_handler_list[$module]); | |
354 } | |
355 if ($modules_installed || $modules_uninstalled) { | |
356 // Note that resetAll() does not reset the kernel module list so we | |
357 // have to do that manually. | |
358 $this->kernel->updateModules($module_handler_list, $module_handler_list); | |
359 } | |
360 | |
361 // If we have successfully clicked 'Apply pending updates' then we need to | |
362 // clear the caches in the update test runner as this has occurred as part | |
363 // of the updates. | |
364 $this->resetAll(); | |
325 | 365 |
326 // The config schema can be incorrect while the update functions are being | 366 // The config schema can be incorrect while the update functions are being |
327 // executed. But once the update has been completed, it needs to be valid | 367 // executed. But once the update has been completed, it needs to be valid |
328 // again. Assert the schema of all configuration objects now. | 368 // again. Assert the schema of all configuration objects now. |
329 $names = $this->container->get('config.storage')->listAll(); | 369 $names = $this->container->get('config.storage')->listAll(); |
330 /** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config */ | 370 /** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config */ |
331 $typed_config = $this->container->get('config.typed'); | 371 $typed_config = $this->container->get('config.typed'); |
332 $typed_config->clearCachedDefinitions(); | |
333 foreach ($names as $name) { | 372 foreach ($names as $name) { |
334 $config = $this->config($name); | 373 $config = $this->config($name); |
335 $this->assertConfigSchema($typed_config, $name, $config->get()); | 374 $this->assertConfigSchema($typed_config, $name, $config->get()); |
336 } | 375 } |
337 | 376 |
383 // @todo: Saving the account before the update is problematic. | 422 // @todo: Saving the account before the update is problematic. |
384 // https://www.drupal.org/node/2560237 | 423 // https://www.drupal.org/node/2560237 |
385 $account = User::load(1); | 424 $account = User::load(1); |
386 $account->setPassword($this->rootUser->pass_raw); | 425 $account->setPassword($this->rootUser->pass_raw); |
387 $account->setEmail($this->rootUser->getEmail()); | 426 $account->setEmail($this->rootUser->getEmail()); |
388 $account->setUsername($this->rootUser->getUsername()); | 427 $account->setUsername($this->rootUser->getAccountName()); |
389 $account->save(); | 428 $account->save(); |
390 } | 429 } |
391 | 430 |
392 /** | 431 /** |
393 * Tests the selection page. | 432 * Tests the selection page. |