upgrade.upload.test 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Upgrade test for comment.module.
  4. */
  5. class UploadUpgradePathTestCase extends UpgradePathTestCase {
  6. public static function getInfo() {
  7. return array(
  8. 'name' => 'Upload upgrade path',
  9. 'description' => 'Upload upgrade path tests.',
  10. 'group' => 'Upgrade path',
  11. );
  12. }
  13. public function setUp() {
  14. // Path to the database dump files.
  15. $this->databaseDumpFiles = array(
  16. drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php',
  17. drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.upload.database.php',
  18. );
  19. parent::setUp();
  20. // Set a small batch size to test multiple iterations of the batch.
  21. $this->variable_set('upload_update_batch_size', 2);
  22. $this->uninstallModulesExcept(array('upload'));
  23. }
  24. /**
  25. * Test a successful upgrade.
  26. */
  27. public function testUploadUpgrade() {
  28. if ($this->skipUpgradeTest) {
  29. return;
  30. }
  31. $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
  32. $query = new EntityFieldQuery();
  33. $query->entityCondition('entity_type', 'node');
  34. $query->entityCondition('bundle', 'page');
  35. $query->age(FIELD_LOAD_REVISION);
  36. $query->fieldCondition('upload');
  37. $entities = $query->execute();
  38. $revisions = $entities['node'];
  39. // Node revision 50 should not have uploaded files, as the entry in {files}
  40. // is corrupted.
  41. $this->assertFalse((isset($revisions[50])), 'Nodes with missing files do not contain filefield data.');
  42. // Node revisions 51-53 should have uploaded files.
  43. $this->assertTrue((isset($revisions[51]) && isset($revisions[52]) && isset($revisions[53])), 'Nodes with uploaded files now contain filefield data.');
  44. // The test database lists uploaded filenames in the body of each node with
  45. // uploaded files attached. Make sure all files are there in the same order.
  46. foreach ($revisions as $vid => $revision) {
  47. $node = node_load($revision->nid, $vid);
  48. // Assemble a list of the filenames as recorded in the node body before
  49. // the upgrade.
  50. $recorded_filenames = preg_split('/\s+/', $node->body[LANGUAGE_NONE][0]['value']);
  51. // The first line of the node body should be "Attachments:"
  52. if (strstr($recorded_filenames[0], "Attachments:")) {
  53. unset($recorded_filenames[0]);
  54. }
  55. $recorded_filenames = array_values($recorded_filenames);
  56. $files = $node->upload[LANGUAGE_NONE];
  57. // Assemble a list of the filenames as they exist after the upgrade.
  58. $filenames = array();
  59. foreach ($files as $file) {
  60. $filenames[] = $file['filename'];
  61. }
  62. $this->assertIdentical($filenames, $recorded_filenames, 'The uploaded files are present in the same order after the upgrade.');
  63. }
  64. // Test for the file with repeating basename to only have the streaming
  65. // path replaced.
  66. $node = node_load(40, 53);
  67. $repeated_basename_file = $node->upload[LANGUAGE_NONE][4];
  68. $this->assertEqual($repeated_basename_file['uri'], 'private://drupal-6/file/directory/path/crazy-basename.png', "The file with the repeated basename path only had the stream portion replaced");
  69. // Ensure that filepaths are deduplicated.
  70. $node0 = node_load(41, 54);
  71. $node1 = node_load(41, 55);
  72. // Ensure that both revisions point to the same file ID.
  73. $items0 = field_get_items('node', $node0, 'upload');
  74. $this->assertEqual(count($items0), 1);
  75. $items1 = field_get_items('node', $node1, 'upload');
  76. $this->assertEqual(count($items1), 2);
  77. $this->assertEqual($items0[0]['fid'], $items1[0]['fid']);
  78. $this->assertEqual($items0[0]['fid'], $items1[1]['fid']);
  79. // The revision with more than one reference to the same file should retain
  80. // the original settings for each reference.
  81. $this->assertEqual($items1[0]['description'], 'first description');
  82. $this->assertEqual($items1[0]['display'], 0);
  83. $this->assertEqual($items1[1]['description'], 'second description');
  84. $this->assertEqual($items1[1]['display'], 1);
  85. // Ensure that the latest version of the files are used.
  86. $this->assertEqual($items1[0]['filesize'], 316);
  87. $this->assertEqual($items1[1]['filesize'], 316);
  88. // No duplicate files should remain on the Drupal 7 site.
  89. $this->assertEqual(0, db_query("SELECT COUNT(*) FROM {file_managed} GROUP BY uri HAVING COUNT(fid) > 1")->fetchField());
  90. // Make sure the file settings were properly migrated.
  91. $d6_file_directory_temp = '/drupal-6/file/directory/temp';
  92. $d6_file_directory_path = '/drupal-6/file/directory/path';
  93. $d6_file_downloads = 2; // FILE_DOWNLOADS_PRIVATE
  94. $this->assertNull(variable_get('file_directory_temp', NULL), "The 'file_directory_temp' variable was properly removed.");
  95. $this->assertEqual(variable_get('file_temporary_path', 'drupal-7-bogus'), $d6_file_directory_temp, "The 'file_temporary_path' setting was properly migrated.");
  96. $this->assertEqual(variable_get('file_default_scheme', 'drupal-7-bogus'), 'private', "The 'file_default_scheme' setting was properly migrated.");
  97. $this->assertEqual(variable_get('file_private_path', 'drupal-7-bogus'), $d6_file_directory_path, "The 'file_private_path' setting was properly migrated.");
  98. }
  99. }