diff --git a/plugins/FeedsUserProcessor.inc b/plugins/FeedsUserProcessor.inc index 3da8597..912fbfa 100644 --- a/plugins/FeedsUserProcessor.inc +++ b/plugins/FeedsUserProcessor.inc @@ -65,6 +65,7 @@ class FeedsUserProcessor extends FeedsProcessor { $account->uid = 0; $account->roles = array_filter($this->config['roles']); $account->status = $this->config['status']; + $account->is_new = TRUE; return $account; } diff --git a/tests/feeds/users.csv b/tests/feeds/users.csv index eb13a19..bdd01bd 100644 --- a/tests/feeds/users.csv +++ b/tests/feeds/users.csv @@ -1,6 +1,6 @@ -name,mail,since,password,password_md5,password_sha512 -Morticia,morticia@example.com,1244347500,mort,e0108a7eb91670308fff8179a4785453,$S$DfuNE4ur7Jq8xVoJURGm8oMIYunKd366KQUE6akc3EXW/ym9ghpq -Fester,fester@example.com,1241865600,fest,c8cce3815094f01f0ab774fd4f7a77d4,$S$DjJPqmjlWTIen0nQrG3a.vA71Vc0DqCpKuB.g9zmBMnGzIV6JxqH -Gomez,gomez@example.com,1228572000,gome,8a5346b9a510f1f698ab0062b71201ac,$S$Dv.EtHlTfnrxuWGLbe3cf31mD9MF6.4u2Z46M2o2dMGgQGzi7m/5 -Wednesday,wednesdayexample.com,1228347137,wedn,fefb673afaf531dbd78771976a150dc8,$S$DdPzksGh/c8UukipWagAhTzaqUp/eNHVPiC.x6URBQyA503Z41PI -Pugsley,pugsley@example,1228260225,pugs,09189568a8ee4d0addf53d2f6e4847cd,$S$D1oUihjrYXr.4iesN8Sfw1rVRLdo188v0NRGgcNR/V09oIyYPYmZ +uid,name,mail,since,password,password_md5,password_sha512 +201,Morticia,morticia@example.com,1244347500,mort,e0108a7eb91670308fff8179a4785453,$S$DfuNE4ur7Jq8xVoJURGm8oMIYunKd366KQUE6akc3EXW/ym9ghpq +202,Fester,fester@example.com,1241865600,fest,c8cce3815094f01f0ab774fd4f7a77d4,$S$DjJPqmjlWTIen0nQrG3a.vA71Vc0DqCpKuB.g9zmBMnGzIV6JxqH +203,Gomez,gomez@example.com,1228572000,gome,8a5346b9a510f1f698ab0062b71201ac,$S$Dv.EtHlTfnrxuWGLbe3cf31mD9MF6.4u2Z46M2o2dMGgQGzi7m/5 +204,Wednesday,wednesdayexample.com,1228347137,wedn,fefb673afaf531dbd78771976a150dc8,$S$DdPzksGh/c8UukipWagAhTzaqUp/eNHVPiC.x6URBQyA503Z41PI +205,Pugsley,pugsley@example,1228260225,pugs,09189568a8ee4d0addf53d2f6e4847cd,$S$D1oUihjrYXr.4iesN8Sfw1rVRLdo188v0NRGgcNR/V09oIyYPYmZ diff --git a/tests/feeds_processor_user.test b/tests/feeds_processor_user.test index 2608bde..7b31af7 100644 --- a/tests/feeds_processor_user.test +++ b/tests/feeds_processor_user.test @@ -142,6 +142,69 @@ class FeedsCSVtoUsersTest extends FeedsWebTestCase { } /** + * Tests mapping to user ID. + */ + public function testUidTarget() { + // Set to update existing users. + $this->setSettings('user_import', 'FeedsUserProcessor', array('update_existing' => FEEDS_UPDATE_EXISTING)); + + // Add mapping to user ID. + $this->addMappings('user_import', array( + 4 => array( + 'source' => 'uid', + 'target' => 'uid', + 'unique' => TRUE, + ), + )); + + // Create account with uid 202. The username and mail address of this account + // should be updated. + 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 2 users'); + $this->assertText('Updated 1 user'); + + // Assert user ID's. + $account = user_load_by_name('Morticia'); + $this->assertEqual(201, $account->uid, 'Morticia got user ID 201.'); + $account = user_load_by_name('Gomez'); + $this->assertEqual(203, $account->uid, 'Gomez got user ID 203.'); + + // Assert that the username and mail address of account 202 were changed. + $account = user_load(202); + $values = array( + 'name' => array( + 'expected' => 'Fester', + 'actual' => $account->name, + ), + 'mail' => array( + 'expected' => 'fester@example.com', + 'actual' => $account->mail, + ), + ); + $this->assertEqual($values['name']['expected'], $values['name']['actual'], format_string('Username of account 202 changed in @expected (actual: @actual).', array( + '@expected' => $values['name']['expected'], + '@actual' => $values['name']['actual'], + ))); + $this->assertEqual($values['mail']['expected'], $values['mail']['actual'], format_string('Mail address of account 202 changed in @expected (actual: @actual).', array( + '@expected' => $values['mail']['expected'], + '@actual' => $values['mail']['actual'], + ))); + + // Assert that user Joe no longer exists in the system. + $this->assertFalse(user_load_by_name('Joe'), 'No user with username Joe exists.'); + $this->assertFalse(user_load_by_mail('joe@example.com'), 'No user with mail address joe@example.com exists.'); + } + + /** * Tests mapping to role without automatically creating new roles. */ public function testRoleTargetWithoutRoleCreation() {