Commit 3b571146 authored by catch's avatar catch
Browse files

Issue #1352000 by BTMash: Forward-port upgrade test clean-ups from 7.x to 8.x.

parent 252e84ec
......@@ -40,6 +40,4 @@ files[] = tests/update.test
files[] = tests/uuid.test
files[] = tests/xmlrpc.test
files[] = tests/upgrade/upgrade.test
files[] = tests/upgrade/upgrade_bare.test
files[] = tests/upgrade/upgrade_filled.test
files[] = tests/upgrade/upgrade.language.test
......@@ -11,6 +11,10 @@
*/
// Add blocks respective for language functionality.
db_delete('block')
->condition('module', 'locale')
->execute();
db_insert('block')->fields(array(
'module',
'delta',
......@@ -52,85 +56,8 @@
))
->execute();
// Add language table from locale.install schema and prefill with some default
// languages for testing.
db_create_table('languages', array(
'fields' => array(
'language' => array(
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
),
'name' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'native' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'direction' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'enabled' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'plurals' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'formula' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'domain' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'prefix' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'weight' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'javascript' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array(
'language',
),
'indexes' => array(
'list' => array(
'weight',
'name',
),
),
'module' => 'locale',
'name' => 'languages',
));
// Prefill languages table from locale.install with some default languages
// for testing.
db_insert('languages')->fields(array(
'language',
'name',
......@@ -170,19 +97,6 @@
'weight' => '0',
'javascript' => '',
))
->values(array(
'language' => 'en',
'name' => 'English',
'native' => 'English',
'direction' => '0',
'enabled' => '1',
'plurals' => '0',
'formula' => '',
'domain' => '',
'prefix' => '',
'weight' => '0',
'javascript' => '',
))
->values(array(
'language' => 'hr',
'name' => 'Croatian',
......@@ -198,58 +112,8 @@
))
->execute();
// Add locales_source table from locale.install schema and fill with some
// sample data for testing.
db_create_table('locales_source', array(
'fields' => array(
'lid' => array(
'type' => 'serial',
'not null' => TRUE,
),
'location' => array(
'type' => 'text',
'not null' => FALSE,
'size' => 'big',
),
'textgroup' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => 'default',
),
'source' => array(
'type' => 'text',
'mysql_type' => 'blob',
'not null' => TRUE,
),
'context' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'version' => array(
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
'default' => 'none',
),
),
'primary key' => array(
'lid',
),
'indexes' => array(
'source_context' => array(
array(
'source',
30,
),
'context',
),
),
'module' => 'locale',
'name' => 'locales_source',
));
// Fill locales_source table from locale.install schema with some sample data
// for testing.
db_insert('locales_source')->fields(array(
'lid',
'location',
......@@ -452,63 +316,8 @@
))
->execute();
// Add locales_target table from locale.install schema.
db_create_table('locales_target', array(
'fields' => array(
'lid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'translation' => array(
'type' => 'text',
'mysql_type' => 'blob',
'not null' => TRUE,
),
'language' => array(
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
),
'plid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'plural' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'language',
'lid',
'plural',
),
'foreign keys' => array(
'locales_source' => array(
'table' => 'locales_source',
'columns' => array(
'lid' => 'lid',
),
),
),
'indexes' => array(
'lid' => array(
'lid',
),
'plid' => array(
'plid',
),
'plural' => array(
'plural',
),
),
'module' => 'locale',
'name' => 'locales_target',
));
// Fill locales_target table from locale.install schema with some sample data
// for testing.
db_insert('locales_target')->fields(array(
'lid',
'translation',
......@@ -554,6 +363,21 @@
->execute();
// Set up variables needed for language support.
$deleted_variables = array(
'javascript_parsed',
'language_count',
'language_default',
'language_negotiation_language',
'language_negotiation_language_content',
'language_negotiation_language_url',
'language_types',
'locale_language_providers_weight_language',
'language_content_type_article',
);
db_delete('variable')
->condition('name', $deleted_variables, 'IN')
->execute();
db_insert('variable')->fields(array(
'name',
'value',
......@@ -596,22 +420,6 @@
))
->execute();
// Enable Locale and Translation module.
db_update('system')->fields(array(
'status' => 1,
'schema_version' => '7001',
))
->condition('type', 'module')
->condition('name', 'locale')
->execute();
db_update('system')->fields(array(
'status' => 1,
'schema_version' => '7001',
))
->condition('type', 'module')
->condition('name', 'translation')
->execute();
// Add sample nodes to test language assignment and translation functionality.
// The first node is also used for testing comment language functionality. This
// is a simple node with LANGUAGE_NOT_SPECIFIED as language code. The second
......
......@@ -22,7 +22,7 @@ class LanguageUpgradePathTestCase extends UpgradePathTestCase {
public function setUp() {
// Path to the database dump files.
$this->databaseDumpFiles = array(
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.filled.database.php.gz',
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.filled.standard_all.database.php.gz',
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.language.database.php',
);
parent::setUp();
......
......@@ -29,6 +29,26 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
*/
var $loadedModules = array();
/**
* Flag to indicate whether there are pending updates or not.
*/
var $pendingUpdates = TRUE;
/**
* Prepares the appropriate session for the release of Drupal being upgraded.
*/
protected function prepareD8Session() {
// Generate and set a D7-compatible session cookie.
$this->curlInitialize();
$sid = drupal_hash_base64(uniqid(mt_rand(), TRUE) . drupal_random_bytes(55));
curl_setopt($this->curlHandle, CURLOPT_COOKIE, rawurlencode(session_name()) . '=' . rawurlencode($sid));
// Force our way into the session of the child site.
drupal_save_session(TRUE);
_drupal_session_write($sid, '');
drupal_save_session(FALSE);
}
/**
* Checks that zlib is enabled in order to run the upgrade tests.
*/
......@@ -42,7 +62,7 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
}
/**
* Override of DrupalWebTestCase::setUp() specialized for upgrade testing.
* Overrides DrupalWebTestCase::setUp() specialized for upgrade testing.
*/
protected function setUp() {
global $user, $language_interface, $conf;
......@@ -105,7 +125,7 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
$conf = array();
// Load the database from the portable PHP dump.
// The files can be gzipped.
// The files may be gzipped.
foreach ($this->databaseDumpFiles as $file) {
if (substr($file, -3) == '.gz') {
$file = "compress.zlib://$file";
......@@ -125,16 +145,8 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
drupal_save_session(FALSE);
$user = db_query('SELECT * FROM {users} WHERE uid = :uid', array(':uid' => 1))->fetchObject();
// Generate and set a D6-compatible session cookie.
$this->curlInitialize();
$sid = drupal_hash_base64(uniqid(mt_rand(), TRUE) . drupal_random_bytes(55));
curl_setopt($this->curlHandle, CURLOPT_COOKIE, rawurlencode(session_name()) . '=' . rawurlencode($sid));
// Force our way into the session of the child site.
drupal_save_session(TRUE);
_drupal_session_write($sid, '');
// Remove the temporarily added ssid column.
drupal_save_session(FALSE);
// Generate and set a D8-compatible session cookie.
$this->prepareD8Session();
// Restore necessary variables.
$this->variable_set('site_mail', 'simpletest@example.com');
......@@ -257,9 +269,17 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
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->assertText('Updates were attempted')) {
if (!$this->assertResponse(200)) {
return FALSE;
}
......@@ -311,9 +331,7 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
$this->refreshVariables();
$this->checkPermissions(array(), TRUE);
// Check we can load the front page of the new site.
$this->drupalGet('');
return $this->assertText('Powered by Drupal', t('The front page of the upgraded site loads successfully.'));
return TRUE;
}
/**
......@@ -335,3 +353,321 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
}
}
/**
* Performs major version release upgrade tests on a bare database.
*
* Loads an installation of Drupal 7.x and runs the upgrade process on it.
*
* The install contains the minimal profile modules (without any generated
* content) so that an upgrade from of a site under this profile may be tested.
*/
class BareMinimalUpgradePath extends UpgradePathTestCase {
public static function getInfo() {
return array(
'name' => 'Basic minimal profile upgrade path, bare database',
'description' => 'Basic upgrade path tests for a minimal profile install with a bare database.',
'group' => 'Upgrade path',
);
}
public function setUp() {
// Path to the database dump files.
$this->databaseDumpFiles = array(
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.minimal.database.php.gz',
);
parent::setUp();
}
/**
* Tests a successful major version release upgrade.
*/
public function testBasicMinimalUpgrade() {
$this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.'));
// Ensure that the new Entity module is enabled after upgrade.
$this->assertTrue(module_exists('entity'), 'Entity module enabled after upgrade.');
// Hit the frontpage.
$this->drupalGet('');
$this->assertResponse(200);
// Verify that we are still logged in.
$this->drupalGet('user');
$this->clickLink(t('Edit'));
$this->assertEqual($this->getUrl(), url('user/1/edit', array('absolute' => TRUE)), t('We are still logged in as admin at the end of the upgrade.'));
// Logout and verify that we can login back in with our initial password.
$this->drupalLogout();
$this->drupalLogin((object) array(
'uid' => 1,
'name' => 'admin',
'pass_raw' => 'drupal',
));
// The previous login should've triggered a password rehash, so login one
// more time to make sure the new hash is readable.
$this->drupalLogout();
$this->drupalLogin((object) array(
'uid' => 1,
'name' => 'admin',
'pass_raw' => 'drupal',
));
// Test that the site name is correctly displayed.
$this->assertText('drupal', t('The site name is correctly displayed.'));
// Verify that the main admin sections are available.
$this->drupalGet('admin');
$this->assertText(t('Content'));
$this->assertText(t('Appearance'));
$this->assertText(t('People'));
$this->assertText(t('Configuration'));
$this->assertText(t('Reports'));
$this->assertText(t('Structure'));
$this->assertText(t('Modules'));
// Confirm that no {menu_links} entry exists for user/autocomplete.
$result = db_query('SELECT COUNT(*) FROM {menu_links} WHERE link_path = :user_autocomplete', array(':user_autocomplete' => 'user/autocomplete'))->fetchField();
$this->assertFalse($result, t('No {menu_links} entry exists for user/autocomplete'));
}
}
/**
* Performs major version release upgrade tests on a populated database.
*
* Loads an installation of Drupal 7.x and runs the upgrade process on it.
*
* The install contains the minimal profile modules (along with generated
* content) so that an update from of a site under this profile may be tested.
*/
class FilledMinimalUpgradePath extends UpgradePathTestCase {
public static function getInfo() {
return array(
'name' => 'Basic minimal profile upgrade path, populated database',
'description' => 'Basic upgrade path tests for a minimal profile install with a populated database.',
'group' => 'Upgrade path',
);
}
public function setUp() {
// Path to the database dump files.
$this->databaseDumpFiles = array(
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.filled.minimal.database.php.gz',
);
parent::setUp();
}
/**
* Tests a successful point release update.
*/
public function testFilledMinimalUpgrade() {
$this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.'));
// Ensure that the new Entity module is enabled after upgrade.
$this->assertTrue(module_exists('entity'), 'Entity module enabled after upgrade.');
// Hit the frontpage.
$this->drupalGet('');
$this->assertResponse(200);
// Verify that we are still logged in.
$this->drupalGet('user');
$this->clickLink(t('Edit'));
$this->assertEqual($this->getUrl(), url('user/1/edit', array('absolute' => TRUE)), t('We are still logged in as admin at the end of the upgrade.'));
// Logout and verify that we can login back in with our initial password.
$this->drupalLogout();
$this->drupalLogin((object) array(
'uid' => 1,
'name' => 'admin',
'pass_raw' => 'drupal',
));
// The previous login should've triggered a password rehash, so login one
// more time to make sure the new hash is readable.
$this->drupalLogout();
$this->drupalLogin((object) array(
'uid' => 1,
'name' => 'admin',
'pass_raw' => 'drupal',
));
// Test that the site name is correctly displayed.
$this->assertText('drupal', t('The site name is correctly displayed.'));
// Verify that the main admin sections are available.
$this->drupalGet('admin');
$this->assertText(t('Content'));
$this->assertText(t('Appearance'));
$this->assertText(t('People'));
$this->assertText(t('Configuration'));
$this->assertText(t('Reports'));
$this->assertText(t('Structure'));
$this->assertText(t('Modules'));
// Confirm that no {menu_links} entry exists for user/autocomplete.
$result = db_query('SELECT COUNT(*) FROM {menu_links} WHERE link_path = :user_autocomplete', array(':user_autocomplete' => 'user/autocomplete'))->fetchField();
$this->assertFalse($result, t('No {menu_links} entry exists for user/autocomplete'));
}
}
/**
* Performs major version release upgrade tests on a bare database.
*
* Loads an installation of Drupal 7.x and runs the upgrade process on it.
*
* The install contains the standard profile (plus all optional) modules
* without any content so that an update from any of the modules under this
* profile installation can be wholly tested.
*/
class BareStandardUpgradePath extends UpgradePathTestCase {
public static function getInfo() {
return array(
'name' => 'Basic standard + all profile upgrade path, bare database',
'description' => 'Basic upgrade path tests for a standard profile install with all enabled modules and a bare database.',
'group' => 'Upgrade path',
);
}
public function setUp() {
// Path to the database dump files.
$this->databaseDumpFiles = array(
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.standard_all.database.php.gz',
);
parent::setUp();
}
/**
* Tests a successful major version release upgrade.
*/
<