upgrade.node.test 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * Upgrade test for node bodies.
  4. *
  5. * Load a filled installation of Drupal 6 and run the upgrade process on it.
  6. */
  7. class NodeBodyUpgradePathTestCase extends UpgradePathTestCase {
  8. public static function getInfo() {
  9. return array(
  10. 'name' => 'Node body upgrade path',
  11. 'description' => 'Node body upgrade path tests.',
  12. 'group' => 'Upgrade path',
  13. );
  14. }
  15. public function setUp() {
  16. // Path to the database dump.
  17. $this->databaseDumpFiles = array(
  18. drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php',
  19. );
  20. parent::setUp();
  21. }
  22. /**
  23. * Test a successful upgrade.
  24. */
  25. public function testNodeBodyUpgrade() {
  26. $this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.'));
  27. $instance = field_info_instance('node', 'body', 'story');
  28. $this->assertIdentical($instance['required'], 0, 'The required setting was preserved during the upgrade path.');
  29. $this->assertTrue($instance['description'], 'The description was preserved during the upgrade path');
  30. $this->drupalGet("content/1263769200");
  31. $this->assertText('node body (broken) - 37');
  32. // Find a published node revision and make sure it still has a body.
  33. $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();
  34. $revision = node_load($revision->nid, $revision->vid);
  35. $this->assertTrue(!empty($revision->body), 'Non-current node revisions still have a node body.');
  36. // Find an unpublished node revision and make sure it still has a body.
  37. $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();
  38. $revision = node_load($revision->nid, $revision->vid);
  39. $this->assertTrue(!empty($revision->body), 'Unpublished non-current node revisions still have a node body.');
  40. // Check that fields created during the upgrade can be edited and resaved
  41. // in the UI.
  42. $this->drupalPost('admin/structure/types/manage/story/fields/body', array(), t('Save settings'));
  43. }
  44. }
  45. /**
  46. * Tests the upgrade path for node disabled node types.
  47. *
  48. * Load a filled installation of Drupal 6 and run the upgrade process on it.
  49. */
  50. class DisabledNodeTypeTestCase extends UpgradePathTestCase {
  51. public static function getInfo() {
  52. return array(
  53. 'name' => 'Disabled node type upgrade path',
  54. 'description' => 'Disabled node type upgrade path tests.',
  55. 'group' => 'Upgrade path',
  56. );
  57. }
  58. public function setUp() {
  59. // Path to the database dump.
  60. $this->databaseDumpFiles = array(
  61. drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php',
  62. drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.node_type_broken.database.php',
  63. );
  64. parent::setUp();
  65. }
  66. /**
  67. * Tests a successful upgrade.
  68. */
  69. public function testDisabledNodeTypeUpgrade() {
  70. $this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.'));
  71. $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');
  72. }
  73. }
  74. /**
  75. * Upgrade test for node type poll.
  76. *
  77. * Load a bare installation of Drupal 6 and run the upgrade process on it.
  78. *
  79. * The install only contains dblog (although it's optional, it's only so that
  80. * another hook_watchdog module can take its place, the site is not functional
  81. * without watchdog) and update.
  82. */
  83. class PollUpgradePathTestCase extends UpgradePathTestCase {
  84. public static function getInfo() {
  85. return array(
  86. 'name' => 'Poll upgrade path',
  87. 'description' => 'Poll upgrade path tests.',
  88. 'group' => 'Upgrade path',
  89. );
  90. }
  91. public function setUp() {
  92. // Path to the database dump.
  93. $this->databaseDumpFiles = array(
  94. drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php',
  95. );
  96. parent::setUp();
  97. $this->uninstallModulesExcept(array('poll'));
  98. }
  99. /**
  100. * Test a successful upgrade.
  101. */
  102. public function testPollUpgrade() {
  103. $this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.'));
  104. // Check modules page for poll
  105. $this->drupalGet('admin/modules');
  106. // Verify that the poll data is still correctly available
  107. for ($i = 0; $i < 12; $i++) {
  108. $this->drupalGet("content/poll/$i");
  109. $nbchoices = ($i % 4) + 2;
  110. for ($c = 0; $c < $nbchoices; $c++) {
  111. $this->assertText("Choice $c for poll $i", t('Choice text is displayed correctly on poll view'));
  112. }
  113. // Now check that the votes are correct
  114. $this->clickLink(t('Results'));
  115. for ($c = 0; $c < $nbchoices; $c++) {
  116. $this->assertText("Choice $c for poll $i", t('Choice text is displayed correctly on result view'));
  117. }
  118. $nbvotes = floor (($i % 4) + 5);
  119. $elements = $this->xpath("//div[@class='percent']");
  120. for ($c = 0; $c < $nbchoices; $c++) {
  121. $votes = floor($nbvotes / $nbchoices);
  122. if (($nbvotes % $nbchoices) > $c) $votes++;
  123. $this->assertTrue(preg_match("/$votes vote/", $elements[$c]), t('The number of votes is displayed correctly: expected ' . $votes . ', got ' . $elements[$c]));
  124. }
  125. }
  126. }
  127. }