home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (upgrade.upload.test)

This example Drupal source code file (upgrade.upload.test) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, drupal-7-bogus, files, foreach, function, migrated, php, properly, recorded_filenames, revisions, setting, the, upgrade, was

The upgrade.upload.test Drupal example source code

<?php
// $Id: upgrade.upload.test,v 1.3 2010/11/21 20:35:10 webchick Exp $

/**
 * 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(), t('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.');
    }
    // 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.");
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal upgrade.upload.test source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.