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