You are here

protected function TMGMTUpgradeAlpha1TestCase::performUpgrade in Translation Management Tool 7

Perform the upgrade.

Copied and adapted from UpgradePathTestCase::performUpgrade().

Parameters

$register_errors: Register the errors during the upgrade process as failures.

Return value

TRUE if the upgrade succeeded, FALSE otherwise.

1 call to TMGMTUpgradeAlpha1TestCase::performUpgrade()
TMGMTUpgradeAlpha1TestCase::setUp in tests/tmgmt.upgrade.alpha1.test
Sets up a Drupal site for running functional and integration tests.

File

tests/tmgmt.upgrade.alpha1.test, line 110

Class

TMGMTUpgradeAlpha1TestCase
Upgrade tests.

Code

protected function performUpgrade($register_errors = TRUE) {
  $update_url = $GLOBALS['base_url'] . '/update.php';

  // Load the first update screen.
  $this
    ->drupalGet($update_url, array(
    'external' => TRUE,
  ));
  if (!$this
    ->assertResponse(200)) {
    return FALSE;
  }

  // Continue.
  $this
    ->drupalPost(NULL, array(), t('Continue'));
  if (!$this
    ->assertResponse(200)) {
    return FALSE;
  }

  // The test should pass if there are no pending updates.
  $content = $this
    ->drupalGetContent();
  if (strpos($content, t('No pending updates.')) !== FALSE) {
    $this
      ->pass(t('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)) {
    return FALSE;
  }

  // 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.
    return FALSE;
  }

  // Check if there still are pending updates.
  $this
    ->drupalGet($update_url, array(
    'external' => TRUE,
  ));
  $this
    ->drupalPost(NULL, array(), t('Continue'));
  if (!$this
    ->assertText(t('No pending updates.'), t('No pending updates at the end of the update process.'))) {
    return FALSE;
  }

  // Clear caches.
  $this
    ->checkPermissions(array(), TRUE);
}