You are here

xml.test in Migrate 6.2

Same filename and directory in other branches
  1. 7.2 tests/plugins/sources/xml.test

File

tests/plugins/sources/xml.test
View source
<?php

/**
 * Test node migration.
 */
class MigrateXMLUnitTest extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'XML migration',
      'description' => 'Test migration from XML source',
      'group' => 'Migrate',
    );
  }
  function setUp() {
    parent::setUp('autoload', 'dbtng', 'taxonomy', 'content', 'text', 'number', 'date_api', 'date_timezone', 'date', 'filefield', 'imagefield', 'migrate', 'migrate_extras', 'migrate_example');

    // Make sure the migrations are registered.
    migrate_get_module_apis();

    // Create and login user
    $migrate_user = $this
      ->drupalCreateUser(array(
      'access content',
      'administer nodes',
      'create page content',
      'delete any page content',
    ));
    $this
      ->drupalLogin($migrate_user);
  }
  function testXMLImport() {
    $migration = Migration::getInstance('WineRegion');
    $result = $migration
      ->processImport();
    $this
      ->assertEqual($result, Migration::RESULT_COMPLETED, t('Region term import returned RESULT_COMPLETED'));
    $migration = Migration::getInstance('WineRole');
    $result = $migration
      ->processImport();
    $this
      ->assertEqual($result, Migration::RESULT_COMPLETED, t('Role import returned RESULT_COMPLETED'));
    $migration = Migration::getInstance('WineUser');
    $result = $migration
      ->processImport();
    $this
      ->assertEqual($result, Migration::RESULT_COMPLETED, t('User import returned RESULT_COMPLETED'));
    $migration = Migration::getInstance('WineProducerXML');
    $result = $migration
      ->processImport();
    $this
      ->assertEqual($result, Migration::RESULT_COMPLETED, t('Producer node import returned RESULT_COMPLETED'));

    // Gather producer nodes, and their corresponding input data
    $nids = db_select('node', 'n')
      ->fields('n', array(
      'nid',
    ))
      ->condition('type', 'migrate_example_producer')
      ->execute()
      ->fetchCol();
    $producer_nodes = array();
    foreach ($nids as $nid) {
      $node = node_load($nid);
      $producer_nodes[$node->title] = $node;
    }
    $this
      ->assertEqual(count($producer_nodes), 1, t('Counts of producer nodes and input rows match'));

    // Test each base node field
    $producer_node = $producer_nodes['Lolonis Winery'];
    $user_migration = MigrationBase::getInstance('WineUser');
    $mapped_uid = $user_migration
      ->getMap()
      ->lookupDestinationID(array(
      3,
    ));
    if (is_array($mapped_uid)) {
      $this
        ->assertEqual($producer_node->uid, reset($mapped_uid), t('uid properly migrated'));
    }
    else {
      $this
        ->error(t('Account ID !id not migrated', array(
        '!id' => 3,
      )));
    }
    $this
      ->assertEqual($producer_node->body, 'Makers of Ladybug Red', t('body properly migrated'));

    // Test Field API fields of all types
    $term = taxonomy_get_term_by_name('Redwood Valley');
    $term = reset($term);
    $this
      ->assertNotNull($node->taxonomy[$term->tid], t('Single taxonomy_term_reference properly migrated'));

    // Test rollback
    $result = $migration
      ->processRollback();
    $this
      ->assertEqual($result, Migration::RESULT_COMPLETED, t('Producer node rollback returned RESULT_COMPLETED'));
    $count = db_select('node', 'n')
      ->fields('n', array(
      'nid',
    ))
      ->condition('type', 'migrate_example_producer')
      ->countQuery()
      ->execute()
      ->fetchField();
    $this
      ->assertEqual($count, 0, t('All nodes deleted'));
    $count = db_select('migrate_map_wineproducerxml', 'map')
      ->fields('map', array(
      'sourceid1',
    ))
      ->countQuery()
      ->execute()
      ->fetchField();
    $this
      ->assertEqual($count, 0, t('Map cleared'));
    $count = db_select('migrate_message_wineproducerxml', 'msg')
      ->fields('msg', array(
      'sourceid1',
    ))
      ->countQuery()
      ->execute()
      ->fetchField();
    $this
      ->assertEqual($count, 0, t('Messages cleared'));
  }

}

Classes

Namesort descending Description
MigrateXMLUnitTest Test node migration.