Commit 382d8f26 authored by Dries's avatar Dries

- Patch #848368 by Stevel, Damien Tournoud: test updating for poll.module.

parent 7d3e5829
......@@ -39,3 +39,4 @@ files[] = tests/unicode.test
files[] = tests/update.test
files[] = tests/xmlrpc.test
files[] = tests/upgrade/upgrade.test
files[] = tests/upgrade/upgrade.poll.test
This diff is collapsed.
<?php
// $Id$
/**
* Upgrade test for poll.module.
*
* Load a bare installation of Drupal 6 and run the upgrade process on it.
*
* The install only contains dblog (although it's optional, it's only so that
* another hook_watchdog module can take its place, the site is not functional
* without watchdog) and update.
*/
class PollUpgradePathTestCase extends UpgradePathTestCase {
public static function getInfo() {
return array(
'name' => 'Poll upgrade path',
'description' => 'Poll upgrade path tests.',
'group' => 'Upgrade path',
);
}
public function setUp() {
// Path to the database dump.
$this->databaseDumpFile = drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php';
parent::setUp();
$this->uninstallModulesExcept(array('poll'));
}
/**
* Test a successful upgrade.
*/
public function testPollUpgrade() {
$this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.'));
// Check modules page for poll
$this->drupalGet('admin/modules');
// Verify that the poll data is still correctly available
for ($i = 0; $i < 12; $i++) {
$this->drupalGet("content/poll/$i");
$nbchoices = ($i % 4) + 2;
for ($c = 0; $c < $nbchoices; $c++) {
$this->assertText("Choice $c for poll $i", t('Choice text is displayed correctly on poll view'));
}
// Now check that the votes are correct
$this->clickLink(t('Results'));
for ($c = 0; $c < $nbchoices; $c++) {
$this->assertText("Choice $c for poll $i", t('Choice text is displayed correctly on result view'));
}
$nbvotes = floor (($i % 4) + 5);
$elements = $this->xpath("//div[@class='percent']");
for ($c = 0; $c < $nbchoices; $c++) {
$votes = floor($nbvotes / $nbchoices);
if (($nbvotes % $nbchoices) > $c) $votes++;
$this->assertTrue(preg_match("/$votes vote/", $elements[$c]), t('The number of votes is displayed correctly: expected ' . $votes . ', got ' . $elements[$c]));
}
}
}
}
......@@ -21,6 +21,11 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
*/
var $upgradeErrors = array();
/**
* Array of modules loaded when the test starts.
*/
var $loadedModules = array();
/**
* Override of DrupalWebTestCase::setUp() specialized for upgrade testing.
*/
......@@ -31,6 +36,8 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
$this->upgradedSite = FALSE;
$this->upgradeErrors = array();
$this->loadedModules = module_list();
// Generate a temporary prefixed database to ensure that tests have a clean starting point.
$this->databasePrefix = 'simpletest' . mt_rand(1000, 1000000);
db_update('simpletest_test_id')
......@@ -258,8 +265,14 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
// of the child site directly from this request.
$this->upgradedSite = TRUE;
// Reload module list and implementations.
module_list(TRUE);
// Reload module list. For modules that are enabled in the test database,
// but not on the test client, we need to load the code here.
$new_modules = array_diff(module_list(TRUE), $this->loadedModules);
foreach ($new_modules as $module) {
drupal_load('module', $module);
}
// Reload hook implementations
module_implements('', FALSE, TRUE);
// Rebuild caches.
......@@ -276,6 +289,24 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
return TRUE;
}
/**
* 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();
}
}
/**
......
......@@ -32,7 +32,24 @@
include_once dirname(__FILE__) . '/../includes/utility.inc';
// Output the PHP header.
$output = "<?php\n\n";
$output = <<<ENDOFHEADER
<?php
// \$Id\$
/**
* @file
* Filled installation of Drupal 6.17, for test purposes.
*
* This file was generated by the dump-database-d6.sh tool, from an
* installation of Drupal 6, filled with data using the generate-d6-content.sh
* tool. It has the following modules installed:
ENDOFHEADER;
foreach (module_list() as $module) {
$output .= " * - $module\n";
}
$output .= " */\n\n";
// Get the current schema, order it by table name.
$schema = drupal_get_schema();
......
#!/usr/bin/env php
<?php
// $Id$
/**
* Generate content for a Drupal 6 database to test the upgrade process.
*
* Run this script at the root of an existing Drupal 6 installation.
* Steps to use this generation script:
* - Install drupal 6.
* - Run this script from your Drupal ROOT directory.
* - Use the dump-database-d6.sh to generate the D7 file
* modules/simpletest/tests/upgrade/database.filled.php
*/
// Define settings.
$cmd = 'index.php';
$_SERVER['HTTP_HOST'] = 'default';
$_SERVER['PHP_SELF'] = '/index.php';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_SOFTWARE'] = NULL;
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['QUERY_STRING'] = '';
$_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] = '/';
$_SERVER['HTTP_USER_AGENT'] = 'console';
$modules_to_enable = array('path', 'poll');
// Bootstrap Drupal.
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// Enable requested modules
include_once './modules/system/system.admin.inc';
$form = system_modules();
foreach ($modules_to_enable as $module) {
$form_state['values']['status'][$module] = TRUE;
}
$form_state['values']['disabled_modules'] = $form['disabled_modules'];
system_modules_submit(NULL, $form_state);
unset($form_state);
// Run cron after installing
drupal_cron_run();
// Create six users
for ($i = 0; $i < 6; $i++) {
$name = "test user $i";
$pass = md5("test PassW0rd $i !(.)");
$mail = "test$i@example.com";
$now = mktime(0, 0, 0, 1, $i + 1, 2010);
db_query("INSERT INTO {users} (name, pass, mail, status, created, access) VALUES ('%s', '%s', '%s', %d, %d, %d)", $name, $pass, $mail, 1, $now, $now);
}
// Create vocabularies and terms
$terms = array();
// All possible combinations of these vocabulary properties.
$hierarchy = array(0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2);
$multiple = array(0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1);
$required = array(0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1);
for ($i = 0; $i < 24; $i++) {
$vocabulary = array();
$vocabulary['name'] = "vocabulary $i";
$vocabulary['description'] = "description of ". $vocabulary['name'];
$vocabulary['nodes'] = $i > 11 ? array('page' => TRUE) : array();
$vocabulary['multiple'] = $multiple[$i % 12];
$vocabulary['required'] = $required[$i % 12];
$vocabulary['relations'] = 1;
$vocabulary['hierarchy'] = $hierarchy[$i % 12];
$vocabulary['weight'] = $i;
taxonomy_save_vocabulary($vocabulary);
$parents = array();
// Vocabularies without hierarcy get one term, single parent vocabularies get
// one parent and one child term. Multiple parent vocabularies get three
// terms: t0, t1, t2 where t0 is a parent of both t1 and t2.
for ($j = 0; $j < $vocabulary['hierarchy'] + 1; $j++) {
$term = array();
$term['vid'] = $vocabulary['vid'];
// For multiple parent vocabularies, omit the t0-t1 relation, otherwise
// every parent in the vocabulary is a parent.
$term['parent'] = $vocabulary['hierarchy'] == 2 && i == 1 ? array() : $parents;
$term['name'] = "term $j of vocabulary $i";
$term['description'] = 'description of ' . $term['name'];
$term['weight'] = $i * 3 + $j;
taxonomy_save_term($term);
$terms[] = $term['tid'];
$parents[] = $term['tid'];
}
}
module_load_include('inc', 'node', 'node.pages');
for ($i = 0; $i < 24; $i++) {
$uid = intval($i / 8) + 3;
$user = user_load($uid);
$node = new stdClass;
$node->uid = $uid;
$node->type = $i < 12 ? 'page' : 'story';
$node->sticky = 0;
$node->title = "node title $i";
$type = node_get_types('type', $node->type);
if ($type->has_body) {
$node->body = str_repeat("node body ($node->type) - $i", 100);
$node->teaser = node_teaser($node->body);
$node->filter = variable_get('filter_default_format', 1);
$node->format = FILTER_FORMAT_DEFAULT;
}
$node->status = intval($i / 4) % 2;
$node->language = '';
$node->revision = $i < 12;
$node->promote = $i % 2;
$node->created = $now + $i * 86400;
$node->log = "added $i node";
$node->taxonomy = $terms;
// Just make every term association different a little.
unset($node->taxonomy[$i], $node->taxonomy[47 - $i]);
node_save($node);
path_set_alias("node/$node->nid", "content/$node->created");
if ($node->revision) {
$user = user_load($uid + 3);
$node->title .= ' revision';
$node->body = str_repeat("node revision body ($node->type) - $i", 100);
$node->log = "added $i revision";
node_save($node);
}
}
// Create poll content
for ($i = 0; $i < 12; $i++) {
$uid = intval($i / 4) + 3;
$user = user_load($uid);
$node = new stdClass;
$node->uid = $uid;
$node->type = 'poll';
$node->sticky = 0;
$node->title = "poll title $i";
$type = node_get_types('type', $node->type);
if ($type->has_body) {
$node->body = str_repeat("node body ($node->type) - $i", 100);
$node->teaser = node_teaser($node->body);
$node->filter = variable_get('filter_default_format', 1);
$node->format = FILTER_FORMAT_DEFAULT;
}
$node->status = intval($i / 2) % 2;
$node->language = '';
$node->revision = 1;
$node->promote = $i % 2;
$node->created = $now + $i * 43200;
$node->log = "added $i poll";
$nbchoices = ($i % 4) + 2;
for ($c = 0; $c < $nbchoices; $c++) {
$node->choice[] = array('chtext' => "Choice $c for poll $i");
}
node_save($node);
path_set_alias("node/$node->nid", "content/poll/$i");
path_set_alias("node/$node->nid/results", "content/poll/$i/results");
// Add some votes
for ($v = 0; $v < ($i % 4) + 5; $v++) {
$c = $v % $nbchoices;
$form_state = array();
$form_state['values']['choice'] = $c;
$form_state['values']['op'] = t('Vote');
drupal_execute('poll_view_voting', $form_state, $node);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment