summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.26/modules/simpletest/tests/upgrade/upgrade.upload.test
blob: be352bd4253a3de428543659c870fa516848cb7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php

/**
 * Upgrade test for comment.module.
 */
class UploadUpgradePathTestCase extends UpgradePathTestCase {
  public static function getInfo() {
    return array(
      'name'  => 'Upload upgrade path',
      'description'  => 'Upload upgrade path tests.',
      'group' => 'Upgrade path',
    );
  }

  public function setUp() {
    // Path to the database dump files.
    $this->databaseDumpFiles = array(
      drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php',
      drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.upload.database.php',
    );
    parent::setUp();
    // Set a small batch size to test multiple iterations of the batch.
    $this->variable_set('upload_update_batch_size', 2);

    $this->uninstallModulesExcept(array('upload'));
  }

  /**
   * Test a successful upgrade.
   */
  public function testUploadUpgrade() {
    $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'node');
    $query->entityCondition('bundle', 'page');
    $query->age(FIELD_LOAD_REVISION);
    $query->fieldCondition('upload');
    $entities = $query->execute();
    $revisions = $entities['node'];
    // Node revision 50 should not have uploaded files, as the entry in {files}
    // is corrupted.
    $this->assertFalse((isset($revisions[50])), 'Nodes with missing files do not contain filefield data.');
    // Node revisions 51-53 should have uploaded files.
    $this->assertTrue((isset($revisions[51]) && isset($revisions[52]) && isset($revisions[53])), 'Nodes with uploaded files now contain filefield data.');
    // The test database lists uploaded filenames in the body of each node with
    // uploaded files attached. Make sure all files are there in the same order.
    foreach ($revisions as $vid => $revision) {
      $node = node_load($revision->nid, $vid);

      // Assemble a list of the filenames as recorded in the node body before
      // the upgrade.
      $recorded_filenames = preg_split('/\s+/', $node->body[LANGUAGE_NONE][0]['value']);
      // The first line of the node body should be "Attachments:"
      if (strstr($recorded_filenames[0], "Attachments:")) {
        unset($recorded_filenames[0]);
      }
      $recorded_filenames = array_values($recorded_filenames);

      $files = $node->upload[LANGUAGE_NONE];
      // Assemble a list of the filenames as they exist after the upgrade.
      $filenames = array();
      foreach ($files as $file) {
        $filenames[] = $file['filename'];
      }
      $this->assertIdentical($filenames, $recorded_filenames, 'The uploaded files are present in the same order after the upgrade.');
    }
    // Test for the file with repeating basename to only have the streaming
    // path replaced.
    $node = node_load(40, 53);
    $repeated_basename_file = $node->upload[LANGUAGE_NONE][4];
    $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");

    // Make sure the file settings were properly migrated.
    $d6_file_directory_temp = '/drupal-6/file/directory/temp';
    $d6_file_directory_path = '/drupal-6/file/directory/path';
    $d6_file_downloads = 2; // FILE_DOWNLOADS_PRIVATE

    $this->assertNull(variable_get('file_directory_temp', NULL), "The 'file_directory_temp' variable was properly removed.");
    $this->assertEqual(variable_get('file_temporary_path', 'drupal-7-bogus'), $d6_file_directory_temp, "The 'file_temporary_path' setting was properly migrated.");
    $this->assertEqual(variable_get('file_default_scheme', 'drupal-7-bogus'), 'private', "The 'file_default_scheme' setting was properly migrated.");
    $this->assertEqual(variable_get('file_private_path', 'drupal-7-bogus'), $d6_file_directory_path, "The 'file_private_path' setting was properly migrated.");
  }
}