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
|
// Test for the file with repeating basename to only have the streaming
|
68
|
// path replaced.
|
69
|
$node = node_load(40, 53);
|
70
|
$repeated_basename_file = $node->upload[LANGUAGE_NONE][4];
|
71
|
$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");
|
72
|
|
73
|
// Make sure the file settings were properly migrated.
|
74
|
$d6_file_directory_temp = '/drupal-6/file/directory/temp';
|
75
|
$d6_file_directory_path = '/drupal-6/file/directory/path';
|
76
|
$d6_file_downloads = 2; // FILE_DOWNLOADS_PRIVATE
|
77
|
|
78
|
$this->assertNull(variable_get('file_directory_temp', NULL), "The 'file_directory_temp' variable was properly removed.");
|
79
|
$this->assertEqual(variable_get('file_temporary_path', 'drupal-7-bogus'), $d6_file_directory_temp, "The 'file_temporary_path' setting was properly migrated.");
|
80
|
$this->assertEqual(variable_get('file_default_scheme', 'drupal-7-bogus'), 'private', "The 'file_default_scheme' setting was properly migrated.");
|
81
|
$this->assertEqual(variable_get('file_private_path', 'drupal-7-bogus'), $d6_file_directory_path, "The 'file_private_path' setting was properly migrated.");
|
82
|
}
|
83
|
}
|