upgrade.node.test 5.5 KB

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