Perform the upgrade.
$register_errors: Register the errors during the upgrade process as failures.
TRUE if the upgrade succeeded, FALSE otherwise.
protected function performUpgrade($register_errors = TRUE) {
// Load the first update screen.
$this
->getUpdatePhp();
if (!$this
->assertResponse(200)) {
throw new \Exception('Initial GET to update.php did not return HTTP 200 status.');
}
// Ensure that the first update screen appeared correctly.
if (!$this
->assertFieldByXPath('//input[@type="submit"]')) {
throw new \Exception('An error was encountered during the first access to update.php.');
}
// Initialize config directories and rebuild the service container after
// creating them in the first step.
parent::prepareConfigDirectories();
$this
->rebuildContainer();
// Continue.
$this
->drupalPost(NULL, array(), t('Continue'));
if (!$this
->assertResponse(200)) {
throw new \Exception('POST to continue update.php did not return HTTP 200 status.');
}
// The test should pass if there are no pending updates.
$content = $this
->drupalGetContent();
if (strpos($content, t('No pending updates.')) !== FALSE) {
$this
->pass('No pending updates and therefore no upgrade process to test.');
$this->pendingUpdates = FALSE;
return TRUE;
}
// Go!
$this
->drupalPost(NULL, array(), t('Apply pending updates'));
if (!$this
->assertResponse(200)) {
throw new \Exception('POST to update.php to apply pending updates did not return HTTP 200 status.');
}
if (!$this
->assertNoText(t('An unrecoverable error has occurred.'))) {
// Error occured during update process.
throw new \Exception('POST to update.php to apply pending updates detected an unrecoverable error.');
}
// Check for errors during the update process.
foreach ($this
->xpath('//li[@class=:class]', array(
':class' => 'failure',
)) as $element) {
$message = strip_tags($element
->asXML());
$this->upgradeErrors[] = $message;
if ($register_errors) {
$this
->fail($message);
}
}
if (!empty($this->upgradeErrors)) {
// Upgrade failed, the installation might be in an inconsistent state,
// don't process.
throw new \Exception('Errors during update process.');
}
// Allow tests to check the completion page.
$this
->checkCompletionPage();
// Check if there still are pending updates.
$this
->getUpdatePhp();
$this
->drupalPost(NULL, array(), t('Continue'));
if (!$this
->assertText(t('No pending updates.'), 'No pending updates at the end of the update process.')) {
throw new \Exception('update.php still shows pending updates after execution.');
}
// Upgrade succeed, rebuild the environment so that we can call the API
// of the child site directly from this request.
$this->upgradedSite = TRUE;
// Force a variable refresh as we only just enabled it.
$this
->refreshVariables();
// Reload module list for modules that are enabled in the test database
// but not on the test client.
\Drupal::moduleHandler()
->resetImplementations();
\Drupal::moduleHandler()
->reload();
// Rebuild the container and all caches.
$this
->rebuildContainer();
$this
->resetAll();
return TRUE;
}