- <?php
-
- * Perform end-to-end tests of the upgrade path.
- */
- abstract class UpgradePathTestCase extends BackdropWebTestCase {
-
-
- * The file path(s) to the dumped database(s) to load into the child site.
- *
- * @var array
- */
- var $databaseDumpFiles = array();
-
-
- * Flag that indicates whether the child site has been upgraded.
- */
- var $upgradedSite = FALSE;
-
-
- * Array of errors triggered during the upgrade process.
- */
- var $upgradeErrors = array();
-
-
- * Array of modules loaded when the test starts.
- */
- var $loadedModules = array();
-
-
- * Checks that zlib is enabled in order to run the upgrade tests.
- */
- protected function checkRequirements() {
- $errors = parent::checkRequirements();
- if (!function_exists('gzopen')) {
- $errors[] = 'Missing zlib requirement for upgrade tests.';
- }
- return $errors;
- }
-
-
- * Overrides BackdropWebTestCase::setUp() for upgrade testing.
- *
- * @see BackdropWebTestCase::prepareDatabasePrefix()
- * @see BackdropWebTestCase::changeDatabasePrefix()
- * @see BackdropWebTestCase::prepareEnvironment()
- */
- protected function setUp() {
- global $user, $language, $conf;
-
-
- require_once BACKDROP_ROOT . '/core/includes/update.inc';
-
-
- $this->upgradedSite = FALSE;
- $this->upgradeErrors = array();
-
- $this->loadedModules = module_list();
-
-
- $this->prepareDatabasePrefix();
-
-
- $this->prepareEnvironment();
- if (!$this->setupEnvironment) {
- return FALSE;
- }
-
-
- $conf = array();
- backdrop_static_reset();
-
-
-
-
-
- $this->changeDatabasePrefix();
- if (!$this->setupDatabasePrefix) {
- return FALSE;
- }
-
-
-
- foreach ($this->databaseDumpFiles as $file) {
- if (substr($file, -3) == '.gz') {
- $file = "compress.zlib://$file";
- }
- require $file;
- }
-
-
- $this->variable_set('file_public_path', $this->public_files_directory);
- $this->variable_set('file_private_path', $this->private_files_directory);
- $this->variable_set('file_temporary_path', $this->temp_files_directory);
-
- $this->pass('Finished loading the dump.');
-
-
-
- backdrop_save_session(FALSE);
-
- $user = db_query('SELECT * FROM {users} WHERE uid = :uid', array(':uid' => 1))->fetchObject();
-
-
- $this->curlInitialize();
- $sid = backdrop_hash_base64(uniqid(mt_rand(), TRUE) . backdrop_random_bytes(55));
- curl_setopt($this->curlHandle, CURLOPT_COOKIE, rawurlencode(session_name()) . '=' . rawurlencode($sid));
-
-
- backdrop_save_session(TRUE);
- _backdrop_session_write($sid, '');
-
- backdrop_save_session(FALSE);
-
-
- $this->variable_set('clean_url', $this->originalCleanUrl);
- $this->variable_set('site_mail', 'simpletest@example.com');
-
- backdrop_set_time_limit($this->timeLimit);
- $this->setup = TRUE;
- }
-
-
- * Specialized variable_set() that works even if the child site is not upgraded.
- *
- * @param $name
- * The name of the variable to set.
- * @param $value
- * The value to set. This can be any PHP data type; these functions take care
- * of serialization as necessary.
- */
- protected function variable_set($name, $value) {
- db_delete('variable')
- ->condition('name', $name)
- ->execute();
- db_insert('variable')
- ->fields(array(
- 'name' => $name,
- 'value' => serialize($value),
- ))
- ->execute();
-
- try {
- cache()->delete('variables');
- cache('bootstrap')->delete('variables');
- }
-
-
- catch (Exception $e) {}
- }
-
-
- * Specialized refreshVariables().
- */
- protected function refreshVariables() {
-
- if (!$this->upgradedSite) {
- return parent::refreshVariables();
- }
- }
-
-
- * Perform the upgrade.
- *
- * @param $register_errors
- * Register the errors during the upgrade process as failures.
- * @return
- * TRUE if the upgrade succeeded, FALSE otherwise.
- */
- protected function performUpgrade($register_errors = TRUE) {
-
-
- $update_url = $GLOBALS['base_url'] . '/core/update.php';
- $this->backdropGet($update_url, array('external' => TRUE));
- if (!$this->assertResponse(200)) {
- return FALSE;
- }
-
-
- $this->backdropPost(NULL, array(), t('Continue'));
- if (!$this->assertResponse(200)) {
- return FALSE;
- }
-
-
- $this->backdropPost(NULL, array(), t('Apply pending updates'));
- if (!$this->assertText(t('Updates were attempted'))) {
- return FALSE;
- }
-
-
- 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)) {
-
-
- return FALSE;
- }
-
-
- $this->backdropGet($update_url, array('external' => TRUE));
- $this->backdropPost(NULL, array(), t('Continue'));
- if (!$this->assertText(t('No pending updates.'), 'No pending updates at the end of the update process.')) {
- return FALSE;
- }
-
-
-
- $this->upgradedSite = TRUE;
-
-
-
- $new_modules = array_diff(module_list(TRUE), $this->loadedModules);
- foreach ($new_modules as $module) {
- backdrop_load('module', $module);
- }
-
-
- module_implements_reset();
-
-
- backdrop_static_reset();
- backdrop_flush_all_caches();
-
-
- $this->refreshVariables();
- $this->checkPermissions(array(), TRUE);
-
-
- $this->backdropGet('');
- return $this->assertText('Powered by Backdrop CMS', 'The home page of the upgraded site loads successfully.');
- }
-
-
- * Force uninstall all modules from a test database, except those listed.
- *
- * @param $modules
- * The list of modules to keep installed. Required core modules will
- * always be kept.
- */
- protected function uninstallModulesExcept(array $modules) {
- $required_modules = array('block', 'dblog', 'filter', 'node', 'system', 'update', 'user');
-
- $modules = array_merge($required_modules, $modules);
-
- db_delete('system')
- ->condition('type', 'module')
- ->condition('name', $modules, 'NOT IN')
- ->execute();
- }
- }