public function FeedsCSVtoUsersTest::testUidUpdating in Feeds 7.2
Tests if user ID's can be changed using the user ID target.
Also checks if a clear error is reported when trying to change the user ID to something that is already in use.
File
- tests/
feeds_processor_user.test, line 217 - Tests for plugins/FeedsUserProcessor.inc.
Class
- FeedsCSVtoUsersTest
- Test aggregating a feed as data records.
Code
public function testUidUpdating() {
// Set to update existing users.
$this
->setSettings('user_import', 'FeedsUserProcessor', array(
'update_existing' => FEEDS_UPDATE_EXISTING,
));
// Add mapping to user ID, but do not mark target as unique.
$this
->addMappings('user_import', array(
4 => array(
'source' => 'uid',
'target' => 'uid',
),
));
// Create an account which user ID should be updated.
user_save(drupal_anonymous_user(), array(
'uid' => 54,
'name' => 'Morticia',
'mail' => 'morticia@example.com',
'pass' => 'mort',
'status' => 1,
));
// Create account with uid 202. Importing an other account with uid 202
// should fail.
user_save(drupal_anonymous_user(), array(
'uid' => 202,
'name' => 'Joe',
'mail' => 'joe@example.com',
'pass' => 'joe',
'status' => 1,
));
// Import CSV file.
$this
->importFile('user_import', $this
->absolutePath() . '/tests/feeds/users.csv');
$this
->assertText('Created 1 user');
$this
->assertText('Updated 1 user');
$this
->assertText('Failed importing 3 users.');
$this
->assertText('Could not update user ID to 202 since that ID is already in use.');
// Assert Morticia's user ID got updated.
$account = user_load_by_name('Morticia');
$this
->assertEqual(201, $account->uid, 'Morticia now got user ID 201.');
// Assert that Fester failed to import.
$this
->assertFalse(user_load_by_name('Fester'), 'The account for Fester was not imported.');
// Assert that user 202 did not change.
$account = user_load(202);
$this
->assertEqual('Joe', $account->name, 'The user name of account 202 is still Joe.');
$this
->assertEqual('joe@example.com', $account->mail, 'The mail address of account 202 is still joe@example.com.');
}