[177a560] | 1 | <?php |
---|
| 2 | module_load_include('test', 'feeds', 'tests/feeds'); |
---|
| 3 | |
---|
| 4 | /** |
---|
| 5 | * @file |
---|
| 6 | * Tests for plugins/FeedsUserProcessor.inc |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | /** |
---|
| 10 | * Test aggregating a feed as data records. |
---|
| 11 | */ |
---|
| 12 | class FeedsCSVtoUsersTest extends FeedsWebTestCase { |
---|
| 13 | public static function getInfo() { |
---|
| 14 | return array( |
---|
| 15 | 'name' => 'CSV import to users', |
---|
| 16 | 'description' => 'Tests a standalone import configuration that uses file fetcher and CSV parser to import users from a CSV file.', |
---|
| 17 | 'group' => 'Feeds', |
---|
| 18 | ); |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | /** |
---|
| 22 | * Test node creation, refreshing/deleting feeds and feed items. |
---|
| 23 | */ |
---|
| 24 | public function test() { |
---|
| 25 | // Create an importer. |
---|
| 26 | $this->createImporterConfiguration('User import', 'user_import'); |
---|
| 27 | |
---|
| 28 | // Set and configure plugins. |
---|
| 29 | $this->setPlugin('user_import', 'FeedsFileFetcher'); |
---|
| 30 | $this->setPlugin('user_import', 'FeedsCSVParser'); |
---|
| 31 | $this->setPlugin('user_import', 'FeedsUserProcessor'); |
---|
| 32 | |
---|
| 33 | // Go to mapping page and create a couple of mappings. |
---|
| 34 | $mappings = array( |
---|
| 35 | '0' => array( |
---|
| 36 | 'source' => 'name', |
---|
| 37 | 'target' => 'name', |
---|
| 38 | 'unique' => 0, |
---|
| 39 | ), |
---|
| 40 | '1' => array( |
---|
| 41 | 'source' => 'mail', |
---|
| 42 | 'target' => 'mail', |
---|
| 43 | 'unique' => 1, |
---|
| 44 | ), |
---|
| 45 | '2' => array( |
---|
| 46 | 'source' => 'since', |
---|
| 47 | 'target' => 'created', |
---|
| 48 | 'unique' => FALSE, |
---|
| 49 | ), |
---|
| 50 | '3' => array( |
---|
| 51 | 'source' => 'password', |
---|
| 52 | 'target' => 'pass', |
---|
| 53 | 'unique' => 0, |
---|
| 54 | ), |
---|
| 55 | ); |
---|
| 56 | $this->addMappings('user_import', $mappings); |
---|
| 57 | |
---|
| 58 | // Use standalone form. |
---|
| 59 | $edit = array( |
---|
| 60 | 'content_type' => '', |
---|
| 61 | ); |
---|
| 62 | $this->drupalPost('admin/build/feeds/edit/user_import/settings', $edit, 'Save'); |
---|
| 63 | |
---|
| 64 | // Create roles and assign one of them to the users to be imported. |
---|
| 65 | $manager_rid = $this->drupalCreateRole(array('access content'), 'manager'); |
---|
| 66 | $admin_rid = $this->drupalCreateRole(array('access content'), 'administrator'); |
---|
| 67 | $edit = array( |
---|
| 68 | "roles[$manager_rid]" => TRUE, |
---|
| 69 | "roles[$admin_rid]" => FALSE, |
---|
| 70 | ); |
---|
| 71 | $this->setSettings('user_import', 'FeedsUserProcessor', $edit); |
---|
| 72 | |
---|
| 73 | // Import CSV file. |
---|
| 74 | $this->importFile('user_import', $this->absolutePath() .'/tests/feeds/users.csv'); |
---|
| 75 | |
---|
| 76 | // Assert result. |
---|
| 77 | $this->assertText('Created 4 users.'); |
---|
| 78 | // 1 user has an invalid email address, all users should be assigned |
---|
| 79 | // the manager role. |
---|
| 80 | $this->assertText('There was 1 user that could not be imported because either their name or their email was empty or not valid. Check import data and mapping settings on User processor.'); |
---|
| 81 | $this->drupalGet('admin/user/user'); |
---|
| 82 | $this->assertText('Morticia'); |
---|
| 83 | $this->assertText('Fester'); |
---|
| 84 | $this->assertText('Gomez'); |
---|
| 85 | $this->assertText('Pugsley'); |
---|
| 86 | $count = db_result(db_query("SELECT count(*) FROM {users_roles} WHERE rid = %d", $manager_rid)); |
---|
| 87 | $this->assertEqual($count, 4, t('All imported users were assigned the manager role.')); |
---|
| 88 | $count = db_result(db_query("SELECT count(*) FROM {users_roles} WHERE rid = %d", $admin_rid)); |
---|
| 89 | $this->assertEqual($count, 0, t('No imported user was assigned the administrator role.')); |
---|
| 90 | |
---|
| 91 | // @todo Test status setting, update existing and role settings. |
---|
| 92 | |
---|
| 93 | // Attempt to log in as one of the imported users. |
---|
| 94 | $uid = db_result(db_query("SELECT uid FROM {users} WHERE name = 'Morticia'")); |
---|
| 95 | $account = user_load($uid); |
---|
| 96 | $this->assertTrue($account, 'Imported user account loaded.'); |
---|
| 97 | $account->pass_raw = 'mort'; |
---|
| 98 | $this->drupalLogin($account); |
---|
| 99 | } |
---|
| 100 | } |
---|