'User migration', 'description' => 'Test migration of user 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'); drupal_flush_all_caches(); // To test timestamps date_default_timezone_set('US/Mountain'); } function testUserImport() { $migration = Migration::getInstance('WineUser'); $result = $migration->processImport(); $this->assertEqual($result, Migration::RESULT_COMPLETED, t('User import returned RESULT_COMPLETED')); $result = db_select('migrate_example_wine_account', 'mea') ->fields('mea', array('accountid', 'status', 'posted', 'name', 'sex', 'password', 'mail', 'last_access', 'last_login', 'sig', 'original_mail')) ->execute(); $uids = db_select('users', 'u') ->fields('u', array('uid')) ->execute() ->fetchCol(); // Index by name $users = array(); foreach ($uids as $uid) { // Skip anon/admin users if ($uid > 1) { $account = user_load($uid); $users[$account->name] = $account; } } $rows = array(); foreach ($result as $row) { $rows[$row->name] = $row; } $this->assertEqual(count($users), count($rows), t('Counts of users and input rows match')); // Test each base user field $this->assert(isset($users['darren']) && isset($rows['darren']), t("Username 'darren' migrated correctly")); $this->assertEqual($users['darren']->mail, $rows['darren']->mail, t('Email addresses match')); $this->assertEqual($users['darren']->status, $rows['darren']->status, t('Statuses match')); $this->assertNotNull($users['darren']->roles[2], t('Authenticated role')); $this->assertEqual($users['darren']->created, strtotime($rows['darren']->posted), t('Created times match')); $this->assertEqual($users['darren']->access, strtotime($rows['darren']->last_access), t('Access times match')); $this->assertEqual($users['darren']->login, strtotime($rows['darren']->last_login), t('Login times match')); $this->assertEqual(md5($rows['darren']->password), $users['darren']->pass, t('Passwords match')); $this->assertEqual($users['darren']->init, $rows['darren']->original_mail, t('Init mails match')); $this->assertEqual($users['darren']->signature, $rows['darren']->sig, t('Signatures match')); $this->assertEqual($users['darren']->signature_format, $migration->basicFormat, t('Signature formats match')); // TODO: Theme, timezone, language, picture // Test rollback $result = $migration->processRollback(); $this->assertEqual($result, Migration::RESULT_COMPLETED, t('User rollback returned RESULT_COMPLETED')); $count = db_select('users', 'u') ->fields('u', array('uid')) ->countQuery() ->execute() ->fetchField(); // 2 users left - anon and admin $this->assertEqual($count, 2, t('All imported users deleted')); $count = db_select('migrate_map_wineuser', 'map') ->fields('map', array('sourceid1')) ->countQuery() ->execute() ->fetchField(); $this->assertEqual($count, 0, t('Map cleared')); $count = db_select('migrate_message_wineuser', 'msg') ->fields('msg', array('sourceid1')) ->countQuery() ->execute() ->fetchField(); $this->assertEqual($count, 0, t('Messages cleared')); } }