public function UploadUpgradePathTestCase::testUploadUpgrade

Test a successful upgrade.

Archivo

drupal-7.x/modules/simpletest/tests/upgrade/upgrade.upload.test, line 31

Class

UploadUpgradePathTestCase
Upgrade test for comment.module.

Código

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.");
}