- Patch #1182290 by BTMash, chx, matason, catch, mdm, tstoeckler: add boilerplate upgrade path tests.

8.0.x
Dries Buytaert 2011-09-16 17:45:27 -04:00
parent 670cf5cd7b
commit 068424e21d
3 changed files with 33 additions and 6 deletions

View File

@ -46,6 +46,13 @@ function drupal_var_export($var, $prefix = '') {
$output = "'" . $var . "'";
}
}
else if (is_object($var) && get_class($var) === 'stdClass') {
// var_export() will export stdClass objects using an undefined
// magic method __set_state() leaving the export broken. This
// workaround avoids this by casting the object as an array for
// export and casting it back to an object when evaluated.
$output .= '(object) ' . drupal_var_export((array) $var, $prefix);
}
else {
$output = var_export($var, TRUE);
}

View File

@ -37,3 +37,6 @@ files[] = tests/theme.test
files[] = tests/unicode.test
files[] = tests/update.test
files[] = tests/xmlrpc.test
files[] = tests/upgrade/upgrade.test
files[] = tests/upgrade/upgrade_bare.test
files[] = tests/upgrade/upgrade_filled.test

View File

@ -33,6 +33,14 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
protected function setUp() {
global $user, $language, $conf;
// We are going to set a missing zlib requirement property for usage during
// the performUpgrade() and tearDown() calls. Also set that the tests failed.
if (!function_exists('gzopen')) {
$this->missing_zlib_requirement = TRUE;
parent::setUp();
return;
}
// Load the Update API.
require_once DRUPAL_ROOT . '/includes/update.inc';
@ -92,7 +100,11 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
$conf = array();
// Load the database from the portable PHP dump.
// The files can be gzipped.
foreach ($this->databaseDumpFiles as $file) {
if (substr($file, -3) == '.gz') {
$file = "compress.zlib://$file";
}
require $file;
}
@ -111,17 +123,12 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
// Generate and set a D6-compatible session cookie.
$this->curlInitialize();
$sid = drupal_hash_base64(uniqid(mt_rand(), TRUE) . drupal_random_bytes(55));
$session_name = update_get_d6_session_name();
curl_setopt($this->curlHandle, CURLOPT_COOKIE, rawurlencode($session_name) . '=' . rawurlencode($sid));
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);
// A session cannot be written without the ssid column which is missing on
// Drupal 6 sites.
db_add_field('sessions', 'ssid', array('description' => "Secure session ID. The value is generated by Drupal's session handlers.", 'type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''));
_drupal_session_write($sid, '');
// Remove the temporarily added ssid column.
db_drop_field('sessions', 'ssid');
drupal_save_session(FALSE);
// Restore necessary variables.
@ -137,6 +144,11 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
protected function tearDown() {
global $user, $language;
if (!empty($this->missing_zlib_requirement)) {
parent::tearDown();
return;
}
// In case a fatal error occured that was not in the test process read the
// log to pick up any fatal errors.
simpletest_log_read($this->testId, $this->databasePrefix, get_class($this), TRUE);
@ -233,6 +245,11 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
protected function performUpgrade($register_errors = TRUE) {
$update_url = $GLOBALS['base_url'] . '/update.php';
if (!empty($this->missing_zlib_requirement)) {
$this->fail(t('Missing zlib requirement for upgrade tests.'));
return FALSE;
}
// Load the first update screen.
$this->drupalGet($update_url, array('external' => TRUE));
if (!$this->assertResponse(200)) {