View source
<?php
class MigrateTableUnitTest extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Table migration',
'description' => 'Test migration of table data',
'group' => 'Migrate',
);
}
function setUp() {
parent::setUp('autoload', 'dbtng', 'taxonomy', 'content', 'text', 'number', 'date_api', 'date_timezone', 'date', 'filefield', 'imagefield', 'migrate', 'migrate_extras', 'migrate_example');
migrate_get_module_apis();
}
function testTableImport() {
$migration = Migration::getInstance('WineTable');
$result = $migration
->processImport();
$this
->assertEqual($result, Migration::RESULT_COMPLETED, t('Table import returned RESULT_COMPLETED'));
$result = db_query("SELECT COUNT(*)\n FROM {migrate_example_wine_table_source} s\n INNER JOIN {migrate_map_winetable} map ON s.fooid=map.sourceid1\n INNER JOIN {migrate_example_wine_table_dest} d ON map.destid1=d.recordid");
$this
->assertEqual(db_result($result), 3, t('Count of imported records is correct'));
$result = $migration
->processRollback();
$this
->assertEqual($result, Migration::RESULT_COMPLETED, t('Variety term rollback returned RESULT_COMPLETED'));
$result = db_query("SELECT COUNT(*) FROM {migrate_example_wine_table_dest}");
$this
->assertEqual(db_result($result), 0, t('All migrated rows removed'));
$result = db_query("SELECT COUNT(*) FROM {migrate_map_winetable}");
$this
->assertEqual(db_result($result), 0, t('All map rows removed'));
}
}