upgrade.upload.test 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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(), t('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. // Make sure the file settings were properly migrated.
  67. $d6_file_directory_temp = '/drupal-6/file/directory/temp';
  68. $d6_file_directory_path = '/drupal-6/file/directory/path';
  69. $d6_file_downloads = 2; // FILE_DOWNLOADS_PRIVATE
  70. $this->assertNull(variable_get('file_directory_temp', NULL), "The 'file_directory_temp' variable was properly removed.");
  71. $this->assertEqual(variable_get('file_temporary_path', 'drupal-7-bogus'), $d6_file_directory_temp, "The 'file_temporary_path' setting was properly migrated.");
  72. $this->assertEqual(variable_get('file_default_scheme', 'drupal-7-bogus'), 'private', "The 'file_default_scheme' setting was properly migrated.");
  73. $this->assertEqual(variable_get('file_private_path', 'drupal-7-bogus'), $d6_file_directory_path, "The 'file_private_path' setting was properly migrated.");
  74. }
  75. }