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

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

This example Drupal source code file (upgrade.node.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

and, array, body, for, function, nbchoices, node, path, php, poll, public, upgrade, votes

The upgrade.node.test Drupal example source code

<?php
// $Id: upgrade.node.test,v 1.4 2010/12/18 02:04:36 dries Exp $

/**
 * Upgrade test for node bodies.
 *
 * Load a filled installation of Drupal 6 and run the upgrade process on it.
 */
class NodeBodyUpgradePathTestCase extends UpgradePathTestCase {
  public static function getInfo() {
    return array(
      'name'  => 'Node body upgrade path',
      'description'  => 'Node body upgrade path tests.',
      'group' => 'Upgrade path',
    );
  }

  public function setUp() {
    // Path to the database dump.
    $this->databaseDumpFiles = array(
      drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php',
    );
    parent::setUp();
  }

  /**
   * Test a successful upgrade.
   */
  public function testNodeBodyUpgrade() {
    $this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.'));
    $this->drupalGet("content/1263769200");
    $this->assertText('node body (broken) - 37');

    // Find a published node revision and make sure it still has a body.
    $revision = db_query_range("SELECT r.nid, r.vid FROM {node_revision} r JOIN {node} n ON n.nid = r.nid WHERE n.status = 1 AND n.type <> 'poll' AND n.vid <> r.vid", 0, 1)->fetch();
    $revision = node_load($revision->nid, $revision->vid);
    $this->assertTrue(!empty($revision->body), 'Non-current node revisions still have a node body.');
    // Find an unpublished node revision and make sure it still has a body.
    $revision = db_query_range("SELECT r.nid, r.vid FROM {node_revision} r JOIN {node} n ON n.nid = r.nid WHERE n.status = 0 AND n.type <> 'poll' AND n.vid <> r.vid", 0, 1)->fetch();
    $revision = node_load($revision->nid, $revision->vid);
    $this->assertTrue(!empty($revision->body), 'Unpublished non-current node revisions still have a node body.');

    // Check that fields created during the upgrade can be edited and resaved
    // in the UI.
    $this->drupalPost('admin/structure/types/manage/story/fields/body', array(), t('Save settings'));
  }
}

/**
 * Upgrade test for node type poll.
 *
 * Load a bare installation of Drupal 6 and run the upgrade process on it.
 *
 * The install only contains dblog (although it's optional, it's only so that
 * another hook_watchdog module can take its place, the site is not functional
 * without watchdog) and update.
 */
class PollUpgradePathTestCase extends UpgradePathTestCase {
  public static function getInfo() {
    return array(
      'name'  => 'Poll upgrade path',
      'description'  => 'Poll upgrade path tests.',
      'group' => 'Upgrade path',
    );
  }

  public function setUp() {
    // Path to the database dump.
    $this->databaseDumpFiles = array(
      drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php',
    );
    parent::setUp();

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

  /**
   * Test a successful upgrade.
   */
  public function testPollUpgrade() {
    $this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.'));

    // Check modules page for poll
    $this->drupalGet('admin/modules');

    // Verify that the poll data is still correctly available
    for ($i = 0; $i < 12; $i++) {
      $this->drupalGet("content/poll/$i");

      $nbchoices = ($i % 4) + 2;

      for ($c = 0; $c < $nbchoices; $c++) {
        $this->assertText("Choice $c for poll $i", t('Choice text is displayed correctly on poll view'));
      }

      // Now check that the votes are correct
      $this->clickLink(t('Results'));

      for ($c = 0; $c < $nbchoices; $c++) {
        $this->assertText("Choice $c for poll $i", t('Choice text is displayed correctly on result view'));
      }

      $nbvotes = floor (($i % 4) + 5);
      $elements = $this->xpath("//div[@class='percent']");
      for ($c = 0; $c < $nbchoices; $c++) {
        $votes = floor($nbvotes / $nbchoices);
        if (($nbvotes % $nbchoices) > $c) $votes++;
        $this->assertTrue(preg_match("/$votes vote/", $elements[$c]), t('The number of votes is displayed correctly: expected ' . $votes . ', got ' . $elements[$c]));
      }
    }
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal upgrade.node.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.