first import
This commit is contained in:
99
sites/all/modules/migrate/tests/plugins/sources/oracle.test
Normal file
99
sites/all/modules/migrate/tests/plugins/sources/oracle.test
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tests for the Oracle source plugin.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test migration from Oracle.
|
||||
*
|
||||
* NOTE: Test won't run correctly due to http://drupal.org/node/362373, enable
|
||||
* when that is fixed.
|
||||
*/
|
||||
class MigrateOracleUnitTest extends DrupalWebTestCase {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Oracle migration',
|
||||
'description' => 'Test migration from an Oracle source',
|
||||
'group' => 'Migrate',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
global $conf;
|
||||
if (empty($conf['oracle_db']) || empty($conf['oracle_db']['username']) ||
|
||||
empty($conf['oracle_db']['password']) || empty($conf['oracle_db']['connection_string'])) {
|
||||
parent::setUp();
|
||||
}
|
||||
else {
|
||||
parent::setUp('features', 'migrate', 'migrate_example_oracle');
|
||||
}
|
||||
}
|
||||
|
||||
function testOracleImport() {
|
||||
global $conf;
|
||||
if (empty($conf['oracle_db'])) {
|
||||
$this->pass(t('To run the Oracle test, you need to defined $conf[\'oracle_db\']
|
||||
in settings.php - see migrate_example_oracle.migrate.inc.'));
|
||||
}
|
||||
$migration = Migration::getInstance('MigrateExampleOracle');
|
||||
$result = $migration->processImport();
|
||||
$this->assertEqual($result, Migration::RESULT_COMPLETED,
|
||||
t('Region term import returned RESULT_COMPLETED'));
|
||||
|
||||
// Gather destination nodes, and their corresponding input data
|
||||
$rawnodes = node_load_multiple(FALSE, array('type' => 'migrate_example_oracle'), TRUE);
|
||||
$data = migrate_example_oracle_sample_data();
|
||||
|
||||
$this->assertEqual(count($rawnodes), count($data), t('Counts of nodes and input rows match'));
|
||||
|
||||
// Index nodes by title
|
||||
$nodes = array();
|
||||
foreach ($rawnodes as $node) {
|
||||
$nodes[$node->title] = $node;
|
||||
}
|
||||
|
||||
// Test each value
|
||||
foreach ($data as $row) {
|
||||
$node = $nodes[$row['title']];
|
||||
if (!$this->assertEqual($node->title, $row['title'], 'Titles match')) {
|
||||
$this->error(t('Source title !source does not match node title !destination',
|
||||
array('!source' => $row['title'], '!destination' => $node->title)));
|
||||
}
|
||||
if (!$this->assertEqual($node->body[LANGUAGE_NONE][0]['value'], $row['body'], 'Bodies match')) {
|
||||
$this->error(t('Source body !source does not match node body !destination',
|
||||
array('!source' => $row['body'], '!destination' => $node->body)));
|
||||
}
|
||||
$created = format_date($node->created, 'custom', 'Y/m/d H:i:s');
|
||||
if (!$this->assertEqual($created, $row['created'], 'Created timestamps match')) {
|
||||
$this->error(t('Source created !source does not match node created !destination',
|
||||
array('!source' => $row['created'], '!destination' => $created)));
|
||||
}
|
||||
$updated = format_date($node->changed, 'custom', 'Y/m/d H:i:s');
|
||||
if (!$this->assertEqual($updated, $row['updated'], 'Updated timestamps match')) {
|
||||
$this->error(t('Source updated !source does not match node changed !destination',
|
||||
array('!source' => $row['updated'], '!destination' => $updated)));
|
||||
}
|
||||
}
|
||||
|
||||
// Test rollback
|
||||
$result = $migration->processRollback();
|
||||
$this->assertEqual($result, Migration::RESULT_COMPLETED,
|
||||
t('Node rollback returned RESULT_COMPLETED'));
|
||||
$rawnodes = node_load_multiple(FALSE, array('type' => 'migrate_example_oracle'), TRUE);
|
||||
$this->assertEqual(count($rawnodes), 0, t('All nodes deleted'));
|
||||
$count = db_select('migrate_map_migrateexampleoracle', 'map')
|
||||
->fields('map', array('sourceid1'))
|
||||
->countQuery()
|
||||
->execute()
|
||||
->fetchField();
|
||||
$this->assertEqual($count, 0, t('Map cleared'));
|
||||
$count = db_select('migrate_message_migrateexampleoracle', 'msg')
|
||||
->fields('msg', array('sourceid1'))
|
||||
->countQuery()
|
||||
->execute()
|
||||
->fetchField();
|
||||
$this->assertEqual($count, 0, t('Messages cleared'));
|
||||
}
|
||||
}
|
100
sites/all/modules/migrate/tests/plugins/sources/xml.test
Normal file
100
sites/all/modules/migrate/tests/plugins/sources/xml.test
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tests for the XML source plugins.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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('taxonomy', 'migrate', 'migrate_example');
|
||||
}
|
||||
|
||||
function testNodeImport() {
|
||||
$migration = Migration::getInstance('WineRegion');
|
||||
$result = $migration->processImport();
|
||||
$this->assertEqual($result, Migration::RESULT_COMPLETED,
|
||||
t('Region term import returned RESULT_COMPLETED'));
|
||||
$migration = Migration::getInstance('WineFileCopy');
|
||||
$result = $migration->processImport();
|
||||
$this->assertEqual($result, Migration::RESULT_COMPLETED,
|
||||
t('File 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
|
||||
$rawnodes = node_load_multiple(FALSE, array('type' => 'migrate_example_producer'), TRUE);
|
||||
// Index by title
|
||||
$producer_nodes = array();
|
||||
foreach ($rawnodes as $node) {
|
||||
$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)));
|
||||
}
|
||||
|
||||
// Test Field API fields of all types
|
||||
// body_with_summary
|
||||
$body = field_get_items('node', $producer_node, 'body');
|
||||
$this->assertEqual($body[0]['value'], 'Makers of Ladybug Red',
|
||||
t('body properly migrated'));
|
||||
$region = field_get_items('node', $producer_node, 'migrate_example_wine_regions');
|
||||
$term = taxonomy_get_term_by_name('Redwood Valley');
|
||||
$term = reset($term);
|
||||
$this->assertEqual($region[0]['tid'], $term->tid,
|
||||
t('region properly migrated'));
|
||||
|
||||
// Test rollback
|
||||
$result = $migration->processRollback();
|
||||
$this->assertEqual($result, Migration::RESULT_COMPLETED,
|
||||
t('Producer node rollback returned RESULT_COMPLETED'));
|
||||
$rawnodes = node_load_multiple(FALSE, array('type' => 'migrate_example_producer'), TRUE);
|
||||
$this->assertEqual(count($rawnodes), 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'));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user