4 * Upgrade test for node bodies.
6 * Load a filled installation of Drupal 6 and run the upgrade process on it.
8 class NodeBodyUpgradePathTestCase extends UpgradePathTestCase {
9 public static function getInfo() {
11 'name' => 'Node body upgrade path',
12 'description' => 'Node body upgrade path tests.',
13 'group' => 'Upgrade path',
17 public function setUp() {
18 // Path to the database dump.
19 $this->databaseDumpFiles = array(
20 drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php',
26 * Test a successful upgrade.
28 public function testNodeBodyUpgrade() {
29 $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
31 $instance = field_info_instance('node', 'body', 'story');
32 $this->assertIdentical($instance['required'], 0, 'The required setting was preserved during the upgrade path.');
33 $this->assertTrue($instance['description'], 'The description was preserved during the upgrade path');
35 $this->drupalGet("content/1263769200");
36 $this->assertText('node body (broken) - 37');
38 // Find a published node revision and make sure it still has a body.
39 $revision = db_query_range("SELECT r.nid, r.vid FROM {node_revision} r JOIN {node} n ON n.nid = r.nid WHERE n.status = 1 AND n.type <> 'poll' AND n.vid <> r.vid", 0, 1)->fetch();
40 $revision = node_load($revision->nid, $revision->vid);
41 $this->assertTrue(!empty($revision->body), 'Non-current node revisions still have a node body.');
42 // Find an unpublished node revision and make sure it still has a body.
43 $revision = db_query_range("SELECT r.nid, r.vid FROM {node_revision} r JOIN {node} n ON n.nid = r.nid WHERE n.status = 0 AND n.type <> 'poll' AND n.vid <> r.vid", 0, 1)->fetch();
44 $revision = node_load($revision->nid, $revision->vid);
45 $this->assertTrue(!empty($revision->body), 'Unpublished non-current node revisions still have a node body.');
47 // Check that fields created during the upgrade can be edited and resaved
49 $this->drupalPost('admin/structure/types/manage/story/fields/body', array(), t('Save settings'));
54 * Tests the upgrade path for node disabled node types.
56 * Load a filled installation of Drupal 6 and run the upgrade process on it.
58 class DisabledNodeTypeTestCase extends UpgradePathTestCase {
59 public static function getInfo() {
61 'name' => 'Disabled node type upgrade path',
62 'description' => 'Disabled node type upgrade path tests.',
63 'group' => 'Upgrade path',
67 public function setUp() {
68 // Path to the database dump.
69 $this->databaseDumpFiles = array(
70 drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php',
71 drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.node_type_broken.database.php',
77 * Tests a successful upgrade.
79 public function testDisabledNodeTypeUpgrade() {
80 $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
81 $this->assertTrue(field_info_instance('comment', 'comment_body', 'comment_node_broken'), 'Comment body field instance was created for comments attached to the disabled broken node type');
86 * Upgrade test for node type poll.
88 * Load a bare installation of Drupal 6 and run the upgrade process on it.
90 * The install only contains dblog (although it's optional, it's only so that
91 * another hook_watchdog module can take its place, the site is not functional
92 * without watchdog) and update.
94 class PollUpgradePathTestCase extends UpgradePathTestCase {
95 public static function getInfo() {
97 'name' => 'Poll upgrade path',
98 'description' => 'Poll upgrade path tests.',
99 'group' => 'Upgrade path',
103 public function setUp() {
104 // Path to the database dump.
105 $this->databaseDumpFiles = array(
106 drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php',
110 $this->uninstallModulesExcept(array('poll'));
114 * Test a successful upgrade.
116 public function testPollUpgrade() {
117 $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
119 // Check modules page for poll
120 $this->drupalGet('admin/modules');
122 // Verify that the poll data is still correctly available
123 for ($i = 0; $i < 12; $i++) {
124 $this->drupalGet("content/poll/$i");
126 $nbchoices = ($i % 4) + 2;
128 for ($c = 0; $c < $nbchoices; $c++) {
129 $this->assertText("Choice $c for poll $i", 'Choice text is displayed correctly on poll view');
132 // Now check that the votes are correct
133 $this->clickLink(t('Results'));
135 for ($c = 0; $c < $nbchoices; $c++) {
136 $this->assertText("Choice $c for poll $i", 'Choice text is displayed correctly on result view');
139 $nbvotes = floor (($i % 4) + 5);
140 $elements = $this->xpath("//div[@class='percent']");
141 for ($c = 0; $c < $nbchoices; $c++) {
142 $votes = floor($nbvotes / $nbchoices);
143 if (($nbvotes % $nbchoices) > $c) $votes++;
144 $this->assertTrue(preg_match("/$votes vote/", $elements[$c]), 'The number of votes is displayed correctly: expected ' . $votes . ', got ' . $elements[$c]);