upgrade.upload.test 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
  29. $query = new EntityFieldQuery();
  30. $query->entityCondition('entity_type', 'node');
  31. $query->entityCondition('bundle', 'page');
  32. $query->age(FIELD_LOAD_REVISION);
  33. $query->fieldCondition('upload');
  34. $entities = $query->execute();
  35. $revisions = $entities['node'];
  36. // Node revision 50 should not have uploaded files, as the entry in {files}
  37. // is corrupted.
  38. $this->assertFalse((isset($revisions[50])), 'Nodes with missing files do not contain filefield data.');
  39. // Node revisions 51-53 should have uploaded files.
  40. $this->assertTrue((isset($revisions[51]) && isset($revisions[52]) && isset($revisions[53])), 'Nodes with uploaded files now contain filefield data.');
  41. // The test database lists uploaded filenames in the body of each node with
  42. // uploaded files attached. Make sure all files are there in the same order.
  43. foreach ($revisions as $vid => $revision) {
  44. $node = node_load($revision->nid, $vid);
  45. // Assemble a list of the filenames as recorded in the node body before
  46. // the upgrade.
  47. $recorded_filenames = preg_split('/\s+/', $node->body[LANGUAGE_NONE][0]['value']);
  48. // The first line of the node body should be "Attachments:"
  49. if (strstr($recorded_filenames[0], "Attachments:")) {
  50. unset($recorded_filenames[0]);
  51. }
  52. $recorded_filenames = array_values($recorded_filenames);
  53. $files = $node->upload[LANGUAGE_NONE];
  54. // Assemble a list of the filenames as they exist after the upgrade.
  55. $filenames = array();
  56. foreach ($files as $file) {
  57. $filenames[] = $file['filename'];
  58. }
  59. $this->assertIdentical($filenames, $recorded_filenames, 'The uploaded files are present in the same order after the upgrade.');
  60. }
  61. // Test for the file with repeating basename to only have the streaming
  62. // path replaced.
  63. $node = node_load(40, 53);
  64. $repeated_basename_file = $node->upload[LANGUAGE_NONE][4];
  65. $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");
  66. // Ensure that filepaths are deduplicated.
  67. $node0 = node_load(41, 54);
  68. $node1 = node_load(41, 55);
  69. // Ensure that both revisions point to the same file ID.
  70. $items0 = field_get_items('node', $node0, 'upload');
  71. $this->assertEqual(count($items0), 1);
  72. $items1 = field_get_items('node', $node1, 'upload');
  73. $this->assertEqual(count($items1), 2);
  74. $this->assertEqual($items0[0]['fid'], $items1[0]['fid']);
  75. $this->assertEqual($items0[0]['fid'], $items1[1]['fid']);
  76. // The revision with more than one reference to the same file should retain
  77. // the original settings for each reference.
  78. $this->assertEqual($items1[0]['description'], 'first description');
  79. $this->assertEqual($items1[0]['display'], 0);
  80. $this->assertEqual($items1[1]['description'], 'second description');
  81. $this->assertEqual($items1[1]['display'], 1);
  82. // Ensure that the latest version of the files are used.
  83. $this->assertEqual($items1[0]['filesize'], 316);
  84. $this->assertEqual($items1[1]['filesize'], 316);
  85. // No duplicate files should remain on the Drupal 7 site.
  86. $this->assertEqual(0, db_query("SELECT COUNT(*) FROM {file_managed} GROUP BY uri HAVING COUNT(fid) > 1")->fetchField());
  87. // Make sure the file settings were properly migrated.
  88. $d6_file_directory_temp = '/drupal-6/file/directory/temp';
  89. $d6_file_directory_path = '/drupal-6/file/directory/path';
  90. $d6_file_downloads = 2; // FILE_DOWNLOADS_PRIVATE
  91. $this->assertNull(variable_get('file_directory_temp', NULL), "The 'file_directory_temp' variable was properly removed.");
  92. $this->assertEqual(variable_get('file_temporary_path', 'drupal-7-bogus'), $d6_file_directory_temp, "The 'file_temporary_path' setting was properly migrated.");
  93. $this->assertEqual(variable_get('file_default_scheme', 'drupal-7-bogus'), 'private', "The 'file_default_scheme' setting was properly migrated.");
  94. $this->assertEqual(variable_get('file_private_path', 'drupal-7-bogus'), $d6_file_directory_path, "The 'file_private_path' setting was properly migrated.");
  95. }
  96. }